Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM You can remove this line if your current RMM deployment method runs scripts as admin or as a "system" user.
- call :RequestAdminElevation "%~dpf0" %* || goto:eof
- @ECHO OFF
- CLS
- set dlURL=http://yourdownload.com/location
- set localinstallfolder=C:\temp
- if not exist %localinstallfolder% mkdir %localinstallfolder%
- bitsadmin.exe /transfer "AVG Device Manager" /PRIORITY FOREGROUND "%dlURL%/DMSetup.exe" "%localinstallfolder%\DMSetup.exe"
- REM Registry key required per AVG instructions
- REM https://support.avg.com/SupportArticleView?l=en_US&urlname=Managed-Workplace-Automating-Silent-Device-Manager-Deployment
- REM **NOTE** The above URL has a new line/carriage return between "managed" and "workplace". I don't know if it's supposed to be "Managed Workplace" or "ManagedWorkplace"
- reg add "HKLM\SOFTWARE\Level Platforms\ManagedWorkplace\Onsite Manager\Install" /v DMSilentMode /d true /f
- REM Run the install wizard for DMSetup.exe silently.
- call "%localinstallfolder%\DMSetup.exe -y"
- REM You can remove everything below here if your RMM solution runs scripts as admin or "System" account.
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :RequestAdminElevation FilePath %* || goto:eof
- ::
- :: By: Cyberponk, v1.3 - 01/08/2015 - Fixed not returning to original folder after elevation successful
- :: v1.2 - 30/07/2015 - Added error message when running from mapped drive
- :: v1.1 - 01/06/2015
- ::
- :: Func: opens an admin elevation prompt. If elevated, runs everything after the function call, with elevated rights.
- :: Returns: -1 if elevation was requested
- :: 0 if elevation was successful
- :: 1 if an error occured
- ::
- :: USAGE:
- :: If function is copied to a batch file:
- :: call :RequestAdminElevation "%~dpf0" %* || goto:eof
- ::
- :: If called as an external library (from a separate batch file):
- :: set "_DeleteOnExit=0" on Options
- :: (call :RequestAdminElevation "%~dpf0" %* || goto:eof) && CD /D %CD%
- ::
- :: If called from inside another CALL, you must set "_ThisFile=%~dpf0" at the beginning of the file
- :: call :RequestAdminElevation "%_ThisFile%" %* || goto:eof
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- setlocal ENABLEDELAYEDEXPANSION & set "_FilePath=%~1"
- if NOT EXIST "!_FilePath!" (ECHO/Read RequestAdminElevation usage information)
- :: UAC.ShellExecute only works with 8.3 filename, so use %~s1
- set "_FN=_%~ns1" & ECHO/%TEMP%| findstr /C:"(" >nul && (ECHO/ERROR: %%TEMP%% path can not contain parenthesis &pause &endlocal &fc;: 2>nul & goto:eof)
- :: Remove parenthesis from the temp filename
- set _FN=%_FN:(=%
- set _vbspath="%temp:~%\%_FN:)=%.vbs" & set "_batpath=%temp:~%\%_FN:)=%.bat"
- :: Test if elevated
- >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
- :: If error flag set, we do not have elevation
- if "%errorlevel%" NEQ "0" goto :_getElevation
- :: Elevation successful
- (if exist %_vbspath% ( del %_vbspath% )) & (if exist %_batpath% ( del %_batpath% ))
- :: Set ERRORLEVEL 0, set original folder and exit
- endlocal & CD /D "%~dp1" & ver >nul & goto:eof
- :_getElevation
- ECHO/Requesting elevation...
- :: Try to create %_vbspath% file. If failed, exit with ERRORLEVEL 1
- ECHO/Set UAC = CreateObject^("Shell.Application"^) > %_vbspath% || (ECHO/&ECHO/Unable to create %_vbspath% & endlocal &md; 2>nul &goto:eof)
- ECHO/UAC.ShellExecute "%_batpath%", "", "", "runas", 1 >> %_vbspath% & ECHO/wscript.Quit(1)>> %_vbspath%
- :: Try to create %_batpath% file. If failed, exit with ERRORLEVEL 1
- ECHO/@%* > "%_batpath%" || (ECHO/&ECHO/Unable to create %_batpath% & endlocal &md; 2>nul &goto:eof)
- ECHO/@if %%errorlevel%%==9009 (ECHO/Admin user could not read the batch file. If running from a mapped drive or UNC path, check if Admin user can read it.) ^& @if %%errorlevel%% NEQ 0 pause >> "%_batpath%"
- :: Run %_vbspath%, that calls %_batpath%, that calls the original file
- %_vbspath% && (ECHO/&ECHO/Failed to run VBscript %_vbspath% &endlocal &md; 2>nul & goto:eof)
- :: Vbscript has been run, exit with ERRORLEVEL -1
- ECHO/&ECHO/Elevation was requested on a new CMD window &endlocal &fc;: 2>nul & goto:eof
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement