/
regat.bat
94 lines (74 loc) · 2.01 KB
/
regat.bat
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
@echo off
setlocal enableDelayedExpansion
rem
rem By default, we want a new regedit to be opened
rem
set opt_m=/m
@if [%1] == [-m] (
rem
rem However, if -m is specified, the default of opening a new regedit window
rem is overwritten
rem
set opt_m=
shift
)
if [%1] == [] (
echo Provide a registry key or env
exit /b
)
@if [%1] == [env] (
set RegistryKey=HKCU\Environment
goto goOn
)
@if [%1] == [globenv] (
set RegistryKey=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
goto goOn
)
@if [%1] == [clsid] (
if [%2] == [] (
echo expected: GUID for clsid
exit /b
)
set RegistryKey=HKCR\CLSID\%2
goto goOn
)
@if [%1] equ [svc] (
set RegistryKey=HKLM\SYSTEM\CurrentControlSet\Services
goto goOn
)
:buildRegistryKey
rem
rem Entering a loop to build the registry key
rem from the command line arguments. This loop
rem is necessary because regat.bat might be called
rem with a registry key that contains spaces, such as
rem regat HKCU\Control Panel\Mouse
rem In such a case, we cannot just assign %1 to !RegistryKey!
rem but must rather iterate over the indivdual
rem arguments and assemble the final registry key.
rem
if not [%1] == [] (
if not [!RegistryKey!] == [] (
set RegistryKey=!RegistryKey! %1
) else (
set RegistryKey=%1
)
shift
goto buildRegistryKey
)
:goOn
rem
rem Replace HKCU with HKEY_CURRENT_USER etc:
rem
set RegistryKey=!RegistryKey:HKCU=HKEY_CURRENT_USER!
set RegistryKey=!RegistryKey:HKLM=HKEY_LOCAL_MACHINE!
set RegistryKey=!RegistryKey:HKCR=HKEY_CLASSES_ROOT!
if [opt_m] neq [/m] (
rem Kill regedit.exe process if already running.
rem If it's not running, it would write an error message. Redirect
rem the message to nul
taskkill /f /im regedit.exe 1> nul 2> nul
)
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit /v LastKey /t REG_SZ /d "!RegistryKey!" /f > nul
start regedit %opt_m%
endlocal