-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34b9754
commit 939b2c9
Showing
1 changed file
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,48 @@ | ||
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit ) | ||
@ECHO OFF | ||
setlocal EnableDelayedExpansion | ||
|
||
::net file to test privileges, 1>NUL redirects output, 2>NUL redirects errors | ||
NET FILE 1>NUL 2>NUL | ||
if '%errorlevel%' == '0' ( goto START ) else ( goto getPrivileges ) | ||
|
||
:getPrivileges | ||
if '%1'=='ELEV' ( goto START ) | ||
|
||
set "batchPath=%~f0" | ||
set "batchArgs=ELEV" | ||
|
||
::Add quotes to the batch path, if needed | ||
set "script=%0" | ||
set script=%script:"=% | ||
IF '%0'=='!script!' ( GOTO PathQuotesDone ) | ||
set "batchPath=""%batchPath%""" | ||
:PathQuotesDone | ||
|
||
::Add quotes to the arguments, if needed. | ||
:ArgLoop | ||
IF '%1'=='' ( GOTO EndArgLoop ) else ( GOTO AddArg ) | ||
:AddArg | ||
set "arg=%1" | ||
set arg=%arg:"=% | ||
IF '%1'=='!arg!' ( GOTO NoQuotes ) | ||
set "batchArgs=%batchArgs% "%1"" | ||
GOTO QuotesDone | ||
:NoQuotes | ||
set "batchArgs=%batchArgs% %1" | ||
:QuotesDone | ||
shift | ||
GOTO ArgLoop | ||
:EndArgLoop | ||
|
||
::Create and run the vb script to elevate the batch file | ||
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs" | ||
ECHO UAC.ShellExecute "cmd", "/c ""!batchPath! !batchArgs!""", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs" | ||
"%temp%\OEgetPrivileges.vbs" | ||
exit /B | ||
|
||
:START | ||
::Remove the elevation tag and set the correct working directory | ||
IF '%1'=='ELEV' ( shift /1 ) | ||
cd /d %~dp0 | ||
|
||
cd "%~dp0" | ||
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned .\mw5-sync.ps1 |