Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


List add and remove not a part of this list.

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,53899
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
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!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 List add and remove not a part of this list. - 11/29/2007 4:04:43 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
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.


      

 
 
Post #: 1
 
 RE: List add and remove not a part of this list. - 11/30/2007 2:30:11 AM   
  dm_4ever


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.


      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to aburt)
 
 
Post #: 2
 
 RE: List add and remove not a part of this list. - 11/30/2007 3:36:25 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
Does anyone have any ideas on how to go about doing this

(in reply to aburt)
 
 
Post #: 3
 
 RE: List add and remove not a part of this list. - 11/30/2007 3:53:27 AM   
  mikeock


Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
the above psot tells you how.

_____________________________

My sig sucks!

(in reply to aburt)
 
 
Post #: 4
 
 RE: List add and remove not a part of this list. - 11/30/2007 5:19:11 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
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.

(in reply to mikeock)
 
 
Post #: 5
 
 RE: List add and remove not a part of this list. - 11/30/2007 6:47:39 AM   
  mikeock


Posts: 124
Score: 1
Joined: 6/8/2006
Status: offline
so create your dictionary like this:

      

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.

_____________________________

My sig sucks!

(in reply to aburt)
 
 
Post #: 6
 
 RE: List add and remove not a part of this list. - 12/1/2007 9:49:50 PM   
  Meg


Posts: 126
Score: 2
Joined: 7/13/2006
From: Australia
Status: offline
It just so happens that I wrote a script that does just this.
http://www.visualbasicscript.com/m_53955/mpage_1/key_/tm.htm#53955

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.

(in reply to aburt)
 
 
Post #: 7
 
 RE: List add and remove not a part of this list. - 12/2/2007 10:04:09 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
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. 

Can anyone give me support on this?



      

(in reply to aburt)
 
 
Post #: 8
 
 Check text file and dictionary entry - 12/4/2007 2:40:21 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
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.


      

(in reply to aburt)
 
 
Post #: 9
 
 RE: Check text file and dictionary entry - 12/4/2007 2:49:31 AM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi aburt,

this code shows how to use .Exists to check whether a dictionary
contains a specific key:


      

I hope this will get you started.

Good luck!

ehvbs

(in reply to aburt)
 
 
Post #: 10
 
 RE: Check text file and dictionary entry - 12/4/2007 4:30:58 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
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


      

(in reply to ehvbs)
 
 
Post #: 11
 
 RE: Check text file and dictionary entry - 12/4/2007 4:56:11 AM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi aburt,

if you want to use a dictionary, you'll have to search/test for keys. Why do you use those
useless letters "a", "b", .. for keys? Change

   Set e = CreateObject("Scripting.Dictionary")
   e.Add "a", "Athens" 'Add some keys and items
   e.Add "b", "Belgrade"
   e.Add "c", "Cairo"

to

   Set e = CreateObject("Scripting.Dictionary")
    e.Add "Athens", ""
    e.Add "Belgrade", ""
    e.Add "Cairo", ""

If you use this

  Do Until objFile.AtEndOfStream
       strNextLine = objFile.Readline
      If strNextLine <> "" Then
          objDictionary.Add i, strNextLine
      End If
      i = i + 1
  Loop

to initialize the dictionary, change it to something like:

  Do Until objFile.AtEndOfStream
       strNextLine = objFile.Readline
        If strNextLine <> "" Then
            objDictionary( strNextLine ), ""
        End If
  Loop

Good luck!

ehvbs

(in reply to aburt)
 
 
Post #: 12
 
 RE: Check text file and dictionary entry - 12/4/2007 5:31:43 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
hi ehvbs

when I do this I get this error

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

(in reply to ehvbs)
 
 
Post #: 13
 
 RE: Check text file and dictionary entry - 12/4/2007 5:40:29 AM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
[OldPedanticParanoiacEatsHisUntestedCode]

Shame on me:

  objDictionary(strNextLine), ""

should be

objDictionary(strNextLine) = ""

[/OldPedanticParanoiacEatsHisUntestedCode]

(in reply to aburt)
 
 
Post #: 14
 
 RE: List add and remove not a part of this list. - 12/4/2007 7:30:55 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
Hey

thanks for the clarification that worked.  but when I try to apply it to my finished script I am missing something can you take a look


      

(in reply to aburt)
 
 
Post #: 15
 
 RE: List add and remove not a part of this list. - 12/4/2007 9:03:38 AM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi aburt,

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:


      

Good luck!

ehvbs

(in reply to aburt)
 
 
Post #: 16
 
 RE: List add and remove not a part of this list. - 12/4/2007 11:51:54 AM   
  aburt

 

Posts: 104
Score: 0
Joined: 12/4/2006
Status: offline
Ehvbs

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.

(in reply to ehvbs)
 
 
Post #: 17
 
 RE: List add and remove not a part of this list. - 12/4/2007 8:37:08 PM   
  ehvbs

 

Posts: 2200
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi aburt,

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.

Good luck!

ehvbs

(in reply to aburt)
 
 
Post #: 18
 
 RE: List add and remove not a part of this list. - 12/5/2007 12:20:37 AM    <