Reputation: 37
in cmd, if I enter the code
taskkill /f /im explorer.ex
it ends explorer. But if I enter
taskkill /f /im taskmgr.exe
It says the access was denied and the only way to do it is open cmd as admin. Is there any way to do it without open as admin, or is there a way that when you open a batch script, it automatically opens as administrator ? Thanks in advance.
Upvotes: 0
Views: 39
Reputation: 4219
I've been using this template for admin tasks a while. Hope it helps you.
:: Verify we don't have administrator privileges
net file >nul 2>&1
if "%errorlevel%" equ "0" goto :admin
:: Execute VB script to execute the script with elevated privileges
(
echo Set UAC = CreateObject^("Shell.Application"^)
echo UAC.ShellExecute "%~dpf0", "", "%~dp0", "runas", 1
) > "%temp%\get-privileges.vbs"
"%temp%\get-privileges.vbs"
exit /b
:admin
::Administrator work here!!
Upvotes: 2