Page 1 of 2 12>
Topic Options
#203754 - 2011-11-16 06:39 PM Microsoft Update Session on remote system
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
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:

 Code:
$objSession = CreateObject("Microsoft.Update.Session")
works fine for creating the object on the local system. However if I try to add:
 Code:
$strWks="remotesys"
$objSession = CreateObject("Microsoft.Update.Session", $strWks)
I get back:
 Code:
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 Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
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)
 Code:
$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 Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
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 Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
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
#203779 - 2011-11-17 07:03 PM Re: Microsoft Update Session on remote system [Re: BradV]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, if you just wanna know if the patches are installed, there are other ways to do it.
one is to enumerate the registry uninstall-key.

other one would be to shell out to systeminfo.
bet there is something similar in wmi as well, but these come to head right out of the bat.
_________________________
!

download KiXnet

Top
#203780 - 2011-11-17 07:23 PM Re: Microsoft Update Session on remote system [Re: BradV]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Let's see your code.
Top
#203781 - 2011-11-17 07:42 PM Re: Microsoft Update Session on remote system [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
who's code your talking about?
_________________________
!

download KiXnet

Top
#203782 - 2011-11-17 08:08 PM Re: Microsoft Update Session on remote system [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I couldn't search far enough in to the past to find the complete packages for these scripts but here is a starting point for a code that works without no com-object

 Code:
function GetInstalledsoftware(optional $machine)
	Dim $root, $softwarekey, $index
	dim $temparray[10]

	if not $machine
		$root = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
	else
		$root = "\\" + $machine + "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
	endif

	$SoftwareKey = enumkey($root,$Index)

	while not @error
		$DisplayName = readvalue($root + $SoftwareKey, "displayname")
		$DisplayVersion = readvalue($root + $SoftwareKey, "DisplayVersion")
		if $DisplayName
			if $count >  ubound($temparray)
				redim preserve $temparray[ubound($temparray)+10]
			endif
			$temparray[$count] = $DisplayName +"  "+ $DisplayVersion
			$count = $count + 1
		endif
		$Index = $Index + 1
		$SoftwareKey = enumkey($root, $Index)
	loop
	if $count > 0
		redim preserve $temparray[$count-1]
	else
		$temparray = ""
	endif
	$getinstalledsoftware = $temparray
endfunction
_________________________
!

download KiXnet

Top
#203787 - 2011-11-18 06:32 AM Re: Microsoft Update Session on remote system [Re: Lonkero]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
I meant Brad.
Top
#203788 - 2011-11-18 02:09 PM Re: Microsoft Update Session on remote system [Re: Allen]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
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:

 Code:
;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 Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
I had two bugs in the addcode line... here is the corrected one.

 Code:
$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 Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
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
#203796 - 2011-11-18 04:20 PM Re: Microsoft Update Session on remote system [Re: BradV]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
I got results... but I might have changed something else.... hmmm.
Top
#203797 - 2011-11-18 04:23 PM Re: Microsoft Update Session on remote system [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Can I see a snipet of your computers.ini
Top
#203798 - 2011-11-18 04:27 PM Re: Microsoft Update Session on remote system [Re: Allen]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
Sure. I have:

 Code:
[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
#203800 - 2011-11-18 04:50 PM Re: Microsoft Update Session on remote system [Re: BradV]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
 Quote:

COM exception error "addcode" (Microsoft VBScript runtime error - The remote server machine does not exist or is unavailable: 'CreateObject') [-2147352567/80020009]
Invalid number of parameters.


I don't have a remote machine to test on at the moment. So I just typed in a random computer name and got the error above. So, I'm thinking either the computer you are using is off or doesn't exist... or maybe try using "\\computername" or possibly one with no "-" in it.

Top
#203801 - 2011-11-18 04:56 PM Re: Microsoft Update Session on remote system [Re: BradV]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
 Originally Posted By: BradV
Sure. I have:

 Code:
[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
Ummm... shouldn't you have quotes around the strings? Kix will try to do math on the - operator.
[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
#203803 - 2011-11-18 05:38 PM Re: Microsoft Update Session on remote system [Re: Les]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
I'm pretty sure the ini file and talking to the remote systems works. I had another script that would prompt you for a server name and would then go interrogate that system using WMI to enumerate disk information. I modified it to instead get the computer name from this ini file and ran it. It ran fine and returned all of the correct information from each system. I am looking more closely at the AddCode method.

Regards,

Brad

Top
#203804 - 2011-11-18 06:03 PM Re: Microsoft Update Session on remote system [Re: BradV]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
OK, I added:

 Code:
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 Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
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:

 Code:
$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
 Code:
$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
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.081 seconds in which 0.026 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org