OS: Windows 7 Enterprise, SP1
Adobe FMLE 3.2
I was always executing FMLECmd.exe from Java-code without any problems. But suddenly smth happened and the stream couldn't start anymore.
Setting the compatibility mode to Windows XP SP3 solved the problem of execution.
But the new one appeared: launching the stream in compatibility mode should be performed as Administrator. I switched off the UAC popup and solved the problem of programmatical stream-starting.
But then the new problem appeared: when I want to kill the FMLECmd.exe process programmatically (to stop the stream) I get the message that 'Access is denied'. I guess the reason is that I started stream as Administrator, but process-killing is held as a usual user.
So, the question: Are there any ways to make FMLE work without compatibility mode? Or are there any ways to kill that process without being administrator from Java?
Didn't find how to run it without compatibility mode but could kill the process:
Create a batch file which contains
taskkill /F /IM FMLECmd.exe
Create a shortcut of this batch file
Go to the properties of shortcut.
Choose Shortcut tab
Click Advanced btn
Tick Run as administrator option
Start the shortcut using this java code:
String command = "start "+ pathToShortcut;
String[] cmd = { "cmd.exe", "/c", command };
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.start();
That worked for me
Related
There is windows process which is actually a java application (java.exe). I need to close it from within other java application (other running .jar) which is probably will also be named as java.exe in windows taskbar.
To do the task we would normally do it this way
Runtime.getRuntime().exec(KILL + serviceName); // where serviceName is a `java.exe`
But there would be some java.exe processes in windows taskbar. So how to find the one I need? In this case it is forum.jar.
Actually this jar was started from .bat file (if it makes any difference) - it is process.bat as it seen in the screenshot.
You could run
wmic process where caption="java.exe" get commandline,description,processid
to get the list of processes and their associated command line like in your screenshot. Then you get the ID of the command you want to kill and kill it with taskkill /pid xxx.
I recently changed my dedicated server and since then the script I use to restart my minecraft server isn't working anymore.
I can call the script using sh start.sh and my server starts, however when I use the in-game /restart command or when I instruct the server to restart from my plugin, the server closes and never restarts.
Here is the content of my start.sh
screen -dmS mc_hub1 java -jar -Xmx2048M -DIReallyKnowWhatIAmDoingISwear server.jar
Unless I'm running the script from the command-line, nothing happens, the screen isn't even created.
The issue seems to be originating from screen -dmS mc_hub1 because the restart instruction works if I remove it, actually it feels like I can't use anything related to screens from Java but it used to work so I'm a bit lost.
The dedicated server on which everything works is running Debian 9.9, Screen 4.05.00 and the new one is running Debian 9.11 and Screen 4.05.00.
I tried to add the -L option to enable logging but it doesn't even create the file,
Everything in the folder has read and execute permissions,
I tried to call the script from my plugin using java.lang.ProcessBuilder, no exception but still no result
ProcessBuilder pb = new ProcessBuilder("start.sh");
pb.directory(new File("/home/minecraft/uhc/"));
pb.start();
Java version doesn't seem to be causing the problem (I tested with the latest one and the one from my first dedicated server which is older)
Any help would be appreciated, thanks
I am trying to open a vi editor using Java code in an linux env (the java code is executed via shell script). The editor should open in foreground & become active terminal, while the java is should be running at Background.
I tried using both commands using :-
String []command = {"xterm", "vi", "/home/user/test.txt"};
Process pr = Runtime.getRuntime().exec(command);
Process p = new ProcessBuilder("vi", "/home/user/test35.txt").start();
In one of the above code, if check the ps -ef | grep vi, I am able to the process, but its running at background. I want to run it in foreground as an active terminal as user for his type the text into the editor. While the java will be running at the background.
Any suggestion or snippet's.
I have referred this Open VIM with Java application , but still in vain.
If you want to create a new xterm and execute a command in that terminal, you need to pass the command with -e. Try this:
ProcessBuilder pb = new ProcessBuilder("xterm", "-e", "vi", "/home/user/test.txt");
The debug steps I did was I tried opening a terminal via command & use the same command in the Java code. Issue observed that I need to set DISPLAY=:0. if I am running via root user , for other user export DISPLAY was not needed
String []command = {"/usr/bin/xterm","-e", "vi", "/home/hscpe/test.txt"};
Process pr = Runtime.getRuntime().exec(command);
Since I am running the java code via shell script I will be adding export in the shell script i.e export DISPLAY=:0. Now will try to make the editor as editable (Will stimulate by pressing I , i.e Insert by java robot).
I referred here & here
I am trying to execute .exe file from java by connecting to command prompt but, when i run the file i am getting a warning that windows has stopped the execution. Then after a long search i have changed the compatibility of file manually from windows xp to win 7 but i cannot do this manually every time because i am trying to automate entire procedure from the java code.
Help me out, if there is any way to change the compatibility mode from command prompt so that i can run that from java code
thanks in advance
You can use the Windows "reg" command to add/delete/read registry elements.
in the registry path HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers You will find all executables(.exe) compatibility options that have been changed, you can also add your own application and changed its options
This is a list of the available options you can change
Privilege Level:
RUNASADMIN - Runs the program with the administrative security token
Display Settings:
DISABLETHEMES - Disable Visual Themes
640X480 - Run in 640 x 480 screen resolution
HIGHDPIAWARE - Disable display scaling on high DPI settings
256COLOR - Run in 256 colors
DISABLEDWM - Disable Desktop Composition
Compatibility Mode:
WIN95 - Windows 95
WIN98 - Windows 98
WIN4SP5 - Windows NT 4.0 SP5
WIN2000 - Windows 2000
WINXPSP2 - Windows XP SP2
WINXPSP3 - Windows XP SP3
VISTARTM - Vista
VISTASP1 - Vista SP1
VISTASP2 - Vista SP2
WIN7RTM - Windows 7
WINSRV03SP1 - Windows Server 2003 SP1
WINSRV08SP1 - Windows Server 2008 SP1
Source
Here is an example how to run "reg add" command using Runtime method
String exePath = "C:\\Program Files\\MyApp\\Test5.exe";
String exe_run_option = "WINXPSP3";// run with Windows XP SP3 compatibilities
String command = "reg.exe Add \"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers\" /v \"" + exePath + "\" /d \"" + exe_run_option + "\"";
Process p = Runtime.getRuntime().exec(command);
//if the value already exists this will cause the reg command to pause and eat the cpu performance, so we give it a timeout
p.waitFor(2,TimeUnit.SECONDS);
//You can check the exit value of the process generally a 0 value means a succeed operation
try{
if(p.exitValue() != 0){
// we probably have an error
}
}catch(IllegalThreadStateException e){
//the process didn't finish execution and we tried to see it's exit value(terminated in 2 seconds forcibly)
//here you can try removing the key and adding it again with a different value using "reg delete" command (you might need to read the current value to add it together with the new one)
}
Please keep in mind
That if you need to add multiple values for one executable don't call the same command more than once for that application this will cause the reg editor to stun as pointed above, instead just add the value at the same time like this
String exe_run_option = "option1 option2 option3";//..etc
That this will only work with executable files (.exe), as an example you can't do this for a jar file instead you might use a .exe runner(wrapper) file and apply these options to it and then it runs the jar file.
That You must have administrator privileges to add elements to the registry thus the java application must have admin rights during the execution of the code above
This is also addressed here:
How can I set the compatibility mode for an executable from the command line?
Not sure if that helps.
The following code is for execute the command from java code.
Process p = Runtime.getRuntime().exec("your command");
p.waitFor();
I'm working on a (non-malicious) screen-locking sort of Swing application, and I've adapted code from Martijn Courteaux's answer at Use Java to lock a screen to do this. The problem is that when I use Runtime.getRuntime().exec("explorer.exe"); to reopen the Explorer process at program closing, Netbeans thinks that my project is still running because the resulting explorer.exe is running. CMD prompt and JCreator don't have this issue.
Can anyone give an example of the preferred way to call a command like explorer.exe to avoid this happening with Netbeans?
Edit: I close the Explorer process at the start of the program (which includes the taskbar). When I run Explorer, it's not to open a Windows Explorer window (which works totally fine with the given answers) but to restore the regular Windows UI.
The problem is Runtime#exec is waiting for the child process to exit. This is the default behavior.
If you want to execute a parentless process (a process in which the parent process can terminate even though the child is still running), you need to get a little more creative.
We use...
"cmd /C start /B /NORMAL " + yourCommand
I would highlight recommend using ProcessBuilder as it makes it significantly easier to build and execute external commands.
Something like...
ProcessBuilder pb = new ProcessBuilder("cmd", "/C", "start", "/B", "/NORMAL", "explorer.exe");
pb.start();
For example....
nb I run this is NetBeans and the program exited after/as explorer opened.
There is one little draw back. This doesn't like long file names. You'll need to find some way to produce short file names/paths for this to work. I was forced to use JNI solution for this
ProcessBuilder allows you to create and control processes.
Here's some example code, it's fairly complex but I don't have time to dumb it down (no offense): https://github.com/Xabster/Botster/blob/master/src/commands/ExecCommand.java