click
here for more groovy stuff like this
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_keyendfunc
func GetConceptCommands(
$file_type)
$file_type =
"HKEY_CLASSES_ROOT\" &
$file_type &
"\Shell" $dirs =
"" $y = 1
while
$y $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)
$reg_test_array_k = ReturnAllSubkeys(
$key)
$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)
$keys =
"" $x = 1
while
$x $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)
$names =
"" $x = 1
while
$x $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
func ReturnAllPairs(
$key,
$skip_empties=false)
$x = 1
$y = 1
local
$pairs[1][2]
while
$x $var = RegEnumVal(
$key,
$x)
if @error <> 0 then exitloop
$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
$pairsendfunc
func SetExplorerContextMenu(
$ext,
$switch=4,
$default=false,
$menu_item=
"",
$fallback=
"my-unique-key",
$switches=
"")
if not
$ext then return false
local
$key =
$my_name if
$default then
$key =
"open" if not
$menu_item then
$menu_item =
$my_name local
$reg1,
$reg2,
$reg3 local
$file_type = RegRead(
"HKEY_CLASSES_ROOT\." &
$ext,
"")
if not
$file_type then
$file_type =
$fallback local
$shell =
"HKEY_CLASSES_ROOT\" &
$file_type &
"\shell" local
$shellkey =
$shell &
"\" &
$key local
$BAX_key =
"HKEY_CLASSES_ROOT\" &
$file_type &
"\" &
$my_name &
"_Backup\" &
$key if @compiled then
$me_app = @ScriptFullPath
else
$me_app =
".\" &
$my_name &
".exe" endif
if
$switch = 1 then
$regexist = RegRead(
$shellkey &
"\command",
"")
if StringInStr(
$regexist, RemoveExtension(BaseName(@ScriptName))) then return true
local
$bax1,
$bax2,
$bax3,
$old_val,
$old_key if
$default 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)
if not
$bax1 and
$bax2 and
$bax3 then return false
endif
$reg1 = RegWrite(
$shellkey,
"",
"REG_SZ",
$menu_item)
$reg2 = RegWrite(
$shellkey &
"\command",
"",
"REG_SZ", '
"' & $me_app & '" ' &
$switches & '
"%1"')
if
$default then RegWrite(
$shell,
"",
"REG_SZ",
"open")
if
$reg1 and
$reg2 then return true
else
$regexist = RegRead(
$shellkey &
"\command",
"")
if not StringInstr(
$regexist,
$me_app) then return true
local
$old_key1,
$old_key2,
$old_key3 if
$default then
$old_key1 = RegRead(
$BAX_key,
"")
$old_key2 = RegRead(
$BAX_key,
"menu")
$old_key3 = RegRead(
$BAX_key,
"cmd")
if
$old_key1 and
$old_key2 and
$old_key3 then
$reg1 = RegWrite(
$shell,
"",
"REG_SZ",
$old_key1)
$reg2 = RegWrite(
$shell &
"\" &
$old_key1,
"",
"REG_SZ",
$old_key2)
$reg3 = RegWrite(
$shell &
"\" &
$old_key1 &
"\command",
"",
"REG_SZ",
$old_key3)
if
$reg1 and
$reg2 and
$reg3 then
RegDelete(
$BAX_key)
if KeyIsEmpty(
"HKEY_CLASSES_ROOT\" &
$file_type &
"\" &
$my_name &
"_Backup") then
RegDelete(
"HKEY_CLASSES_ROOT\" &
$file_type &
"\" &
$my_name &
"_Backup")
endif
if
$old_key1 <>
"open" then RegDelete(
$shellkey)
return true
endif
endif
else
$restored = RegDelete(
$shellkey)
if
$restored then return true
endif
endif
return false
endfunc