2

I created simple .cmd file:

sc stop audiosrv
sc start audiosrv

but I have to right click and "Run as Administrator" how can I set this file to run as admin by default after double left click?

1
  • 3
    create a shortcut then modify the properties. This will still required the approval of the esclation of the process which means a UAC prompt.
    – Ramhound
    May 6, 2014 at 13:09

2 Answers 2

1

Call it with PSEXEC -h

That will work. Other than that, you can disable UAC completely.

0

Put this before your script starts:

@echo off

:: 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"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B

:gotAdmin
pushd "%CD%"
CD /D "%~dp0"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.