How to call executable bat file with admin privilege from java program ? That executable is in another directory.
Asked
Active
Viewed 2,474 times
2
-
I tried the SO search "run as windows admin java" and found several answers already posted on this very subject. If the existing answers don't resolve the issue please post a very specific question with what is not working and what you have tried. – karakuricoder Apr 14 '11 at 11:48
-
[This will help](http://stackoverflow.com/questions/4183438/changing-windows-user-in-java/4183477#4183477) – jmj Apr 14 '11 at 11:48
-
5please don't ask for replies ASAP. – jzd Apr 14 '11 at 11:52
1 Answers
2
You need use the runas command. Something like the following:
Runtime.exec("runas /user:ROOTUSERNAME c:\yourdir\yourbat.bat");
Of course, the windows ROOTUSERNAME user must have admin priviledge.
P.S.: I don't know why people voted this question down, it is a valid one...

Jérôme Verstrynge
- 57,710
- 92
- 283
- 453
-
i want to run some command like "peach.bat peachpit.xml" how to pass arguments like option filename ? – Tukesh Apr 19 '11 at 07:07
-
You can add them to the string when calling Runtime.exec. If it is data, you first need to save it on file, then pass the location to your bat in the command line. – Jérôme Verstrynge Apr 19 '11 at 09:32