Skip to content

Instantly share code, notes, and snippets.

@yoav-lavi
Last active December 20, 2018 14:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoav-lavi/5293edb0408ce488f9842d8001b07fa1 to your computer and use it in GitHub Desktop.
Save yoav-lavi/5293edb0408ce488f9842d8001b07fa1 to your computer and use it in GitHub Desktop.
Run VS2017 remote debugger as the system session, even if no prerequisites are installed
@echo off
:: BatchGotAdmin
:-------------------------------------
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
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"
:--------------------------------------
echo Checking if Chocolatey is installed...
if exist C:\ProgramData\chocolatey\bin\cinst.exe (
echo Chocolatey is installed.
) else (
echo Chocolatey is not installed, installing now.
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
)
echo Checking if VS2017 Remote Debugger is installed...
if exist "C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\" (
echo VS2017 Remote Debugger is installed.
) else (
echo VS2017 Remote Debugger is not installed, installing now.
cinst visualstudio2017-remotetools -y
)
echo Checking if Sysinternals are installed...
if exist C:\ProgramData\chocolatey\lib\sysinternals\tools\PsExec.exe (
echo Sysinternals are installed.
) else (
echo Sysinternals are not installed, installing now.
cinst sysinternals -y
)
echo Killing any existing msvsmon.exe processes...
pskill -accepteula -nobanner msvsmon.exe
echo Running VS2017 Remote Debugger as SYSTEM...
psexec -accepteula -nobanner -sd -i 0 "C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe" /noauth /anyuser /port:4000 /nosecuritywarn
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment