corz.org uses cookies to remember that you've seen this notice explaining that corz.org uses cookies, okay!
Miscelleneous Registry Comands
@Extended values..
0 = directory (key)
1 = REG_SZ
2 = REG_EXPAND_SZ
3 = REG_BINARY
4 = REG_DWORD
7 = REG_MULTI_SZ
Function List..
MakeLongRegPaths()
GetContextCommands()
KeyIsEmpty()
ReturnAllSubkeys()
ReturnAllValueNames()
ReturnAllPairs()
SetExplorerContextMenu()
func MakeLongRegPaths($reg_key)
$reg_key = StringReplace($reg_key, "HKCR", "HKEY_CLASSES_ROOT")
$reg_key = StringReplace($reg_key, "HKCU", "HKEY_CURRENT_USER")
$reg_key = StringReplace($reg_key, "HKU", "HKEY_USERS")
$reg_key = StringReplace($reg_key, "HKLM", "HKEY_LOCAL_MACHINE")
$reg_key = StringReplace($reg_key, "HKCC", "HKEY_CURRENT_CONFIG")
return $reg_key
endfunc
func GetContextCommands($file_type)
$file_type = "HKEY_CLASSES_ROOT\" & $file_type & "\Shell"
local $dirs = ""
local $y = 1
while $y
local $var = RegEnumKey($file_type, $y)
if @error <> 0 then exitloop
if @extended = 0 then
$dirs &= $var & "|"
endif
$y += 1
wend
if $dirs <> "" then
$dirs = StringTrimRight($dirs, 1)
return StringSplit($dirs, "|")
endif
endfunc
func KeyIsEmpty($key)
local $reg_test_array_k = ReturnAllSubkeys($key)
local $reg_test_array_v = ReturnAllValueNames($key)
if $reg_test_array_k[1] = "" and $reg_test_array_v[1] = "" then
return 1
endif
endfunc
func ReturnAllSubkeys($key)
$key = MakeLongRegPaths($key)
local $keys = ""
local $x = 1
while $x
local $var = RegEnumKey($key, $x)
if @error <> 0 then exitloop
if $var <> "" then $keys &= $var & "|"
$x += 1
wend
$keys = StringTrimRight($keys, 1)
return StringSplit($keys, "|")
endfunc
func ReturnAllValueNames($key)
$key = MakeLongRegPaths($key)
local $names = ""
local $x = 1
while $x
local $var = RegEnumVal($key, $x)
if @error <> 0 then exitloop
if $var <> "" then $names &= $var & "|"
$x += 1
wend
$names = StringTrimRight($names, 1)
return StringSplit($names, "|")
endfunc
ReturnAllPairs example:
$str = ""
$foo = ReturnAllPairs("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
for $i = 1 to $foo[0][0]
$str &= "key: " & $foo[$i][0] & " value: " & $foo[$i][1] & " " & @LF
next
MsgBox (0, "These programs run at startup..", $str)
exit
dim $startup_places[4] = _
[ "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx" ]
for $place in $startup_places
$foo = ReturnAllPairs($place)
for $i = 1 to $foo[0][0]
$str &= $foo[$i][0] & " : " & $foo[$i][1] & " " & @LF
next
next
MsgBox (0, "These programs run at startup..", $str)
func ReturnAllPairs($key, $skip_empties=false)
local $x = 1
local $y = 1
local $pairs[1][2]
while $x
local $var = RegEnumVal($key, $x)
if @error <> 0 then exitloop
local $this_value = RegRead($key, $var)
if (not $skip_empties) or ($skip_empties and $this_value <> "") then
redim $pairs[$y+1][2]
$pairs[$y][0] = $var
$pairs[$y][1] = $this_value
$y += 1
endif
$x += 1
wend
$pairs[0][0] = $y - 1
return $pairs
endfunc
func SetExplorerContextMenu($ext, $switch=default, $default=default, $menu_item=default, _
$fallback=default, $switches=default, $app_override=default, $icon=default)
if $switch = default then $switch = $OFF
if $default = default then $default = $OFF
if $menu_item = default or $menu_item = "" then $menu_item = "Open with " & $my_name & "|" & $my_name
if $fallback = default then $fallback = "my-unique-key"
if $switches = default then $switches = ""
if $app_override = default then $app_override = ""
if $icon = default then $icon = ""
if not $ext then return SetError(1, 0, "no extension given")
local $key
if $default = $ON then
$key = "open"
else
local $menu_array = StringSplit($menu_item, "|")
debug_PrintArray($menu_array, "$menu_array:", @ScriptLineNumber, 0)
$menu_item = $menu_array[1]
$key = $menu_array[2]
endif
local $reg1, $reg2, $reg3, $reg4
local $filextkey = "HKEY_CLASSES_ROOT\." & $ext
local $file_type = RegRead($filextkey, "")
if not $file_type then $file_type = $fallback
local $regbase = "HKEY_CLASSES_ROOT\" & $file_type
local $shell = $regbase & "\shell"
local $shellkey = $shell & "\" & $key
local $BAX_key = $regbase & "\" & $my_name & "_Backup"
local $my_app
if $app_override then
$my_app = $app_override
else
if @compiled then
$my_app = @ScriptFullPath
else
$my_app = ".\" & $my_name & ".exe"
endif
endif
if $switch = $ON then
debug("Adding Context Menu (" & $menu_item & ") for.. =>" & $ext & "<=", @ScriptLineNumber)
local $extexist = RegRead($filextkey, "")
if not $extexist then
RegWrite($filextkey, "", "REG_SZ", $file_type)
endif
local $regexist = RegRead($shellkey & "\command", "")
if StringInStr($regexist, $my_app) then return SetError(2, 0, "still enabled!")
local $bax1, $bax2, $bax3, $bax4, $old_val, $old_key
if $default = $ON then
$old_key = RegRead($shell, "")
$bax1 = RegWrite($BAX_key, "", "REG_SZ", $old_key)
$old_val = RegRead($shell & "\" & $old_key, "")
$bax2 = RegWrite($BAX_key, "menu", "REG_SZ", $old_val)
$old_val = RegRead($shell & "\" & $old_key & "\command", "")
$bax3 = RegWrite($BAX_key, "cmd", "REG_SZ", $old_val)
$old_val = RegRead($regbase & "\defaulticon", "")
$bax4 = RegWrite($BAX_key, "icon", "REG_SZ", $old_val)
if not $old_key then RegWrite($BAX_key, "created", "REG_SZ", "yes")
if not $bax1 or not $bax2 or not $bax3 or not $bax4 then return SetError(3, 0, "no backup")
endif
$reg1 = RegWrite($shellkey, "", "REG_SZ", $menu_item)
$reg2 = RegWrite($shellkey & "\command", "", "REG_SZ", '"' & $my_app & '" ' & $switches & ' "%1"')
if $default = $ON then RegWrite($shell, "", "REG_SZ", "open")
if $icon then RegWrite($regbase & "\defaulticon", "", "REG_SZ", $icon)
if $reg1 and $reg2 then return SetError(0, 0, "Written OK!")
else
debug("Removing Context Menu for.. =>" & $ext & "<=", @ScriptLineNumber)
$regexist = RegRead($shellkey & "\command", "")
if not StringInstr($regexist, $my_app) then return SetError(4, 0, "already off!")
local $old_key1, $old_key2, $old_key3, $old_key4, $old_key5
if $default = $ON then
$old_key1 = RegRead($BAX_key, "")
$old_key2 = RegRead($BAX_key, "menu")
$old_key3 = RegRead($BAX_key, "cmd")
$old_key4 = RegRead($BAX_key, "icon")
$old_key5 = RegRead($BAX_key, "created")
if ($old_key1 and ($old_key2 or $old_key3 or $old_key4)) or $old_key5 then
if $old_key5 <> "yes" then
if $old_key1 then
$reg1 = RegWrite($shell, "", "REG_SZ", $old_key1)
if $old_key2 then $reg2 = RegWrite($shell & "\" & $old_key1, "", "REG_SZ", $old_key2)
if $old_key3 then $reg3 = RegWrite($shell & "\" & $old_key1 & "\command", "", "REG_SZ", $old_key3)
if $old_key4 then $reg4 = RegWrite("HKEY_CLASSES_ROOT\" & $old_key1 & "\defaulticon", "", "REG_SZ", $old_key4)
endif
endif
if $reg1 and $reg2 and $reg3 and $reg4 then RegDelete($BAX_key)
if $old_key5 = "yes" then
RegDelete($regbase)
RegDelete($filextkey)
endif
return SetError(0, 0, "SUCCESS!")
endif
else
local $restored = RegDelete($shellkey)
if $restored then return SetError(0, 0, "Deleted!")
endif
endif
return SetError(-1, 0, "nothing happened!")
endfunc
Changes:
0.2
Added..
SetExplorerContextMenu()
which I cooked up for LoopDropZ & MangleeZee. All yours!
0.1
A small selection of useful registry functions..
MakeLongRegPaths()
GetContextCommands()
KeyIsEmpty()
ReturnAllSubkeys()
ReturnAllValueNames()
ReturnAllPairs()