Im struggling to run a vbscript from java as administrator. I need my java program to run the command in an elevated command prompt in order for the script to execute properly.
I use the following code to call the command
Process child = Runtime.getRuntime().exec("cscript C:\Some\Path\Name\ScriptName.vbs "); child.waitFor();
But it runs a normal prompt. I have tried creating a runnable jar to run as admin, but it doesn’t start my program. I am currently building and running it from eclipse, which works fine except that the only way to get my script to run is to have it elevate and restart itself. This option doesn’t work because my java code doesn’t wait for the second process to finish.
I have seen some documentation on an elevate.exe command but i get an error message that the command isn’t recognized.
How do I get java to run my script as admin without having it elevate itself?
EDIT: Creating a shortcut doesn’t work for a vbs. Putting this in front of my command doesnt work either, because it prompts the user for a password.
runas /profile /user:Administrator
The answers to other questions already posted have not worked for me, which is why I asked this as a different question. Maybe someone can claify the usage of the elevate command in windows, since I cannot seem to find documentation on it that allows me to run it.