notepad.exe is not opening in tomcat but works in eclipse - java

My requirement is to open the notepad using processbuilder.
If we run the
C:\>notepad.exe
In command line or eclipse (through java using processbuilder )the process is created like below.
Name PID status UserName
notepad.exe 8380 Running Selva
The process is created in task manager and also notepad is opening and we can able to execute the command again and again.
But If we run the command from Tomcat using java process builder(Tomcat started through services.msc) the process is created like below.
Name PID status UserName
notepad.exe 8380 Running SYSTEM
The process is created in task manager.But notepad is not opening in the system and also we can't able to run the command again.Because it's showing,
"The process cannot be accessible,because it's being used by another process"
Why the process is created with the name "SYSTEM" instead of "Selva" in tomcat and why the notepad is not opening.
How to fix this issue?
Any help will be greatly appreciated!!

Services run in the background - regardless whether a user is logged on or not. Thus they usually have no access to the GUI. Windows redirects their GUI output to a 'hidden' desktop.
This problem is per Windows design and not related to Java. See also Swing JDialog is showing fine when I run it from eclipse but not working from windows service(services.msc)

Related

How to defferentiate several running java Jar in windows

I have a Windows server which run several java .jar running in the background.
For example programABC.jar, programDEF.jar, and so on.
They were triggered trough the Windows task scheduler.
I can see through DOS command line tasklist or Windows "Task Manager" there are a couple of java.exe currently running, I can also tell their Process ID. But I don't know which instance belong to which jar program. How to identify these processes?
As a comparison in linux if we have the Process ID we can just cat /proc/YOURPID/maps that will give a clue what is the program name, run from where, etc.
Thanks in advance
In Task Manager processes tab click View|Select Columns. Scroll down the list then select "Command Line" then OK. You should see the command line of the process which should include the .jar file used.

Launch Minecraft 1.7.10 from command line

I've been trying to make a batch file in Windows to directly launch Minecraft 1.7.10. However, the method I tried had changed since the new launcher has been released. Does anyone know how I could directly launch it from the command line, with my username and session token? I legally own Minecraft, so I should be able to use my session token and username.
Try to run Minecraft 1.7.10 normally then use task manager or another program to get the command used to launch the program.

running application from cmd as administrator through java code

I executed the netsh command from the CMD that was manually opened by me by right clicking the CMD icon from the start and then selecting run as administrator from the options.It worked fine.Now I tried to run the netsh command through my java code,then it is not working.Nothing is happening when i run that code.I want to ask that I can run applications like notepad.exe from the cmd by calling appropriate methods of the runtime class from my java code,But how can I open the same application with the administrator priviliges from my java code.r.exec("notepad"); where r is an object reference to the runtime class will run the application,but the notepad so opened will not be in administrator mode.Actually I guess that learning to run the application in administrator mode from CMD will be enough to do the work done as The corresponding CMD command will be passed as the argument to the exec() method of the Runtime class.So my questions are:
How to run any application from CMD in windows 8 with administrator privilliges?
The way i want to implement the use of netsh is a good thing to practise or there is some other way out i must use these commands from my java code.
I have seen some commands while googling but they where not working out for me,like runas /user:administrator "notepad.exe" etc.
Thanks
You cannot use the runas /user:administrator approach, as that requires a password input which you cannot provide from an external source (such as a Java application) for security reasons.
I had a similar issue to you in the past, and I solved it using PsExec, running the process on localhost with an administrator username and password allowed me to execute external applications as an administrator.
Using your example you could run:
PsExec.exe \\\\127.0.0.1 /accepteula -u USER -p PASSWORD notepad.exe
The "/accepteula" flag prevents the requirement to accept the EULA interactively when run on a machine for the first time.
This approach may require a bit of tweaking to get working with your setup, but hope it gives you a starting point.

Running a Java Application on a Shared Drive from Windows Task Scheduler Client Side

First, just wanted to thank everyone in advance for helping with this, let me take you on my journey...
Task: Run a Java application that is located in a folder on a file server using Windows Task Scheduler, simple enough.
The caveat, is that I would like to utilize the task scheduler option of "Run whether user is logged on or not." and this seems to be a tricky function...
I have set my account as the account that the task is to run under.
What have I tried?
Creating a task based on these actions:
Java.exe -jar "path to share jar"
Java.exe -jar "path to local jar"
Javaw.exe -jar "path to share jar"
Javaw.exe -jar "path to local jar"
All have had the same result with the "Run whether use is logged on or not." option : 0x1
Next, I tried creating a batch file to run this on my behalf and changed the task to run that batch file and I got all the same results. I have read that utilizing the "Start in (optional)" field of an action may solve the problem, but it did not.
After that, I created a .vbs file with code similar to the following:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0
Set WshShell = Nothing
This achieved a 'silent run', but task scheduler still did not run with the "Run whether use is logged on or not.", and ended in 0x1.
All of these work fine with the "Run only when user is logged on." option.
The reason I want to do it whether I am logged on or not, is because I want to run my application before I come in to work.
Update:
I've disocvered a few things. In power options for Windows, I had to enable the ability for scheduled tasks to wake the computer, felt kind of dumb about that one.
Using a simpler task - one that just creates a blank text file - this option works fine. I belive the problem lies with executing Java.
The task needs a user to run. It doesn't have to be the user that is logged in, of course, but a user is needed anyway.
Make a batch file (or equivalent) that works when you launch it manually
Schedule the same batch file (with cmd /c c:\full\path\to\batch.bat) to run as yourself, with your password and everything.
Now you are ready to debug your problem
The user Windows will use to run your task when no one is logged needs all the tools configured and working. For exemple, does local service have all the path and registry settings set ? Is the share readable by that user (the SYSTEM account does not have network credentials).
To help in debugging, use psexec. This command line will allow you to run your script under the SYSTEM account. Something like
psexec -dies cmd /c c:\full\path\to\batch.bat
+Welcome to SO !

Installation failed due to low priviledge on Win8

I am using Java code to install an EXE program on Win8, by executing this command "java -jar installapp.jar" in CML. The command line window is NOT opened by "Run as administrator", but the current user is a member of administrator group.
However, in the same CML window, if I install the EXE directly, it works. It just fails when the installation is executed by Java.
So anyone can give me a tip?
Thanks a lot,
Michael
To correctly install an application which includes writing to system-protected areas can't be done without elevating through UAC. That means the CML window must be Run as administrator.
Java executables are marked with manifest which requests asInvoker privileges. So the process would start with administrator tokens dropped if the parent process wasn't elevated. It's the whole point of UAC: even if you are member of Administrators group, you don't get the full, unlimited privileges until you elevate.
What do you mean by "install the exe directly"?

Categories