-
Notifications
You must be signed in to change notification settings - Fork 6
/
RelaunchElevated.cmd
70 lines (62 loc) · 2.76 KB
/
RelaunchElevated.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
:: #########################################################################################
:: # MICROSOFT LEGAL STATEMENT FOR SAMPLE SCRIPTS/CODE
:: #########################################################################################
:: # This Sample Code is provided for the purpose of illustration only and is not
:: # intended to be used in a production environment.
:: #
:: # THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY
:: # OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
:: # WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
:: #
:: # We grant You a nonexclusive, royalty-free right to use and modify the Sample Code
:: # and to reproduce and distribute the object code form of the Sample Code, provided
:: # that You agree:
:: # (i) to not use Our name, logo, or trademarks to market Your software product
:: # in which the Sample Code is embedded;
:: # (ii) to include a valid copyright notice on Your software product in which
:: # the Sample Code is embedded; and
:: # (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and
:: # against any claims or lawsuits, including attorneys’ fees, that arise
:: # or result from the use or distribution of the Sample Code.
:: #########################################################################################
:: #########################################################################################
:: //***************************************************************************
:: //
:: // File: RelaunchElevated.cmd
:: //
:: // Additional files required: elevate.cmd and elevate.vbs
:: //
:: // Purpose: CMD script that will “re-launch itself” elevated if it is
:: // not already running elevated
:: //
:: // Usage: RelaunchElevated.cmd <arguments>
:: //
:: // Version: 1.0.0
:: //
:: // History:
:: // 1.0.0 06/19/2010 Created initial version.
:: //
:: // ***** End Header *****
:: //***************************************************************************
@echo off
setlocal enabledelayedexpansion
set CmdDir=%~dp0
set CmdDir=%CmdDir:~0,-1%
:: Check for Mandatory Label\High Mandatory Level
whoami /groups | find "S-1-16-12288" > nul
if "%errorlevel%"=="0" (
echo Running as elevated user. Continuing script.
) else (
echo Not running as elevated user.
echo Relaunching Elevated: "%~dpnx0" %*
if exist "%CmdDir%\elevate.cmd" (
set ELEVATE_COMMAND="%CmdDir%\elevate.cmd"
) else (
set ELEVATE_COMMAND=elevate.cmd
)
set CARET=^^
!ELEVATE_COMMAND! cmd /k cd /d "%~dp0" !CARET!^& call "%~dpnx0" %*
goto :EOF
)
:: Continue script here
echo Arguments passed: %*