How run file .bat as admin - batch-file

I have question how run file .bat as admin? How run cmd as admin in file bat?
I must run command on cmd:
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -px "MyKey" c:\key.xml -pri
Please help and have any tips or any good material.

Use RUNAS command for this purpose like below. See help using runas /? in command prompt
runas /user:administrator "%windir%\Microsoft.NET\Framework\v2.0.5
0727\aspnet_regiis.exe -px "MyKey" d:\key.xml -pri"
Enter the password for administrator:

open start menu by pressing windows key type cmd right click cmd and select Run as administrator this will open the command prompt in administrator mode and then you can run your command as an administrator.

Related

I need to have a batch file's opening line makeing it run as Admin. I know the Runas command, but can I runas in the batch file already open?

I was wondering if there was any code that would make the current script run in Admin privileges. So I can run a batch file and it is something like
run as admin*
{code}
It is an automaticly run script so I can't right click and run as admin, and I want to be clean and not need another script to use runas to run it as an admin.
I've tried runas, and pointing it to that script it is in, with no luck.

Run batch file as admin, hidden, from inno setup

I have an Inno Setup installation which successfully run a batch file when finished. The batch asks for admin rights, gets them and does things.
I've been asked to completely hide the prompt window, so I've added "Flags: runhidden" in Inno Setup and #echo off and >nul 2>nul in the batch. But the batch still flash a prompt window, because of this:
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & goto
batch & exit /b)
EXIT /b
:batch
---MyCodeHere---
I have not written this code by myself and I'm not expert about batch programming, but I'm pretty sure that these lines open a new prompt with admin permissions, and that's the prompt flashing.
Does anyone know if there's a solution to this? Maybe some flag to add to "powershell start", or another completely different way to do this task.
Thank you all in advance
Don't make the batch file ask for Administrator permissions.
Run the batch file with Administrator permissions straight away:
Run process (net.exe or sc.exe) with Administrator privileges at the end of an installation in Inno Setup
[Run]
Filename: "{app}\my.bat"; Description: "Run my batch file"; \
Flags: postinstall runascurrentuser runhidden

Give Admin privileges to exe application

I'm starting an exe application through a .bat file, I want to start it granting admin privileges to it. How can I do it in a .bat file.
Two basic options:
Run the script as admin
Use the 'runas' command e.g.
runas /user:administrator blah.exe
Runas will then prompt for the admin password.

Run a command promt and run a command

I need to write a command which is calling other command prompt of Oracle and running a command on it. Currently, I am running it using below command
D:\Oracle\setenv.bat /k BuildApp
But it only runs setenv.bat and quits and doesn't run BuildApp. BuildApp is to run on a command prompt opened by setenv.bat. Can anyone please help on this?
Try CMD /c d:\Oracle\setenv.bat /k BuildApp.

Command Prompt Runas cscript

I have get_data.vbs located in C:/test/source/. I've created run.bat file in C:/test/bin.
I'm able to run vbs script when I put the following in bat file:
cscript ../source/get_data.vbs
Q: Why it doesn't work when I use runas command:
runas /user:domain\username "cscript \"../source/get_data.vbs""
If I put full path, it works without any issues:
runas /user:domain\username "cscript \"C:/test/source/get_data.vbs""
Thanks in advance
It didn't work because runas is started on its current directory %windir%\System32 and there is no /source/get_data.vbs there.
If you want to make sure of this, try this code:
start /separate runas /user:domain\username "cscript \"../source/get_data.vbs""
You will see on title of the Window that opened something like C:\Windows\System32\runas.exe

Resources