What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Parse Registry SubKeys in JScript?

Parse Registry SubKeys in JScript?
Author: Message:
Shondoit
Full Member
***

Avatar
Hmm, Just Me...

Posts: 227
Reputation: 15
36 / Male / Flag
Joined: Jul 2006
RE: Parse Registry SubKeys in JScript?
No need for a DLL, it can be done without it

I have the code, but I'll have to look for it though
post them asap

-edit1- I found the code, but it is script specific, I will make it variable now
-edit2- Changed the code, gonna test it now...

-edit3- Here is the final code. The first function enumerates all available subkey names, the second function enumerates all key value names, could be used to look wich programs run on windows startup ("HKLM\Software\Microsoft\Windows\CurrentVersion\Run", if you'd want to know, user specific startup is located in HKCU instead of HKLM)

code:
function EnumSubKeys (RegKey) {
  var RootKey = new Object()
  RootKey["HKCR"] = RootKey["HKEY_CLASSES_ROOT"]   = 0x80000000;
  RootKey["HKCU"] = RootKey["HKEY_CURRENT_USER"]   = 0x80000001;
  RootKey["HKLM"] = RootKey["HKEY_LOCAL_MACHINE"]  = 0x80000002;
  RootKey["HKUS"] = RootKey["HKEY_USERS"]          = 0x80000003;
  RootKey["HKCC"] = RootKey["HKEY_CURRENT_CONFIG"] = 0x80000005;
  var RootVal = RootKey[RegKey.substr(0, RegKey.indexOf("\\"))]
  if (RootVal != undefined) {
    Locator = new ActiveXObject("WbemScripting.SWbemLocator");
    ServerConn = Locator.ConnectServer(null, "root\\default");
    Registry = ServerConn.Get("StdRegProv");
    Method = Registry.Methods_.Item("EnumKey");
    p_In = Method.InParameters.SpawnInstance_();
    p_In.hDefKey = RootVal;
    p_In.sSubKeyName = RegKey.substr(RegKey.indexOf("\\") + 1)
    p_Out = Registry.ExecMethod_(Method.Name, p_In);
    return p_Out.sNames.toArray();
  }
}

function EnumValues (RegKey) {
  var RootKey = new Object()
  RootKey["HKCR"] = RootKey["HKEY_CLASSES_ROOT"]   = 0x80000000;
  RootKey["HKCU"] = RootKey["HKEY_CURRENT_USER"]   = 0x80000001;
  RootKey["HKLM"] = RootKey["HKEY_LOCAL_MACHINE"]  = 0x80000002;
  RootKey["HKUS"] = RootKey["HKEY_USERS"]          = 0x80000003;
  RootKey["HKCC"] = RootKey["HKEY_CURRENT_CONFIG"] = 0x80000005;
  var RootVal = RootKey[RegKey.substr(0, RegKey.indexOf("\\"))]
  if (RootVal != undefined) {
    Locator = new ActiveXObject("WbemScripting.SWbemLocator");
    ServerConn = Locator.ConnectServer(null, "root\\default");
    Registry = ServerConn.Get("StdRegProv");
    Method = Registry.Methods_.Item("EnumValues");
    p_In = Method.InParameters.SpawnInstance_();
    p_In.hDefKey = RootVal;
    p_In.sSubKeyName = RegKey.substr(RegKey.indexOf("\\") + 1)
    p_Out = Registry.ExecMethod_(Method.Name, p_In);
    return p_Out.sNames.toArray();
  }
}

Then you can use it like this...
code:
var SubKeyArray = EnumSubKeys("HKEY_CURRENT_USER\\Software\\Item1\\Item2");
for (Index in SubKeyArray) {
   Debug.Trace(SubKeyArray[Index])
}

Or enumerate all programs running on startup...
code:
var Shell = new ActiveXObject("WScript.Shell")
var Key = "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
var ValuesArray = EnumValues(Key);
Debug.Trace("=== Global startup ===")
for (Index in ValuesArray) {
   var ValueName = ValuesArray[Index]
   ValueValue = Shell.RegRead(Key + "\\" + ValueName)
   Debug.Trace(ValueName + " = " + ValueValue)
}
var Key = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
var ValuesArray = EnumValues(Key);
Debug.Trace("=== User startup ===")
for (Index in ValuesArray) {
   var ValueName = ValuesArray[Index]
   ValueValue = Shell.RegRead(Key + "\\" + ValueName)
   Debug.Trace(ValueName + " = " + ValueValue)
}


This post was edited on 08-24-2006 at 11:43 PM by Shondoit.
My scripts:                            [Image: shondoit.gif]
+ Timezone
+ Camelo
+ Multisearch
08-24-2006 10:54 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Parse Registry SubKeys in JScript? - by Jedimark on 08-24-2006 at 05:23 PM
RE: Parse Registry SubKeys in JScript? - by J-Thread on 08-24-2006 at 07:52 PM
RE: Parse Registry SubKeys in JScript? - by Ezra on 08-24-2006 at 10:35 PM
RE: Parse Registry SubKeys in JScript? - by Shondoit on 08-24-2006 at 10:54 PM
RE: Parse Registry SubKeys in JScript? - by CookieRevised on 08-25-2006 at 12:00 AM
RE: Parse Registry SubKeys in JScript? - by Shondoit on 08-25-2006 at 12:09 AM
RE: RE: Parse Registry SubKeys in JScript? - by CookieRevised on 08-25-2006 at 12:14 AM
RE: Parse Registry SubKeys in JScript? - by Shondoit on 08-25-2006 at 12:17 AM
RE: Parse Registry SubKeys in JScript? - by matty on 08-25-2006 at 01:52 AM
RE: Parse Registry SubKeys in JScript? - by -dt- on 08-25-2006 at 04:15 AM
RE: Parse Registry SubKeys in JScript? - by CookieRevised on 08-25-2006 at 03:26 PM
RE: Parse Registry SubKeys in JScript? - by Jedimark on 08-26-2006 at 12:48 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On