I have a program which requires Administrative privileges that I want to run from a batch file. What command can I run from command line will run my program with administrative privileges? I'm okay with the pop-up window asking for permission. Additionally, the file needs to be able to run from anywhere on a computer so additional files are run from ./src. The problem is that if I right-click and choose "run as administrator" it changes my current directory so ./src no longer works. If I disable UAC on my machine then everything runs fine. Thank you!
相关问题
- how to get running process information in java?
- Stop child process when parent process stops
- xcopy include folder
- Program doesn’t terminate when using processes
- Batch file if string starts by
相关文章
- Compile and build with single command line Java (L
- How to start a process in its own process group?
- Extracting columns from text file using Perl one-l
- How to update command line output?
- Looking for documentation on the “right” way to in
- How to execute another python script from your scr
- How can one batch file get the exit code of anothe
- How to redirect child process stdout/stderr to the
This is tough, Microsoft provides no utility to do this (mostly because giving a batch file that ability breaks security), except for RunAs, and that requires that the Administrator account be activated.
There IS a JScript program that can do something similar, by using SendKeys to open the Start menu and type cmd[CTL]+[SHIFT]+[ENTER] which will launch a Command-Line shell.
Save the following as as .js file, like StartAdmin.js:
To run StartAdmin.js from a batch file, you will need the following line:
To launch from a particular directory and launch a batch file, change line 2 in StartAdmin.js to something like:
/C switch tells it to run the commands, then close the command-line window.
/K would leave the command window open after it exited the batch file.
To help you understand the SendKeys commands:
To learn more about using CMD.EXE, type CMD /? at the command prompt.
This is a very untidy and ugly way to do it, but it's the only way I know how using only the tools that come with Windows.
Look here: https://superuser.com/a/269750/139371
elevate seems to be working, calling
executes
dir
in the "current directory" whereelevate
was called.