Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. REM You can remove this line if your current RMM deployment method runs scripts as admin or as a "system" user.
  2. call :RequestAdminElevation "%~dpf0" %* || goto:eof
  3.  
  4. @ECHO OFF
  5. CLS
  6. set dlURL=http://yourdownload.com/location
  7. set localinstallfolder=C:\temp
  8. if not exist %localinstallfolder% mkdir %localinstallfolder%
  9. bitsadmin.exe /transfer "AVG Device Manager" /PRIORITY FOREGROUND "%dlURL%/DMSetup.exe" "%localinstallfolder%\DMSetup.exe"
  10.  
  11. REM Registry key required per AVG instructions
  12. REM https://support.avg.com/SupportArticleView?l=en_US&urlname=Managed-Workplace-Automating-Silent-Device-Manager-Deployment
  13. 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"
  14. reg add "HKLM\SOFTWARE\Level Platforms\ManagedWorkplace\Onsite Manager\Install" /v DMSilentMode /d true /f
  15.  
  16. REM Run the install wizard for DMSetup.exe silently.
  17. call "%localinstallfolder%\DMSetup.exe -y"
  18.  
  19.  
  20. REM You can remove everything below here if your RMM solution runs scripts as admin or "System" account.
  21. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  22. :RequestAdminElevation FilePath %* || goto:eof
  23. ::
  24. :: By: Cyberponk, v1.3 - 01/08/2015 - Fixed not returning to original folder after elevation successful
  25. :: v1.2 - 30/07/2015 - Added error message when running from mapped drive
  26. :: v1.1 - 01/06/2015
  27. ::
  28. :: Func: opens an admin elevation prompt. If elevated, runs everything after the function call, with elevated rights.
  29. :: Returns: -1 if elevation was requested
  30. :: 0 if elevation was successful
  31. :: 1 if an error occured
  32. ::
  33. :: USAGE:
  34. :: If function is copied to a batch file:
  35. :: call :RequestAdminElevation "%~dpf0" %* || goto:eof
  36. ::
  37. :: If called as an external library (from a separate batch file):
  38. :: set "_DeleteOnExit=0" on Options
  39. :: (call :RequestAdminElevation "%~dpf0" %* || goto:eof) && CD /D %CD%
  40. ::
  41. :: If called from inside another CALL, you must set "_ThisFile=%~dpf0" at the beginning of the file
  42. :: call :RequestAdminElevation "%_ThisFile%" %* || goto:eof
  43. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  44. setlocal ENABLEDELAYEDEXPANSION & set "_FilePath=%~1"
  45. if NOT EXIST "!_FilePath!" (ECHO/Read RequestAdminElevation usage information)
  46. :: UAC.ShellExecute only works with 8.3 filename, so use %~s1
  47. set "_FN=_%~ns1" & ECHO/%TEMP%| findstr /C:"(" >nul && (ECHO/ERROR: %%TEMP%% path can not contain parenthesis &pause &endlocal &fc;: 2>nul & goto:eof)
  48. :: Remove parenthesis from the temp filename
  49. set _FN=%_FN:(=%
  50. set _vbspath="%temp:~%\%_FN:)=%.vbs" & set "_batpath=%temp:~%\%_FN:)=%.bat"
  51.  
  52. :: Test if elevated
  53. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  54. :: If error flag set, we do not have elevation
  55. if "%errorlevel%" NEQ "0" goto :_getElevation
  56.  
  57. :: Elevation successful
  58. (if exist %_vbspath% ( del %_vbspath% )) & (if exist %_batpath% ( del %_batpath% ))
  59. :: Set ERRORLEVEL 0, set original folder and exit
  60. endlocal & CD /D "%~dp1" & ver >nul & goto:eof
  61.  
  62. :_getElevation
  63. ECHO/Requesting elevation...
  64. :: Try to create %_vbspath% file. If failed, exit with ERRORLEVEL 1
  65. ECHO/Set UAC = CreateObject^("Shell.Application"^) > %_vbspath% || (ECHO/&ECHO/Unable to create %_vbspath% & endlocal &md; 2>nul &goto:eof)
  66. ECHO/UAC.ShellExecute "%_batpath%", "", "", "runas", 1 >> %_vbspath% & ECHO/wscript.Quit(1)>> %_vbspath%
  67. :: Try to create %_batpath% file. If failed, exit with ERRORLEVEL 1
  68. ECHO/@%* > "%_batpath%" || (ECHO/&ECHO/Unable to create %_batpath% & endlocal &md; 2>nul &goto:eof)
  69. 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%"
  70.  
  71. :: Run %_vbspath%, that calls %_batpath%, that calls the original file
  72. %_vbspath% && (ECHO/&ECHO/Failed to run VBscript %_vbspath% &endlocal &md; 2>nul & goto:eof)
  73.  
  74. :: Vbscript has been run, exit with ERRORLEVEL -1
  75. ECHO/&ECHO/Elevation was requested on a new CMD window &endlocal &fc;: 2>nul & goto:eof
  76. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement