Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically running a batch file as an administrator

Tags:

batch-file

How do I run a batch file from another batch file with administrator rights?

I have tried the RUNAS command, but it requires the administrator password.

I am searching for an alternative for running a batch file by right clicking on it and running as an administrator. I want to automate it from another batch file.

like image 332
Vinay KV Avatar asked Sep 12 '13 04:09

Vinay KV


People also ask

Is it possible to automatically run a batch file as administrator?

Yes, you're able to run a batch file with administrative rights.

How do I schedule a batch file to run as administrator?

Step 1: Open the Start Menu and type command prompt on the search bar. Step 2: Select Command Prompt and then on the right-side panel click on Run as Administrator. Step 3: The command prompt opens with the title Administrator: Command Prompt. Type the batch file path and name and press Enter.

How do I run a batch file as administrator in CMD?

So instead You just right click on your "file. bat - shortcut" then go to ->Properties->Shortcut tab -> Advanced and there you can click Run as administrator. After that, You can execute the shortcut.


1 Answers

Put each line in cmd or all of theme in the batch file:

@echo off  if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)  "Put your command here" 

it works fine for me.

like image 179
Hossein Jafarinejad Avatar answered Sep 21 '22 21:09

Hossein Jafarinejad