Next, add a new file type (see Chapter 3) for .vbsa files
and associate its Open action with the wscript_admin.exe file. Thereafter, just
rename the filename extension of any .vbs file to .vbsa to run the script as an
administrator.
Object References | 525
Scripting and
Automation
Sub RegistryWrite(KeyName, ValueName, ValueData, ValueType)
ValueType = UCase(ValueType)
If ValueType <> "REG_DWORD" and ValueType <> "REG_BINARY" Then _
ValueType = "REG_SZ"
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite KeyName & "\" & ValueName, ValueData, ValueType
End Sub
Function RegistryRead(KeyName, ValueName)
Set WshShell = WScript.CreateObject("WScript.Shell")
RegistryRead = WSHShell.RegRead(KeyName & "\" & ValueName)
End Function
Sub RegistryDelete(KeyName, ValueName)
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite KeyName & "\" & ValueName, ""
WshShell.RegDelete KeyName & "\" & ValueName
End Sub
Using these three routines, you can accomplish nearly all Registry tasks. To
create a Registry key, type this (note that all HKEY... roots must appear in
uppercase):
Call RegistryWrite("HKEY_LOCAL_MACHINE\Software\My Key", "", "", "")
To assign data to a Registry value:
Call RegistryWrite("HKEY_LOCAL_MACHINE\Software\My Key", "My Value", _
"Some Data", "")
Leave "My Value" blank to set the (Default) value. To read the data stored in
a given value:
Variable = RegistryRead("HKEY_LOCAL_MACHINE\Software\My Key", "My Value")
Leave "My Value" blank to read the (Default) value.
Pages:
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731