Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Registry scripting

Reply
 
Old 04-01-2009   #1 (permalink)
Cary Shultz


 
 

Registry scripting

Good evening!

Okay, here is what I am trying to do (er, think that this is the best
method):

1) Connect to the local machine and enumerate the
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" key
(read: looking for all of the subkeys).
2) Take what ever is returned (probably different on each machine) and look
for one of 15 specific subkeys ( "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}"
would be one of the entries for which I would be searching)
3) Specify each of the 15 subkeys for which to search
4) Specify if each of the 15 exists or not (possible....very very possible)
5) Write that results to a file

Here is what I am trying to do: I want to look on each computer in the
domain and determine which - if any - Anti Virus software is installed. The
GUID that I mentioned above is specifically for Trend Micro Worry Free.
There will be some 14 others (and this number may grow).

Currently I can do two things (neither of which results in me being happy!):

Look for the existence of ONE of the specified subkeys as per the below
script....

+++++++++++++++++++++++++++++++++++++

Const HKLM = &H80000002
Set objReg =GetObject("Winmgmts:root\default:StdRegProv")

strKeyPath =
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}"

If RegKeyExists(strKeyPath) Then
WScript.Echo "Key exists"
Else
WScript.Echo "Key does not exist"
End If

Function RegKeyExists(strRegKey)
strRegKey = Trim(strRegKey)
If objReg.EnumValues(HKLM, strKeyPath1, aValueNames, aValueTypes) = 0 Then
RegKeyExists = True
Else
RegKeyExists = False
End If
End Function

+++++++++++++++++++++++++++++++++++++

That is fine and dandy, but I would really like to be able to put in all 15
GUIDs at once....and see which one exists. Also, the possibility that none
of them exists needs to be taken into consideration.


I can also enumerate all of the subkeys as per the below script....

*****************************************
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
Wscript.Echo subkey
Next

*****************************************
That enumerates all of the subkeys of the uninstall key. However, I do not
know how to cycle through the results and look for any of the 15 GUIDs
(again, that number will grow). So, I need to be able to specify those 15
GUIDs and then look through the results of that enumeration and "find" one
of the 15 statically entered GUIDs (or, possibly none at all).

I am fairly proficient with a select few concepts of VBScript/WMI/ADSI. It
appears to me that that what I am trying to do is 'a bit' beyond my
abilities.

If someone could push me in the right direction I would really appreciate
it.

For the record - both scripts listed above I found on the Internet. The
second one I could have probably written myself...the first one - most
assuredly NOT!


What we will then do is to look at the results file on each machine and
parse it, looking to see where "EXISTS" is....that way we know which AV is
installed and can remove it accordingly (my boss has the uninstall script
most most AV apps....) We just need to know which uninstall script to
use....thus, this exercise!

Thanks all!

Cary


My System SpecsSystem Spec
Old 04-01-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Registry scripting

Cary Shultz wrote:
Quote:

>
> Okay, here is what I am trying to do (er, think that this is the best
> method):
>
> 1) Connect to the local machine and enumerate the
> "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
> key (read: looking for all of the subkeys).
> 2) Take what ever is returned (probably different on each machine) and
> look for one of 15 specific subkeys (
> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}" would be one of the entries for
> which I would be searching)
> 3) Specify each of the 15 subkeys for which to search
> 4) Specify if each of the 15 exists or not (possible....very very
> possible)
> 5) Write that results to a file
>
> Here is what I am trying to do: I want to look on each computer in the
> domain and determine which - if any - Anti Virus software is installed.
> The GUID that I mentioned above is specifically for Trend Micro Worry
> Free. There will be some 14 others (and this number may grow).
>
> Currently I can do two things (neither of which results in me being
> happy!):
>
> Look for the existence of ONE of the specified subkeys as per the below
> script....
>
> +++++++++++++++++++++++++++++++++++++
>
> Const HKLM = &H80000002
> Set objReg =GetObject("Winmgmts:root\default:StdRegProv")
>
> strKeyPath =
> "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}"
>
> If RegKeyExists(strKeyPath) Then
> WScript.Echo "Key exists"
> Else
> WScript.Echo "Key does not exist"
> End If
>
> Function RegKeyExists(strRegKey)
> strRegKey = Trim(strRegKey)
> If objReg.EnumValues(HKLM, strKeyPath1, aValueNames, aValueTypes) = 0
> Then
> RegKeyExists = True
> Else
> RegKeyExists = False
> End If
> End Function
>
> +++++++++++++++++++++++++++++++++++++
>
> That is fine and dandy, but I would really like to be able to put in all
> 15 GUIDs at once....and see which one exists. Also, the possibility that
> none of them exists needs to be taken into consideration.
>
>
> I can also enumerate all of the subkeys as per the below script....
>
> *****************************************
> Const HKEY_LOCAL_MACHINE = &H80000002
>
> strComputer = "."
>
> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
> strComputer & "\root\default:StdRegProv")
>
> strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>
> For Each subkey In arrSubKeys
> Wscript.Echo subkey
> Next
>
> *****************************************
> That enumerates all of the subkeys of the uninstall key. However, I do
> not know how to cycle through the results and look for any of the 15 GUIDs
> (again, that number will grow). So, I need to be able to specify those 15
> GUIDs and then look through the results of that enumeration and "find" one
> of the 15 statically entered GUIDs (or, possibly none at all).
>
> I am fairly proficient with a select few concepts of VBScript/WMI/ADSI.
> It appears to me that that what I am trying to do is 'a bit' beyond my
> abilities.
>
> If someone could push me in the right direction I would really appreciate
> it.
>
> For the record - both scripts listed above I found on the Internet. The
> second one I could have probably written myself...the first one - most
> assuredly NOT!
>
>
> What we will then do is to look at the results file on each machine and
> parse it, looking to see where "EXISTS" is....that way we know which AV is
> installed and can remove it accordingly (my boss has the uninstall script
> most most AV apps....) We just need to know which uninstall script to
> use....thus, this exercise!
>
> Thanks all!
>
> Cary
>
You can use the EnumKey method of the objReg object to enumerate subkeys. I
would use a dictionary object to keep track of the GUID's. It has an Exists
method that makes it easy to find matches. For example:
==========
Option Explicit

Dim objReg, strComputer, objNetwork
Dim strKeyPath, arrSubKeys, strSubKey
Dim arrGuids, objList, strGuid

Const HKEY_LOCAL_MACHINE = &H80000002

' Array of subkey values to look for. I include just two here.
arrGuids = Array("{23959E96-A80F-4172-A655-210E9BB7BFBE}", _
"{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}")

' Create dictionary object to keep track of subkey values.
Set objList = CreateObject("Scripting.Dictionary")
' Make comparisons case insensitive.
objList.CompareMode = vbTextCompare

' Populate dictioanry object with the subkey values.
For Each strGuid In arrGuids
objList.Add strGuid, True
Next

' Find local computer NetBIOS name.
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

' Connect to WMI namespace.
Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strComputer & "\root\default:StdRegProv")

' Specify registry key to enumerate.
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

' Enumerate subkeys and look for matches in dictionary object.
For Each strSubKey In arrSubKeys
If (objList.Exists(strSubKey) = True) Then
' Subkey found, echo results.
Wscript.Echo "Found: " & strSubKey
End If
Next
===========
You can run this at a command prompt with the cscript host and redirect the
output to a text file. Or you can use the FileSystemObject to write to a
text file. For example (in part):
===========
Dim strLogFile, objFSO, objFile

Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True

' Specify log file.
strLogFile = "c:\Scripts\RegistryKeys.log"

' Open the file for write access.
Set objFile = objFSO.OpenTextFile(strLogFile, _
ForWriting, CreateIfNotExist, OpenAsASCII)

objFile.WriteLine "Computer: " & strComputer

' Enumerate subkeys and look for matches in dictionary object.
For Each strSubKey In arrSubKeys
If (objList.Exists(strSubKey) = True) Then
' Subkey found, write to log file.
objFile.WriteLine "Found: " & strSubKey
End If
Next

' Clean up.
objFile.Close
=========
You can incorporate this code in a script that enumerates all computers in
the domain. As written, the code above can be run remotely. You can use ADO
to enumerate all computers in the domain. For information on using ADO see
this link:

http://www.rlmueller.net/ADOSearchTips.htm

For an example program that inventories all computers in the domain and
writes results to a spreadsheet, see this link:

http://www.rlmueller.net/Inventory.htm

With these examples, you can code an script to search for the subkeys on all
computers in your domain.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 04-01-2009   #3 (permalink)
Cary Shultz


 
 

Re: Registry scripting

Richard,

I was hoping that you would see my plea for help and respond.

I really need to get a better grasp on this stuff. Have a nice evening!
Thank you very much. I will let you know how this works out (but I suspect
that you already know!).

Cary


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:%230BHu7ysJHA.240@xxxxxx
Quote:

> Cary Shultz wrote:
>
Quote:

>>
>> Okay, here is what I am trying to do (er, think that this is the best
>> method):
>>
>> 1) Connect to the local machine and enumerate the
>> "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
>> key (read: looking for all of the subkeys).
>> 2) Take what ever is returned (probably different on each machine) and
>> look for one of 15 specific subkeys (
>> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}" would be one of the entries for
>> which I would be searching)
>> 3) Specify each of the 15 subkeys for which to search
>> 4) Specify if each of the 15 exists or not (possible....very very
>> possible)
>> 5) Write that results to a file
>>
>> Here is what I am trying to do: I want to look on each computer in the
>> domain and determine which - if any - Anti Virus software is installed.
>> The GUID that I mentioned above is specifically for Trend Micro Worry
>> Free. There will be some 14 others (and this number may grow).
>>
>> Currently I can do two things (neither of which results in me being
>> happy!):
>>
>> Look for the existence of ONE of the specified subkeys as per the below
>> script....
>>
>> +++++++++++++++++++++++++++++++++++++
>>
>> Const HKLM = &H80000002
>> Set objReg =GetObject("Winmgmts:root\default:StdRegProv")
>>
>> strKeyPath =
>> "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}"
>>
>> If RegKeyExists(strKeyPath) Then
>> WScript.Echo "Key exists"
>> Else
>> WScript.Echo "Key does not exist"
>> End If
>>
>> Function RegKeyExists(strRegKey)
>> strRegKey = Trim(strRegKey)
>> If objReg.EnumValues(HKLM, strKeyPath1, aValueNames, aValueTypes) = 0
>> Then
>> RegKeyExists = True
>> Else
>> RegKeyExists = False
>> End If
>> End Function
>>
>> +++++++++++++++++++++++++++++++++++++
>>
>> That is fine and dandy, but I would really like to be able to put in all
>> 15 GUIDs at once....and see which one exists. Also, the possibility that
>> none of them exists needs to be taken into consideration.
>>
>>
>> I can also enumerate all of the subkeys as per the below script....
>>
>> *****************************************
>> Const HKEY_LOCAL_MACHINE = &H80000002
>>
>> strComputer = "."
>>
>> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
>> strComputer & "\root\default:StdRegProv")
>>
>> strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
>> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>>
>> For Each subkey In arrSubKeys
>> Wscript.Echo subkey
>> Next
>>
>> *****************************************
>> That enumerates all of the subkeys of the uninstall key. However, I do
>> not know how to cycle through the results and look for any of the 15
>> GUIDs (again, that number will grow). So, I need to be able to specify
>> those 15 GUIDs and then look through the results of that enumeration and
>> "find" one of the 15 statically entered GUIDs (or, possibly none at all).
>>
>> I am fairly proficient with a select few concepts of VBScript/WMI/ADSI.
>> It appears to me that that what I am trying to do is 'a bit' beyond my
>> abilities.
>>
>> If someone could push me in the right direction I would really appreciate
>> it.
>>
>> For the record - both scripts listed above I found on the Internet. The
>> second one I could have probably written myself...the first one - most
>> assuredly NOT!
>>
>>
>> What we will then do is to look at the results file on each machine and
>> parse it, looking to see where "EXISTS" is....that way we know which AV
>> is installed and can remove it accordingly (my boss has the uninstall
>> script most most AV apps....) We just need to know which uninstall
>> script to use....thus, this exercise!
>>
>> Thanks all!
>>
>> Cary
>>
>
> You can use the EnumKey method of the objReg object to enumerate subkeys.
> I would use a dictionary object to keep track of the GUID's. It has an
> Exists method that makes it easy to find matches. For example:
> ==========
> Option Explicit
>
> Dim objReg, strComputer, objNetwork
> Dim strKeyPath, arrSubKeys, strSubKey
> Dim arrGuids, objList, strGuid
>
> Const HKEY_LOCAL_MACHINE = &H80000002
>
> ' Array of subkey values to look for. I include just two here.
> arrGuids = Array("{23959E96-A80F-4172-A655-210E9BB7BFBE}", _
> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}")
>
> ' Create dictionary object to keep track of subkey values.
> Set objList = CreateObject("Scripting.Dictionary")
> ' Make comparisons case insensitive.
> objList.CompareMode = vbTextCompare
>
> ' Populate dictioanry object with the subkey values.
> For Each strGuid In arrGuids
> objList.Add strGuid, True
> Next
>
> ' Find local computer NetBIOS name.
> Set objNetwork = CreateObject("Wscript.Network")
> strComputer = objNetwork.ComputerName
>
> ' Connect to WMI namespace.
> Set objReg = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
> & strComputer & "\root\default:StdRegProv")
>
> ' Specify registry key to enumerate.
> strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
> objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>
> ' Enumerate subkeys and look for matches in dictionary object.
> For Each strSubKey In arrSubKeys
> If (objList.Exists(strSubKey) = True) Then
> ' Subkey found, echo results.
> Wscript.Echo "Found: " & strSubKey
> End If
> Next
> ===========
> You can run this at a command prompt with the cscript host and redirect
> the output to a text file. Or you can use the FileSystemObject to write to
> a text file. For example (in part):
> ===========
> Dim strLogFile, objFSO, objFile
>
> Const ForWriting = 2
> Const OpenAsASCII = 0
> Const CreateIfNotExist = True
>
> ' Specify log file.
> strLogFile = "c:\Scripts\RegistryKeys.log"
>
> ' Open the file for write access.
> Set objFile = objFSO.OpenTextFile(strLogFile, _
> ForWriting, CreateIfNotExist, OpenAsASCII)
>
> objFile.WriteLine "Computer: " & strComputer
>
> ' Enumerate subkeys and look for matches in dictionary object.
> For Each strSubKey In arrSubKeys
> If (objList.Exists(strSubKey) = True) Then
> ' Subkey found, write to log file.
> objFile.WriteLine "Found: " & strSubKey
> End If
> Next
>
> ' Clean up.
> objFile.Close
> =========
> You can incorporate this code in a script that enumerates all computers in
> the domain. As written, the code above can be run remotely. You can use
> ADO to enumerate all computers in the domain. For information on using ADO
> see this link:
>
> http://www.rlmueller.net/ADOSearchTips.htm
>
> For an example program that inventories all computers in the domain and
> writes results to a spreadsheet, see this link:
>
> http://www.rlmueller.net/Inventory.htm
>
> With these examples, you can code an script to search for the subkeys on
> all computers in your domain.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
My System SpecsSystem Spec
Old 04-02-2009   #4 (permalink)
Joe Fawcett


 
 

Re: Registry scripting

There's also a script here, http://www.billsway.com/vbspage/, that lists
installed programs. I'm sure it could be tailored to do what you need.

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
"Cary Shultz" <cshultz@xxxxxx> wrote in message
news:O0co4azsJHA.5912@xxxxxx
Quote:

> Richard,
>
> I was hoping that you would see my plea for help and respond.
>
> I really need to get a better grasp on this stuff. Have a nice evening!
> Thank you very much. I will let you know how this works out (but I
> suspect that you already know!).
>
> Cary
>
>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:%230BHu7ysJHA.240@xxxxxx
Quote:

>> Cary Shultz wrote:
>>
Quote:

>>>
>>> Okay, here is what I am trying to do (er, think that this is the best
>>> method):
>>>
>>> 1) Connect to the local machine and enumerate the
>>> "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
>>> key (read: looking for all of the subkeys).
>>> 2) Take what ever is returned (probably different on each machine) and
>>> look for one of 15 specific subkeys (
>>> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}" would be one of the entries for
>>> which I would be searching)
>>> 3) Specify each of the 15 subkeys for which to search
>>> 4) Specify if each of the 15 exists or not (possible....very very
>>> possible)
>>> 5) Write that results to a file
>>>
>>> Here is what I am trying to do: I want to look on each computer in the
>>> domain and determine which - if any - Anti Virus software is installed.
>>> The GUID that I mentioned above is specifically for Trend Micro Worry
>>> Free. There will be some 14 others (and this number may grow).
>>>
>>> Currently I can do two things (neither of which results in me being
>>> happy!):
>>>
>>> Look for the existence of ONE of the specified subkeys as per the below
>>> script....
>>>
>>> +++++++++++++++++++++++++++++++++++++
>>>
>>> Const HKLM = &H80000002
>>> Set objReg =GetObject("Winmgmts:root\default:StdRegProv")
>>>
>>> strKeyPath =
>>> "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}"
>>>
>>> If RegKeyExists(strKeyPath) Then
>>> WScript.Echo "Key exists"
>>> Else
>>> WScript.Echo "Key does not exist"
>>> End If
>>>
>>> Function RegKeyExists(strRegKey)
>>> strRegKey = Trim(strRegKey)
>>> If objReg.EnumValues(HKLM, strKeyPath1, aValueNames, aValueTypes) = 0
>>> Then
>>> RegKeyExists = True
>>> Else
>>> RegKeyExists = False
>>> End If
>>> End Function
>>>
>>> +++++++++++++++++++++++++++++++++++++
>>>
>>> That is fine and dandy, but I would really like to be able to put in all
>>> 15 GUIDs at once....and see which one exists. Also, the possibility
>>> that none of them exists needs to be taken into consideration.
>>>
>>>
>>> I can also enumerate all of the subkeys as per the below script....
>>>
>>> *****************************************
>>> Const HKEY_LOCAL_MACHINE = &H80000002
>>>
>>> strComputer = "."
>>>
>>> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
>>> strComputer & "\root\default:StdRegProv")
>>>
>>> strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
>>> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>>>
>>> For Each subkey In arrSubKeys
>>> Wscript.Echo subkey
>>> Next
>>>
>>> *****************************************
>>> That enumerates all of the subkeys of the uninstall key. However, I do
>>> not know how to cycle through the results and look for any of the 15
>>> GUIDs (again, that number will grow). So, I need to be able to specify
>>> those 15 GUIDs and then look through the results of that enumeration and
>>> "find" one of the 15 statically entered GUIDs (or, possibly none at
>>> all).
>>>
>>> I am fairly proficient with a select few concepts of VBScript/WMI/ADSI.
>>> It appears to me that that what I am trying to do is 'a bit' beyond my
>>> abilities.
>>>
>>> If someone could push me in the right direction I would really
>>> appreciate it.
>>>
>>> For the record - both scripts listed above I found on the Internet. The
>>> second one I could have probably written myself...the first one - most
>>> assuredly NOT!
>>>
>>>
>>> What we will then do is to look at the results file on each machine and
>>> parse it, looking to see where "EXISTS" is....that way we know which AV
>>> is installed and can remove it accordingly (my boss has the uninstall
>>> script most most AV apps....) We just need to know which uninstall
>>> script to use....thus, this exercise!
>>>
>>> Thanks all!
>>>
>>> Cary
>>>
>>
>> You can use the EnumKey method of the objReg object to enumerate subkeys.
>> I would use a dictionary object to keep track of the GUID's. It has an
>> Exists method that makes it easy to find matches. For example:
>> ==========
>> Option Explicit
>>
>> Dim objReg, strComputer, objNetwork
>> Dim strKeyPath, arrSubKeys, strSubKey
>> Dim arrGuids, objList, strGuid
>>
>> Const HKEY_LOCAL_MACHINE = &H80000002
>>
>> ' Array of subkey values to look for. I include just two here.
>> arrGuids = Array("{23959E96-A80F-4172-A655-210E9BB7BFBE}", _
>> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}")
>>
>> ' Create dictionary object to keep track of subkey values.
>> Set objList = CreateObject("Scripting.Dictionary")
>> ' Make comparisons case insensitive.
>> objList.CompareMode = vbTextCompare
>>
>> ' Populate dictioanry object with the subkey values.
>> For Each strGuid In arrGuids
>> objList.Add strGuid, True
>> Next
>>
>> ' Find local computer NetBIOS name.
>> Set objNetwork = CreateObject("Wscript.Network")
>> strComputer = objNetwork.ComputerName
>>
>> ' Connect to WMI namespace.
>> Set objReg = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
>> & strComputer & "\root\default:StdRegProv")
>>
>> ' Specify registry key to enumerate.
>> strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
>> objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>>
>> ' Enumerate subkeys and look for matches in dictionary object.
>> For Each strSubKey In arrSubKeys
>> If (objList.Exists(strSubKey) = True) Then
>> ' Subkey found, echo results.
>> Wscript.Echo "Found: " & strSubKey
>> End If
>> Next
>> ===========
>> You can run this at a command prompt with the cscript host and redirect
>> the output to a text file. Or you can use the FileSystemObject to write
>> to a text file. For example (in part):
>> ===========
>> Dim strLogFile, objFSO, objFile
>>
>> Const ForWriting = 2
>> Const OpenAsASCII = 0
>> Const CreateIfNotExist = True
>>
>> ' Specify log file.
>> strLogFile = "c:\Scripts\RegistryKeys.log"
>>
>> ' Open the file for write access.
>> Set objFile = objFSO.OpenTextFile(strLogFile, _
>> ForWriting, CreateIfNotExist, OpenAsASCII)
>>
>> objFile.WriteLine "Computer: " & strComputer
>>
>> ' Enumerate subkeys and look for matches in dictionary object.
>> For Each strSubKey In arrSubKeys
>> If (objList.Exists(strSubKey) = True) Then
>> ' Subkey found, write to log file.
>> objFile.WriteLine "Found: " & strSubKey
>> End If
>> Next
>>
>> ' Clean up.
>> objFile.Close
>> =========
>> You can incorporate this code in a script that enumerates all computers
>> in the domain. As written, the code above can be run remotely. You can
>> use ADO to enumerate all computers in the domain. For information on
>> using ADO see this link:
>>
>> http://www.rlmueller.net/ADOSearchTips.htm
>>
>> For an example program that inventories all computers in the domain and
>> writes results to a spreadsheet, see this link:
>>
>> http://www.rlmueller.net/Inventory.htm
>>
>> With these examples, you can code an script to search for the subkeys on
>> all computers in your domain.
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>


My System SpecsSystem Spec
Old 04-03-2009   #5 (permalink)
Cary Shultz


 
 

Re: Registry scripting

Richard,

I just got off the phone with my 'boss man' and I have two questions for
you:

1) what if running the script detects multiple GUIDs? I know what will
happen - all of the GUIDs will be written to that file. Not a problem.
However, what if I want only the last GUID detected to be included in that
result file?

2) Next logical question: what happens if it finds no GUIDs? Well, I know
that answer to that question as wellll.....nothing is written to the file
(we will have the file - it will just be empty - we removed the computer
name because it turns out that we do not need it....I did not know that when
I set out on this journey!). However, what if I want - assuming that no
GUIDs are found - the following text to be written to the .txt file? "No AV
Software detected"!!!!!!!

Okay - I do not want you to write the entire script for me. You have
already done a ton (and it is - as always - greatly appreciated). I would
like to try to figure this out.

To be honest - the first one is completely over my head. I will research
this. For the second one I have some ideas but am going to have to do a
little research. I know that "if you find a guid, write it to this file but
if you don't find a guid then write that" is pretty simple in concept but in
implementing it....well, ain't never dun that before!

Thanks,

Cary



"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:%230BHu7ysJHA.240@xxxxxx
Quote:

> Cary Shultz wrote:
>
Quote:

>>
>> Okay, here is what I am trying to do (er, think that this is the best
>> method):
>>
>> 1) Connect to the local machine and enumerate the
>> "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
>> key (read: looking for all of the subkeys).
>> 2) Take what ever is returned (probably different on each machine) and
>> look for one of 15 specific subkeys (
>> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}" would be one of the entries for
>> which I would be searching)
>> 3) Specify each of the 15 subkeys for which to search
>> 4) Specify if each of the 15 exists or not (possible....very very
>> possible)
>> 5) Write that results to a file
>>
>> Here is what I am trying to do: I want to look on each computer in the
>> domain and determine which - if any - Anti Virus software is installed.
>> The GUID that I mentioned above is specifically for Trend Micro Worry
>> Free. There will be some 14 others (and this number may grow).
>>
>> Currently I can do two things (neither of which results in me being
>> happy!):
>>
>> Look for the existence of ONE of the specified subkeys as per the below
>> script....
>>
>> +++++++++++++++++++++++++++++++++++++
>>
>> Const HKLM = &H80000002
>> Set objReg =GetObject("Winmgmts:root\default:StdRegProv")
>>
>> strKeyPath =
>> "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}"
>>
>> If RegKeyExists(strKeyPath) Then
>> WScript.Echo "Key exists"
>> Else
>> WScript.Echo "Key does not exist"
>> End If
>>
>> Function RegKeyExists(strRegKey)
>> strRegKey = Trim(strRegKey)
>> If objReg.EnumValues(HKLM, strKeyPath1, aValueNames, aValueTypes) = 0
>> Then
>> RegKeyExists = True
>> Else
>> RegKeyExists = False
>> End If
>> End Function
>>
>> +++++++++++++++++++++++++++++++++++++
>>
>> That is fine and dandy, but I would really like to be able to put in all
>> 15 GUIDs at once....and see which one exists. Also, the possibility that
>> none of them exists needs to be taken into consideration.
>>
>>
>> I can also enumerate all of the subkeys as per the below script....
>>
>> *****************************************
>> Const HKEY_LOCAL_MACHINE = &H80000002
>>
>> strComputer = "."
>>
>> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
>> strComputer & "\root\default:StdRegProv")
>>
>> strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
>> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>>
>> For Each subkey In arrSubKeys
>> Wscript.Echo subkey
>> Next
>>
>> *****************************************
>> That enumerates all of the subkeys of the uninstall key. However, I do
>> not know how to cycle through the results and look for any of the 15
>> GUIDs (again, that number will grow). So, I need to be able to specify
>> those 15 GUIDs and then look through the results of that enumeration and
>> "find" one of the 15 statically entered GUIDs (or, possibly none at all).
>>
>> I am fairly proficient with a select few concepts of VBScript/WMI/ADSI.
>> It appears to me that that what I am trying to do is 'a bit' beyond my
>> abilities.
>>
>> If someone could push me in the right direction I would really appreciate
>> it.
>>
>> For the record - both scripts listed above I found on the Internet. The
>> second one I could have probably written myself...the first one - most
>> assuredly NOT!
>>
>>
>> What we will then do is to look at the results file on each machine and
>> parse it, looking to see where "EXISTS" is....that way we know which AV
>> is installed and can remove it accordingly (my boss has the uninstall
>> script most most AV apps....) We just need to know which uninstall
>> script to use....thus, this exercise!
>>
>> Thanks all!
>>
>> Cary
>>
>
> You can use the EnumKey method of the objReg object to enumerate subkeys.
> I would use a dictionary object to keep track of the GUID's. It has an
> Exists method that makes it easy to find matches. For example:
> ==========
> Option Explicit
>
> Dim objReg, strComputer, objNetwork
> Dim strKeyPath, arrSubKeys, strSubKey
> Dim arrGuids, objList, strGuid
>
> Const HKEY_LOCAL_MACHINE = &H80000002
>
> ' Array of subkey values to look for. I include just two here.
> arrGuids = Array("{23959E96-A80F-4172-A655-210E9BB7BFBE}", _
> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}")
>
> ' Create dictionary object to keep track of subkey values.
> Set objList = CreateObject("Scripting.Dictionary")
> ' Make comparisons case insensitive.
> objList.CompareMode = vbTextCompare
>
> ' Populate dictioanry object with the subkey values.
> For Each strGuid In arrGuids
> objList.Add strGuid, True
> Next
>
> ' Find local computer NetBIOS name.
> Set objNetwork = CreateObject("Wscript.Network")
> strComputer = objNetwork.ComputerName
>
> ' Connect to WMI namespace.
> Set objReg = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
> & strComputer & "\root\default:StdRegProv")
>
> ' Specify registry key to enumerate.
> strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
> objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>
> ' Enumerate subkeys and look for matches in dictionary object.
> For Each strSubKey In arrSubKeys
> If (objList.Exists(strSubKey) = True) Then
> ' Subkey found, echo results.
> Wscript.Echo "Found: " & strSubKey
> End If
> Next
> ===========
> You can run this at a command prompt with the cscript host and redirect
> the output to a text file. Or you can use the FileSystemObject to write to
> a text file. For example (in part):
> ===========
> Dim strLogFile, objFSO, objFile
>
> Const ForWriting = 2
> Const OpenAsASCII = 0
> Const CreateIfNotExist = True
>
> ' Specify log file.
> strLogFile = "c:\Scripts\RegistryKeys.log"
>
> ' Open the file for write access.
> Set objFile = objFSO.OpenTextFile(strLogFile, _
> ForWriting, CreateIfNotExist, OpenAsASCII)
>
> objFile.WriteLine "Computer: " & strComputer
>
> ' Enumerate subkeys and look for matches in dictionary object.
> For Each strSubKey In arrSubKeys
> If (objList.Exists(strSubKey) = True) Then
> ' Subkey found, write to log file.
> objFile.WriteLine "Found: " & strSubKey
> End If
> Next
>
> ' Clean up.
> objFile.Close
> =========
> You can incorporate this code in a script that enumerates all computers in
> the domain. As written, the code above can be run remotely. You can use
> ADO to enumerate all computers in the domain. For information on using ADO
> see this link:
>
> http://www.rlmueller.net/ADOSearchTips.htm
>
> For an example program that inventories all computers in the domain and
> writes results to a spreadsheet, see this link:
>
> http://www.rlmueller.net/Inventory.htm
>
> With these examples, you can code an script to search for the subkeys on
> all computers in your domain.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
My System SpecsSystem Spec
Old 04-03-2009   #6 (permalink)
Richard Mueller [MVP]


 
 

Re: Registry scripting

I guess I would suggest the following:
========
Dim strLast

' Enumerate subkeys and look for matches in dictionary object.
strLast = "No AV Software detected"
For Each strSubKey In arrSubKeys
If (objList.Exists(strSubKey) = True) Then
' Subkey found. Retain last value.
strLast = strSubKey
End If
Next
' Write last value to log file.
objFile.WriteLine strLast

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
"Cary Shultz" <cshultz@xxxxxx> wrote in message
news:u7LhL0ItJHA.1236@xxxxxx
Quote:

> Richard,
>
> I just got off the phone with my 'boss man' and I have two questions for
> you:
>
> 1) what if running the script detects multiple GUIDs? I know what will
> happen - all of the GUIDs will be written to that file. Not a problem.
> However, what if I want only the last GUID detected to be included in that
> result file?
>
> 2) Next logical question: what happens if it finds no GUIDs? Well, I
> know that answer to that question as wellll.....nothing is written to the
> file (we will have the file - it will just be empty - we removed the
> computer name because it turns out that we do not need it....I did not
> know that when I set out on this journey!). However, what if I want -
> assuming that no GUIDs are found - the following text to be written to the
> .txt file? "No AV Software detected"!!!!!!!
>
> Okay - I do not want you to write the entire script for me. You have
> already done a ton (and it is - as always - greatly appreciated). I would
> like to try to figure this out.
>
> To be honest - the first one is completely over my head. I will research
> this. For the second one I have some ideas but am going to have to do a
> little research. I know that "if you find a guid, write it to this file
> but if you don't find a guid then write that" is pretty simple in concept
> but in implementing it....well, ain't never dun that before!
>
> Thanks,
>
> Cary
>
>
>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:%230BHu7ysJHA.240@xxxxxx
Quote:

>> Cary Shultz wrote:
>>
Quote:

>>>
>>> Okay, here is what I am trying to do (er, think that this is the best
>>> method):
>>>
>>> 1) Connect to the local machine and enumerate the
>>> "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
>>> key (read: looking for all of the subkeys).
>>> 2) Take what ever is returned (probably different on each machine) and
>>> look for one of 15 specific subkeys (
>>> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}" would be one of the entries for
>>> which I would be searching)
>>> 3) Specify each of the 15 subkeys for which to search
>>> 4) Specify if each of the 15 exists or not (possible....very very
>>> possible)
>>> 5) Write that results to a file
>>>
>>> Here is what I am trying to do: I want to look on each computer in the
>>> domain and determine which - if any - Anti Virus software is installed.
>>> The GUID that I mentioned above is specifically for Trend Micro Worry
>>> Free. There will be some 14 others (and this number may grow).
>>>
>>> Currently I can do two things (neither of which results in me being
>>> happy!):
>>>
>>> Look for the existence of ONE of the specified subkeys as per the below
>>> script....
>>>
>>> +++++++++++++++++++++++++++++++++++++
>>>
>>> Const HKLM = &H80000002
>>> Set objReg =GetObject("Winmgmts:root\default:StdRegProv")
>>>
>>> strKeyPath =
>>> "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}"
>>>
>>> If RegKeyExists(strKeyPath) Then
>>> WScript.Echo "Key exists"
>>> Else
>>> WScript.Echo "Key does not exist"
>>> End If
>>>
>>> Function RegKeyExists(strRegKey)
>>> strRegKey = Trim(strRegKey)
>>> If objReg.EnumValues(HKLM, strKeyPath1, aValueNames, aValueTypes) = 0
>>> Then
>>> RegKeyExists = True
>>> Else
>>> RegKeyExists = False
>>> End If
>>> End Function
>>>
>>> +++++++++++++++++++++++++++++++++++++
>>>
>>> That is fine and dandy, but I would really like to be able to put in all
>>> 15 GUIDs at once....and see which one exists. Also, the possibility
>>> that none of them exists needs to be taken into consideration.
>>>
>>>
>>> I can also enumerate all of the subkeys as per the below script....
>>>
>>> *****************************************
>>> Const HKEY_LOCAL_MACHINE = &H80000002
>>>
>>> strComputer = "."
>>>
>>> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
>>> strComputer & "\root\default:StdRegProv")
>>>
>>> strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
>>> oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>>>
>>> For Each subkey In arrSubKeys
>>> Wscript.Echo subkey
>>> Next
>>>
>>> *****************************************
>>> That enumerates all of the subkeys of the uninstall key. However, I do
>>> not know how to cycle through the results and look for any of the 15
>>> GUIDs (again, that number will grow). So, I need to be able to specify
>>> those 15 GUIDs and then look through the results of that enumeration and
>>> "find" one of the 15 statically entered GUIDs (or, possibly none at
>>> all).
>>>
>>> I am fairly proficient with a select few concepts of VBScript/WMI/ADSI.
>>> It appears to me that that what I am trying to do is 'a bit' beyond my
>>> abilities.
>>>
>>> If someone could push me in the right direction I would really
>>> appreciate it.
>>>
>>> For the record - both scripts listed above I found on the Internet. The
>>> second one I could have probably written myself...the first one - most
>>> assuredly NOT!
>>>
>>>
>>> What we will then do is to look at the results file on each machine and
>>> parse it, looking to see where "EXISTS" is....that way we know which AV
>>> is installed and can remove it accordingly (my boss has the uninstall
>>> script most most AV apps....) We just need to know which uninstall
>>> script to use....thus, this exercise!
>>>
>>> Thanks all!
>>>
>>> Cary
>>>
>>
>> You can use the EnumKey method of the objReg object to enumerate subkeys.
>> I would use a dictionary object to keep track of the GUID's. It has an
>> Exists method that makes it easy to find matches. For example:
>> ==========
>> Option Explicit
>>
>> Dim objReg, strComputer, objNetwork
>> Dim strKeyPath, arrSubKeys, strSubKey
>> Dim arrGuids, objList, strGuid
>>
>> Const HKEY_LOCAL_MACHINE = &H80000002
>>
>> ' Array of subkey values to look for. I include just two here.
>> arrGuids = Array("{23959E96-A80F-4172-A655-210E9BB7BFBE}", _
>> "{5DB0ECA1-4C56-488B-9BF1-FB300D9E1F54}")
>>
>> ' Create dictionary object to keep track of subkey values.
>> Set objList = CreateObject("Scripting.Dictionary")
>> ' Make comparisons case insensitive.
>> objList.CompareMode = vbTextCompare
>>
>> ' Populate dictioanry object with the subkey values.
>> For Each strGuid In arrGuids
>> objList.Add strGuid, True
>> Next
>>
>> ' Find local computer NetBIOS name.
>> Set objNetwork = CreateObject("Wscript.Network")
>> strComputer = objNetwork.ComputerName
>>
>> ' Connect to WMI namespace.
>> Set objReg = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
>> & strComputer & "\root\default:StdRegProv")
>>
>> ' Specify registry key to enumerate.
>> strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
>> objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
>>
>> ' Enumerate subkeys and look for matches in dictionary object.
>> For Each strSubKey In arrSubKeys
>> If (objList.Exists(strSubKey) = True) Then
>> ' Subkey found, echo results.
>> Wscript.Echo "Found: " & strSubKey
>> End If
>> Next
>> ===========
>> You can run this at a command prompt with the cscript host and redirect
>> the output to a text file. Or you can use the FileSystemObject to write
>> to a text file. For example (in part):
>> ===========
>> Dim strLogFile, objFSO, objFile
>>
>> Const ForWriting = 2
>> Const OpenAsASCII = 0
>> Const CreateIfNotExist = True
>>
>> ' Specify log file.
>> strLogFile = "c:\Scripts\RegistryKeys.log"
>>
>> ' Open the file for write access.
>> Set objFile = objFSO.OpenTextFile(strLogFile, _
>> ForWriting, CreateIfNotExist, OpenAsASCII)
>>
>> objFile.WriteLine "Computer: " & strComputer
>>
>> ' Enumerate subkeys and look for matches in dictionary object.
>> For Each strSubKey In arrSubKeys
>> If (objList.Exists(strSubKey) = True) Then
>> ' Subkey found, write to log file.
>> objFile.WriteLine "Found: " & strSubKey
>> End If
>> Next
>>
>> ' Clean up.
>> objFile.Close
>> =========
>> You can incorporate this code in a script that enumerates all computers
>> in the domain. As written, the code above can be run remotely. You can
>> use ADO to enumerate all computers in the domain. For information on
>> using ADO see this link:
>>
>> http://www.rlmueller.net/ADOSearchTips.htm
>>
>> For an example program that inventories all computers in the domain and
>> writes results to a spreadsheet, see this link:
>>
>> http://www.rlmueller.net/Inventory.htm
>>
>> With these examples, you can code an script to search for the subkeys on
>> all computers in your domain.
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Registry Search Tool... Cleaning Up Vista Registry... Vista General
Wise Registry Cleaner vs AusLogics Registry Defrag vs CCLeaner? Vista performance & maintenance
Registry Export Not Inserting Into Registry Vista General
VB scripting help VB Script
Registry Semi-Disaster: I am an idiot - used 2 registry 'cleaners' Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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