I'm developing a Java Swing App to automate installation and configuration of some Off the shelf products. At a certain point in a product installation, it becomes imperative that I stop a Service (to avoid a file in use problem in another installation). I am using runtime.exec (see code) to execute various windows installers etc. Are there commands available which I could execute to exercise control on Windows services?
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
C:\>net The syntax of this command is: NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP | HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION | SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ] C:\>
"net stop" is one of the subcommands (as above).
C:\>net stop The syntax of this command is: NET STOP service C:\>
As you might guess, there is of course a parallel "net start".
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
C:\>sc 'sc' is not recognized as an internal or external command, operable program or batch file.
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Yes, I noticed that too when I tried it. I don't have an sc command on my Windows XP Home system either.
I am running into problems executing net stop "service name" from my runtime. The process never ends.
I have code to spawn threads to empty error and output streams from the net stop process. These threads never get end of file on their streams and my main application never gets control back from
Do you have any hints as to what may be going wrong?
Here is the code which sets up and invokes net stop and checks for completion.
[ Jess adjusted the 2nd code block to shrink the whitespace so it wouldn't stretch the screen ] [ September 23, 2004: Message edited by: Jessica Sant ]
Actually, I found out what was wrong and everything is running OK now.
The problem is that I (and you apparently) assumed that net is internal to command.com or cmd.exe. The fact is is that it is not a command processor internal. It is some other kind of windows executable (.exe?) and therefore should be invoked in the exec as "net stop \"SERVICE NAME\" " This works fine, command.com or cmd.exe are not involved. I also discovered that the command "net stop 'SERVICE NAME' " does not work. The runtime exec requires double quotes on a command line parameter which has embedded spaces, so the internal double quotes must be escaped.
> The problem is that I (and you apparently) assumed that net is internal to command.com or cmd.exe.
I didn't assume it. The point I wanted to make is that when using cmd.exe, you must use the "/c" flag. That's all. For instance, don't do "cmd.exe set" but rather "cmd.exe /c set".
By the way it works perfectly well if you try it with a command-line executable, like net.exe, as I previously wrote. But you're right, it's overhead to use the cmd shell for any command-line executable.