| 
| 
| 
| #203754 - 2011-11-16 06:39 PM  Microsoft Update Session on remote system |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
Good Afternoon,
 I'm working on a script to check the installed patches on a remote system.  I'm trying to create an object of "Microsoft.Update.Session" which points to the remote system.  Doing:
 
 
 works fine for creating the object on the local system.  However if I try to add:$objSession = CreateObject("Microsoft.Update.Session")
 I get back:$strWks="remotesys"
$objSession = CreateObject("Microsoft.Update.Session", $strWks)ERROR : invalid method/function call: too many parameters!
 Anyone have an idea what I am doing wrong?  An example is given in:
 Scripting Guy Determine Patch Applied
 
 Regards,
 
 Brad
 |  
| Top |  |  |  |  
| 
| 
| #203755 - 2011-11-16 06:55 PM  Re: Microsoft Update Session on remote system
[Re:  BradV] |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
I believe this is happening because createobject in kixtart does not support a second parameter.  You should be able to pull this off by using the scriptcontrol object.
 Something like...
 
 (untested)
 
 
$sc = CreateObject("ScriptControl")
$sc.language = "VBScript"
$sc.addcode('Session=CreateObject("Microsoft.Update.Session","' + $strWks + '"')
$sc.run
$ObjSession=$sc.codeobject.session
 |  
| Top |  |  |  |  
| 
| 
| #203776 - 2011-11-17 11:48 AM  Re: Microsoft Update Session on remote system
[Re:  Allen] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
Thanks, I'll give that a try.    |  
| Top |  |  |  |  
| 
| 
| #203778 - 2011-11-17 06:57 PM  Re: Microsoft Update Session on remote system
[Re:  BradV] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
OK, tried it, but it gives an error when trying to execute the $sc.addcode line.  "support for this property or method: 'Session' doesn't" and the rest falls of the window.   
 I guess I'll have to distribute the script to each server and then run it remotely there.
 
 Regards,
 
 Brad
 |  
| Top |  |  |  |  
| 
| 
| #203788 - 2011-11-18 02:09 PM  Re: Microsoft Update Session on remote system
[Re:  Allen] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
 
 I have 29 Windows 2008 servers that I am responsible to administer, but the patches are applied at the domain level.  I don't have access to that.  I have to report when a critical vulnerability has been discovered (CVE) whether the systems have been patched.  So, I was trying to find a method to search for the applied patches.  I'll have to take a look at the registry locations.  In the meantime, this is what I was working on so far:
 
 
 ;NAME  check_win_patch.kix
;
;DESCRIPTION  This is a script to check for patches on systems.
;
Break On
Dim $SO
;
$SO = SetOpt('Explicit',          'On')
$SO = SetOpt('NoMacrosInStrings', 'On')
;
Dim $strWks, $strComps, $colComps, $objComp
;
$strComps = "u:\Desktop\computers.ini"
;
$colComps = Split(ReadProfileString($strComps,"computers",""),chr(10))
;
For Each $objComp in $colComps
   If $objComp <> ""
      $strWks - ReadProfileString($strComps,"computers",$objComp)
   EndIf
   GetAllPatches($strWks)
   ; more stuff to do here
Next
;
Function GetAllPatches($strWks)
   Dim $objSession, $objSC, $objSearcher, $colUpdates, $intI, $intHistoryCount, $objIdentity, $objUpdate, $objIdentity
   ;
   $objSC = CreateObject("ScriptControl")
   If @ERROR
      ? "There was an error creating the scriptcontrol object " + @SERROR
   EndIf
   $objSC.language = "VBScript"
   $objSC.addcode('Session=CreateObject("Microsoft.Update.Session","' + $strWks + '")')
   If @ERROR
      "There was an error creating the Update Session object"
      ? @SERROR
   EndIf
   $objSC.run
   If @ERROR
      ? "There was an error running the Update Session object " + @SERROR
   EndIf
   $objSession = $objSC.codeobject.session
   If @ERROR
      ? "There was an error creating the Session Object after running the Update Session " @SERROR
   EndIf
   $objSearcher = $objSession.CreateUpdateSearcher
   If @ERROR
      ? " There was an error creating the Update Searcher object " + @SERROR
   EndIf
   $intHistoryCount = $objSearcher.GetTotalHistoryCount
   If @ERROR
      ? "There was an error getting the Update Searcher History count " + @SERROR
   EndIf
   $colUpdates = $objSearcher.QueryHistory(0, $intHistoryCount)
   If @ERROR
      ? "There was an error getting the update collection " + @SERROR
   EndIf
   ;
   ; I haven't really decided what to do with them yet.
   ; So, just printing out the data
   ;
   For Each $objUpdate in $colUpdates
      ? "Title:                   " + $objUpdate.Title
      ? "Description:             " + $objUpdate.Description
      ? "Update application date: " + $objUpdate.Date
      $intI = $objUpdate.Operation
      Select
         Case $intI = 1
            ? "Operation type:         Installation"
         Case $intI = 2
            ? "Operation type:         Uninstallation"
         Case 1
            ? "Operation type:         could not be determined"
      EndSelect
      $intI = $objUpdate.ResultCode
      Select
         Case $intI = 0
            ? "Operation result:       The operation has not started."
         Case $intI = 1
            ? "Operation result:       The operation is in progress."
         Case $intI = 2
            ? "Operation result:       The operation completed successfully."
         Case $intI = 3
            ? "Operation result:       The operation complted, but one or more errors occurred"
            ? "                        during the operation and the results are potentially incomplete."
         Case $intI = 4
            ? "Operation result:       The operation failed to complete."
         Case $intI = 5
            ? "Operation result:       The operation was aborted."
         Case 1
            ? "Operation result:       Could not be determined."
      EndSelect
      $objIdentity = $objUpdate.UpdateIdentity
      ? "Update ID:              " + $objIdentity.UpdateID
      ? "------------------------------------------------------------?
   Next
EndFunction
 If there are any typos, I apologize.  I have to re-type it all.
 
 Regards,
 
 Brad
 |  
| Top |  |  |  |  
| 
| 
| #203793 - 2011-11-18 04:03 PM  Re: Microsoft Update Session on remote system
[Re:  BradV] |  
| Allen   KiX Supporter
 
       
 Registered:  2003-04-19
 Posts: 4562
 Loc:  USA
 | 
I had two bugs in the addcode line... here is the corrected one.
 
 
$objsc.addcode('Set Session=CreateObject("Microsoft.Update.Session","' + $strWks + '")')
 |  
| Top |  |  |  |  
| 
| 
| #203794 - 2011-11-18 04:15 PM  Re: Microsoft Update Session on remote system
[Re:  Allen] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
Hi Allen,
 I caught the missing end parenthisis, but missed the "Set " command.  I just added that and I'm getting "Invalid number of parameters."  Looking further.
   |  
| Top |  |  |  |  
| 
| 
| #203798 - 2011-11-18 04:27 PM  Re: Microsoft Update Session on remote system
[Re:  Allen] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
Sure.  I have:
 
 [computers]
comp1=netbios-name1
comp2=netbios-name2
comp3=netbios-name3
 etc.  It's pulling the correct computer name.  On the first loop, $strWks is set to "netbios-name1"
 
 Regards,
 
 Brad
 |  
| Top |  |  |  |  
| 
| 
| #203801 - 2011-11-18 04:56 PM  Re: Microsoft Update Session on remote system
[Re:  BradV] |  
| Les   KiX Master
 
       
 Registered:  2001-06-11
 Posts: 12734
 Loc:  fortfrances.on.ca
 | 
Ummm... shouldn't you have quotes around the strings?  Kix will try to do math on the - operator.Sure.  I have: [computers]
comp1=netbios-name1
comp2=netbios-name2
comp3=netbios-name3etc.  It's pulling the correct computer name.  On the first loop, $strWks is set to "netbios-name1" Regards, Brad [edit]NM... just realized this is an INI file.
 
 Edited by Les (2011-11-18 04:58 PM)
 Edit Reason: DOH
 
_________________________Give a man a fish and he will be back for more.  Slap him with a fish and he will go away forever.
 |  
| Top |  |  |  |  
| 
| 
| #203804 - 2011-11-18 06:03 PM  Re: Microsoft Update Session on remote system
[Re:  BradV] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
OK, I added:
 
 Dim $strCommand
$strCommand = 'Set Session = CreateObject("Microsoft.Update.Session","' + $strWks + '")'
? "The update session command is:"
? $strCommand
$objSC.AddCode($strCommand)
 It gets past the AddCode method now and is failing on the run with invalid number of parameters.  I think I need to give the code a name and specify that in the run command.  Still looking.
   |  
| Top |  |  |  |  
| 
| 
| #203805 - 2011-11-18 06:26 PM  Re: Microsoft Update Session on remote system
[Re:  BradV] |  
| BradV   Seasoned Scripter
 
      
 Registered:  2006-08-16
 Posts: 687
 Loc:  Maryland, USA
 | 
OK, slowly making progress.  I changed the AddCode section to create a function and then called that function by name in the Run section as follows:
 
 $strCommand = 'Function CO
Set Session = CreateObject("Microsoft.Update.Session","' + $strWks + '")
End Function'
$objSC.AddCode($strCommand)
$objSC.Run("CO")
 That all passes without any errors.  I'm now getting an error on the
 $objSession = $objSC.CodeObject.Session
 I'll have to check that syntax.
 
 
   
 Edited by BradV (2011-11-21 02:10 PM)
 Edit Reason: Corrected typo
 |  
| Top |  |  |  |  
 Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
 
 | 
| 
 
| 0 registered
and 793 anonymous users online. 
 | 
 |  |