-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathservice-manager.cmd
98 lines (83 loc) · 3.55 KB
/
service-manager.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@echo off
chcp 1251
::::::::::::::::::::::::::::::::::::::::::::
:: Elevate.cmd - Version 9 custom
:: Automatically check & get admin rights
:: see "https://stackoverflow.com/a/12264592/1016343" for description
::::::::::::::::::::::::::::::::::::::::::::
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================
:init
setlocal DisableDelayedExpansion
set cmdInvoke=1
set winSysFolder=System32
set "batchPath=%~dpnx0"
rem this works also from cmd shell, other than %~0
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion
:checkPrivileges
whoami /groups /nh | find "S-1-16-12288" > nul
if '%errorlevel%' == '0' ( goto checkPrivileges2 ) else ( goto getPrivileges )
:checkPrivileges2
net session 1>nul 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
if '%cmdInvoke%'=='1' goto InvokeCmd
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
goto ExecElevation
:InvokeCmd
ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"
:ExecElevation
"%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
exit /B
:gotPrivileges
setlocal & cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
taskkill /im "tor.exe"
sc query "Tor Win32 Service" | find "RUNNING" >nul
if %errorLevel% EQU 0 (
sc stop "Tor Win32 Service"
sc delete "Tor Win32 Service"
powershell -Command "(gc '%CD%\torrc.txt') "^
"-replace '^DataDirectory.*$', ('DataDirectory ..\data') "^
"-replace '^GeoIPFile.*$', ('GeoIPFile ..\data\geoip') "^
"-replace '^GeoIPv6File.*$', ('GeoIPv6File ..\data\geoip6') "^
"| Out-File -encoding default '%CD%\torrc.txt'"
) else (
powershell -Command "(gc '%CD%\torrc.txt') "^
"-replace '^DataDirectory.*$', ('DataDirectory \"%CD%\data\"' -replace '\\','\\') "^
"-replace '^GeoIPFile.*$', ('GeoIPFile \"%CD%\data\geoip\"' -replace '\\','\\') "^
"-replace '^GeoIPv6File.*$', ('GeoIPv6File \"%CD%\data\geoip6\"' -replace '\\','\\') "^
"| Out-File -encoding default '%CD%\torrc.txt'"
sc create "Tor Win32 Service" binPath= "\"%CD%\tor\tor.exe\" --nt-service -f \"%CD%\torrc.txt\"" start= "auto"
sc description "Tor Win32 Service" "Provides an anonymous Internet communication system"
sc start "Tor Win32 Service"
)
sc query "Tor Win32 Service" | find "STOPPED" >nul
if %errorLevel% EQU 0 (
sc delete "Tor Win32 Service"
powershell -Command "(gc '%CD%\torrc.txt') "^
"-replace '^DataDirectory.*$', ('DataDirectory ..\data') "^
"-replace '^GeoIPFile.*$', ('GeoIPFile ..\data\geoip') "^
"-replace '^GeoIPv6File.*$', ('GeoIPv6File ..\data\geoip6') "^
"| Out-File -encoding default '%CD%\torrc.txt'"
)
pause