jrfonseca / drmingw

Postmortem debugging tools for MinGW.
GNU Lesser General Public License v2.1
279 stars 56 forks source link

easier installation #44

Open Optiligence opened 5 years ago

Optiligence commented 5 years ago

From time to time i let users install Dr. Mingw and it’s a bit weird to tell them that they have to open an Admin command prompt, navigate to the extracted folder and execute some command to get it working.

Logic like this could imo be implemented as part of the usage prompt that comes up if you execute drmingw.exe in the explorer, but i currently simply share the following script which could be included as is without much further work needed:

REM http://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file#10052222
@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>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"
:--------------------------------------
"%CD%/bin/drmingw.exe" -i
jrfonseca commented 2 years ago

It would be better to avoid batch, and have drmingw to call itself again with elevator priviledges, and the same command line parameters, as exemplified in https://stackoverflow.com/a/6418873