All Forums >> [Scripting] >> WSH & Client Side VBScript >> List add and remove not a part of this list. Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Hello everyone, my office is in the middle of a migration, I am trying build a vbsript to list everything in add remove programs that is not a part of our standard Image. I can list the add remove no problem but I need some help with excluding the programs that are part of our standard image. I have run this script on one our image to get the base applications.
My goal is to get a list off applications the client has that is not part of the standard image. Any help would be appreciated.
Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I would use a dictionary. Add the authorized application names to the dictionary and then loop through the software on the other machines and user the Exists method to see if it is in your dictionary...if not then you write it somewhere or output it however you want. i.e.
I see that I not clear how I would tie that in with what I already have. In others words if the data in the dictionary is my base image applications how can I tell the script to print my base image application. How do I ask the script to write the other applications to my text file.
Now where you are looping through the registry entries, i assume this is the for loop in GetAddRemove, you would add this in:
I cannot tell for sure what that function is doing, but when you are getting the names, you need to check against the dictionary to see if they need to be included or not.
I uses a database instead of a dictionary though. I will have to read up on dictionaries.
Hope this is of some use to you and you can give me some feedback to improve it. Have not tested it at work yet but it works bug free on my little xp network at home.
Meg thanks for your post. I took a look at your script it does work but for my particular use. I also want to initiate my script remotely. Thank you for your response.
I have added the dictionary but I am having a hard time understanding how to use the registry collection to search against the dictionary. In other I have the script searching the computer for installed applications and I also have the dictionary pulling the data from a text file. But I am not clear on how to request the script to print out all installed apps not listed in the dictionary.
Since I can't get a response for help with my script. Maybe I can get some guidance on how to fix it myself. My problem is how do check each item in a for each loop to check against a dictionary object items. In other words, if the software in add removes does not exist in the dictionary print it out.
ehvbs thanks for responding I have tried what you suggested It seems that if I do what you suggest the output is not found. I think this is because object.exist is looking at the key. What I need to base my match on is the item or value of the dictionary key. Is it possible to do that.
Dim addremove : addremove = Array("Athens","Belgrade","Cairo","DenMark","Egypt") Dim e 'Create a variable Set e = CreateObject("Scripting.Dictionary") e.Add "a", "Athens" 'Add some keys and items e.Add "b", "Belgrade" e.Add "c", "Cairo" b = e.items 'Get the keys For i = 0 To e.Count -1 'Iterate the array 'wscript.echo b(i) 'Print key Next
For Each software In addremove If e.Exists("a") Then WScript.Echo "found", software,"in on local machine" Else WScript.Echo "not", software, "in Base Image" End If Next
Microsoft VBScript runtime error: Object doesn't support this property or method: 'objDictionary'
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objDictionary = CreateObject("Scripting.Dictionary") Const ForReading = 1 Set objFile = objFSO.OpenTextFile ("G:\add Remove script\image.txt", ForReading) i = 0
Do Until objFile.AtEndOfStream strNextLine = objFile.Readline If strNextLine <> "" Then objDictionary(strNextLine), "" WScript.Echo "this dictionary item Is " & strItem End If Loop
you concatenate all names of the installed programs into sTmp:
sTmp = sTmp & sValue & VbCrLf
Then you lookup this monster string in objDictionary:
If objDictionary.Exists( sTmp ) Then
No wonder you won't find it. If you'd thought about what your script should do and what your code makes it really do and if you'd invested a little bit of diligence in the indentation, you'd have seen that
sTmp = sTmp & sValue & VbCrLf ... sTmp = BubbleSort(sTmp) 'puts output in alphabetical order Next ...
If objDictionary.Exists( sTmp ) Then
can't be right. Just as it's to late to check for the existence of a name (or the concatenation of all names) in the dictionary after the Next=loop, it's too early/useless to bubbleort the content of sTmp each time you add another name to it.
There a many line in your code that aren't used. This makes it difficult to spot problems. So start simple:
I appreciate your words of wisdom and guidance. sorry about the indentation (guilty as charged) I have been trying to work this non stop for the past two days and Im frustrated that its whipping my butt.
I took a look at last bit off code taking your advice and trying to start off small. I thought my biggest problem was trying to get the add remove applications to compare to the dictionary of base applications. Looks like your code does that but it does not pull out any applications. Your code list all applications on the machine the script is run on regardless of whether it exist in the dictionary or not. And Im not clear why.
I changed my script slightly to make testing/demonstrating a bit easier (command line args) and to tackle the problem of trailing whitespace (my editor deletes such junk):
Now doing
cscript aburt01.vbs /all /trim
will give me a long list of software installed on my computer. I send this list to aburt.txt
cscript aburt01.vbs /all /trim >aburt.txt
and look for the missing items:
cscript aburt01.vbs /miss /trim Forté Agent is missing in the dictionary InstallShield für Microsoft Visual C++ 6 is missing in the dictionary ...
Obviously there is an encoding problem (funny letter é,ü, ä). After editing those lines in aburt.txt, I get no output from
cscript aburt01.vbs /miss /trim
and a long list from
cscript aburt01.vbs /std /trim
All DisplayNames of the software installed on my computer are listed in aburt.txt. After deleting some lines from aburt.txt (you'd choose the non standard software)
cscript aburt01.vbs /miss /trim
lists all those items deleted from the file.
So make sure, your input file contains the standard software's DisplayNames and use the Else branch of
If objDictionary.Exists( sValue ) Then If bStd Then WScript.Echo sValue, "exist in the dictionary" Else If bMiss Then WScript.Echo sValue, "is missing in the dictionary" End If
to code what you want to do if non standard software is found on a computer.