Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Run as Administrator command name

11 May 2014   #1
John256145

Windows 7 Home Premium 64-bit
 
 
Run as Administrator command name

Is there a command to insert into a batch file so the file can ask for administrator approval before continuing?


My System SpecsSystem Spec
.

11 May 2014   #2
Brink
Microsoft MVP

64-bit Windows 10 build 10158
 
 

Hello John,

I'm not sure about with a .bat file, but you could use this below with a .vbs file to have it prompt with UAC for elevation approval.

Code:
If WScript.Arguments.Count = 0 Then
 Set objShell = CreateObject("Shell.Application")
 objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " Run", , "runas", 1
Else
 
Your code here
 
End If
Hope this helps,
Shawn
My System SpecsSystem Spec
11 May 2014   #3
DavidE

Win 7 Pro x64 SP1, Win 7 Ult x86 SP1
 
 

You can also create a Shortcut with Run as administrator to run the .bat file.
My System SpecsSystem Spec
.


11 May 2014   #4
John256145

Windows 7 Home Premium 64-bit
 
 

Quote   Quote: Originally Posted by Brink View Post
[CODE]If WScript.Arguments.Count = 0 Then
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " Run", , "runas", 1
Else
Close Enough.
My System SpecsSystem Spec
11 May 2014   #5
Brink
Microsoft MVP

64-bit Windows 10 build 10158
 
 

I'm glad that'll work for you.
My System SpecsSystem Spec
12 May 2014   #6
andrew129260

Windows 7 Professional x64 Sp1
 
 

Yes there is a very easy way to have UAC ask for a batch file to prompt to run as admin:

See this code:

Code:
:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt

    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"

    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"




    "%temp%\getadmin.vbs"

    exit /B

:gotAdmin

    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )

    pushd "%CD%"


    CD /D "%~dp0"

:--------------------------------------
My System SpecsSystem Spec
Reply

 Run as Administrator command name




Thread Tools





Similar help and support threads
Thread Forum
Open Command Window Here as Administrator
Add or Remove "Open Command Window Here as Administrator" to Context Menu This will show you how to add or remove Open Command Window Here as Administrator to the context menu of a folder, drive, and desktop of all users to open an elevated command prompt with the focus at the folder, drive,...
Tutorials
Cannot Run command as Administrator
Hello, I have been buried by a cascade of issues that just drove me to a dead end. Everything started when one of the applications I use couldn't install properly. Now everytime I try to run this application it says that the folder d:\windows\assembly\gac_32\mscorlib\... is corrupted. Weirdly...
Performance & Maintenance
Run as administrator command has stopped working
Whenever I try to "run as administrator" a .exe file nothing happens aside from the window I was using to browse to the file freezing. Any ideas on what is wrong or how to fix it?
General Discussion
elevated command administrator password
I am writing a vba script for a standard user to run a program in elevated mode. Is there a way to program in the administrative password? ie..elevate "cmd /k mkdir "newfolder" The goal is to enable the standard user to create a new subfolder within a directory they don't have permission...
General Discussion
I've lost my Run As Administrator command
In my context menu, I had lost my Run As Administrator command. I had installed a Take Ownership command for installing WMP11 but uninstalled it because I wanted RAA. But, it doesn't show up in my context menu anymore. Anyway to solve?
Performance & Maintenance
Run login command as Administrator
I used to have a network drive mapped to U:, but I have moved it to the local machine. Some programs (one in particular: iTunes) don't do well if you move their file paths around, plus it would be nice if all the machines on the network could have the same setup. So now I want to have a virtual...
Network & Sharing

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 14:46.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App