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

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
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

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

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

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
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

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

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 for2: Run as Administrator command name
Thread Forum
Solved Cannot Run command as Administrator Performance & Maintenance
Open Command Window Here as Administrator Tutorials
Run as administrator command has stopped working General Discussion
Solved I've lost my Run As Administrator command Performance & Maintenance
Run login command as Administrator 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 12:57 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33