Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a program with admin privileges in a batch file

How do I start/call a batch file from another, but with administrative privileges, so that it doesn't give me errors like the following?

Access is denied error code 5

Here is something like what I would like it to be.

echo PLEASE TYPE YOUR USERNAME AND PASSWORD IN THE FIELDS BELOW.
echo.
echo.
echo.
echo.
set /p u=Username:
echo.
set /p p=Password:
start next.bat %u% %p%
like image 905
cmd Avatar asked Aug 04 '13 16:08

cmd


People also ask

How do I Run a program with administrator rights?

Press and hold down the SHIFT key while you right-click the executable file or the icon for the application, and then select Run as. Select The following user. In the User name and Password boxes, type the administrator account and password, and then select OK.

How do I Run a program as administrator in cmd?

Click on Command Prompt to open the application and type your first command. Right-click on the application and select "Run as administrator," then a new Command Prompt window opens.

How do I Run a batch file with administrator privileges in task scheduler?

In the Start in (optional) field, enter the directory path to the task files. Click OK. You are prompted for the Windows user name and password. Enter the Administrator user name and password and click OK to run the task.


1 Answers

No matter which way you chose, You must accept run it with admin privilege, so the point is which way is shorter? You could Right Click > Run as administrator as jean-Michael said although I prefer james approach (using vbScript) but if you don't want to use another vbScript file and just want benefit of just click on batch file and accept run with admin privilege (Note you have one right click and left click less) I suggest you this:

create a shortcut from your batch file and right click on shortcut > Properties > Shortcut Tab > Advanced now check the Run as administrator check-box. every time you execute it from the shortcut you just have one click to accept run it with admin privilege.

Hope this help.

like image 134
QMaster Avatar answered Oct 02 '22 07:10

QMaster