1
+ < !-- : Begin batch script
2
+
1
3
@ echo off
4
+ setlocal enableDelayedExpansion
2
5
3
6
:checkPrivileges
4
- NET FILE 1 > NUL 2 > NUL
5
- if ' %errorlevel% ' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
7
+ net file 1 > nul 2 > nul
8
+ if " %errorlevel% " == " 0 " ( goto gotPrivileges ) else ( goto getPrivileges )
6
9
7
10
:getPrivileges
8
- if '%~1 '== 'ELEV' (shift & goto main)
9
- ECHO .
10
-
11
- setlocal DisableDelayedExpansion
12
- set " batchPath = %~0 "
13
- setlocal EnableDelayedExpansion
14
- ECHO Set UAC = CreateObject^ (" Shell.Application" ^ ) > " %temp% \OEgetPrivileges.vbs"
15
- ECHO UAC.ShellExecute " !batchPath! " , " ELEV" , " " , " runas" , 1 >> " %temp% \OEgetPrivileges.vbs"
16
- " %temp% \OEgetPrivileges.vbs"
17
- exit /B
11
+ cscript //nologo " %~f0 ?.wsf" //job:ADMIN " --self" %*
12
+ exit /b
18
13
19
14
:gotPrivileges
20
- @ echo off
21
- setlocal enableDelayedExpansion
22
15
cls
16
+ REM See if we have a custom script passed
17
+ set " target = ProperTree.bat"
18
+ set " name = ProperTree"
19
+ if NOT " %~1 " == " " (
20
+ set " target = %~nx1 "
21
+ set " name = %~n1 "
22
+ )
23
23
REM Get one directory up
24
24
pushd %~dp0
25
25
cd ..\
26
+ REM Ensure the target exists
27
+ if NOT EXIST " %target% " (
28
+ echo Could not find %target% .
29
+ echo Please make sure to run this script from ProperTree's Scripts Folder.
30
+ echo .
31
+ echo Press [enter] to quit.
32
+ pause > nul
33
+ exit /b
34
+ )
26
35
set " path = %cd% "
27
36
set " regpath = %ComSpec:cmd.exe =% reg.exe"
28
37
popd
29
- echo Checking if ProperTree.bat exists in registry...
30
- " !regpath! " query " HKCR\Applications\ProperTree.bat " > nul 2 >& 1
38
+ echo Checking if %target% exists in registry...
39
+ " !regpath! " query " HKCR\Applications\%target% " > nul 2 >& 1
31
40
if " %errorlevel% " == " 0" (
32
41
echo - Already exists. Removing...
33
42
echo .
34
- " !regpath! " delete " HKCR\Applications\ProperTree.bat " /f 2 > nul
43
+ " !regpath! " delete " HKCR\Applications\%target% " /f 2 > nul
35
44
" !regpath! " delete " HKCR\.plist_auto_file" /f 2 > nul
36
45
" !regpath! " delete " HKCR\.plist" /f 2 > nul
37
- " !regpath! " delete " HKCU\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" /v " Applications\ProperTree.bat_ .plist" /f 2 > nul
46
+ " !regpath! " delete " HKCU\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" /v " Applications\%target% _ .plist" /f 2 > nul
38
47
)
39
- set arg = \" %path% \ProperTree.bat \" \" %% 1\"
48
+ set arg = \" %path% \%target% \" \" %% 1\"
40
49
echo .
41
50
echo Adding registry values...
42
51
echo .
43
- " !regpath! " add " HKCR\Applications\ProperTree.bat \shell\Open" /t REG_SZ /d " Open with ProperTree " /f
44
- " !regpath! " add " HKCR\Applications\ProperTree.bat \shell\Open\command" /t REG_SZ /d " %arg% " /f
52
+ " !regpath! " add " HKCR\Applications\%target% \shell\Open" /t REG_SZ /d " Open with %name% " /f
53
+ " !regpath! " add " HKCR\Applications\%target% \shell\Open\command" /t REG_SZ /d " %arg% " /f
45
54
" !regpath! " add " HKCR\.plist" /t REG_SZ /d " .plist_auto_file" /f
46
- " !regpath! " add " HKCR\.plist_auto_file\shell\Open" /t REG_SZ /d " Open with ProperTree " /f
55
+ " !regpath! " add " HKCR\.plist_auto_file\shell\Open" /t REG_SZ /d " Open with %name% " /f
47
56
" !regpath! " add " HKCR\.plist_auto_file\shell\Open\command" /t REG_SZ /d " %arg% " /f
48
- " !regpath! " add " HKCU\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" /v " Applications\ProperTree.bat_ .plist" /t REG_DWORD /d 0 /f
57
+ " !regpath! " add " HKCU\Software\Microsoft\Windows\CurrentVersion\ApplicationAssociationToasts" /v " Applications\%target% _ .plist" /t REG_DWORD /d 0 /f
49
58
echo .
50
59
echo Press [enter] to exit...
51
60
pause > nul
52
61
exit /b
62
+
63
+ ----- Begin wsf script --->
64
+
65
+ < package>
66
+ < job id=" ADMIN" >
67
+ < script language=" VBScript" >
68
+ dim self_path: self_path = WScript.ScriptFullName
69
+ If StrComp(Right(self_path,5)," ?.wsf" ,vbTextCompare)=0 Then: self_path = Left(self_path,Len(self_path)-5): End If
70
+ Set argument_list = CreateObject(" System.Collections.ArrayList" )
71
+ For Each argument_item in WScript.Arguments
72
+ If StrComp(argument_item," --self" ,vbTextCompare)=0 Then: argument_item = self_path: End If
73
+ Call argument_list.Add(argument_item)
74
+ Next
75
+ If argument_list.Count=0 Then: Call argument_list.Add(self_path): End If
76
+ dim target_exe: target_exe = " cmd.exe"
77
+ If StrComp(Right(argument_list(0),4)," .exe" ,vbTextCompare)=0 Then
78
+ target_exe = argument_list(0)
79
+ Call argument_list.RemoveAt(0)
80
+ ElseIf StrComp(Right(argument_list(0),4)," .bat" ,vbTextCompare)=0 or StrComp(Right(argument_list(0),4)," .cmd" ,vbTextCompare)=0 Then
81
+ Call argument_list.Insert(0," /c" )
82
+ End If
83
+ dim args: args = " "
84
+ For Each a in argument_list
85
+ if args<> " " Then: args = args & " " : End If
86
+ args = args & chr(34) & a & chr(34)
87
+ Next
88
+ CreateObject(" Shell.Application" ).ShellExecute target_exe, args, , " runas" , 5
89
+ < /script>
90
+ < /job>
91
+ < /package>
0 commit comments