KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

ShellScript VBScript returns nothing

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
Kris



Joined: 12 May 2010
Posts: 254

PostPosted: Mon Jul 03, 2017 1:06 am    Post subject: ShellScript VBScript returns nothing Reply with quote

Hi guys,

I have created a vbscript that reads the date of the last installed Windows update.
The code runs fine from the prompt or from a compiler.
However, when run from HostMonitor it comes up empty.

Start Command:
Code:
cmd /c cscript /B /E:VBScript %Script%


VBCode
Code:
HKEY_LOCAL_MACHINE   = &H80000002
strComputer          = "<target host>"
strUser              = "<domain>\<username>"
strPassword          = "<password>"
Set objSWbemLocator  = CreateObject("wbemScripting.SwbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\default", strUser, strPassword)
Set objReg           = objSWbemServices.Get("StdRegProv")
strKeyPath           = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install"
strEntryName         = "LastSuccessTime"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strEntryName, strDate
WScript.StdOut.Write "scriptRes:Ok:" & strDate


Any ideas?

HM version: 10.64 running on W2K8R2
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 11761
Location: USA

PostPosted: Mon Jul 03, 2017 4:45 am    Post subject: Reply with quote

Add some checks into script, e.g.
Code:

HKEY_LOCAL_MACHINE   = &H80000002
strComputer          = "<target host>"
strUser              = "<domain>\<username>"
strPassword          = "<password>"

On Error Resume Next

Set objSWbemLocator  = CreateObject("wbemScripting.SwbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\default", strUser, strPassword)

If Err <> 0 Then
  WScript.StdOut.Write statusUnknown & "connect error: " & Err.Description
  WScript.Quit
End If

Set objReg           = objSWbemServices.Get("StdRegProv")

If Err <> 0 Then
  WScript.StdOut.Write statusUnknown & "StdRegProv error: " & Err.Description
  WScript.Quit
End If

strKeyPath           = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install"
strEntryName         = "LastSuccessTime"
objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strEntryName, strDate

If Err <> 0 Then
  WScript.StdOut.Write statusUnknown & "GetString error: " & Err.Description
  WScript.Quit
End If

WScript.StdOut.Write "scriptRes:Ok:" & strDate


Regards
Alex
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kris



Joined: 12 May 2010
Posts: 254

PostPosted: Mon Jul 03, 2017 9:07 am    Post subject: Reply with quote

Added some missing variables and more debugging.
Still the script runs through, resulting in status OK and an empty value for 'strDate'.
And it still runs from the prompt or any compiler and returns a date and time, no problem there.

Code:
On Error Resume Next

strComputer          = "<target host>"
strUser              = "<domain>\<username>"
strPassword          = "<password>"
HKEY_LOCAL_MACHINE   = &H80000002
strKeyPath           = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install"
strEntryName         = "LastSuccessTime"
statusOk             = "scriptRes:Ok:"
statusBad            = "scriptRes:Bad:"
statusUnknown        = "scriptRes:Unknown:"

Set objSWbemLocator  = CreateObject("wbemScripting.SwbemLocator")
If Err <> 0 Then
   WScript.StdOut.Write statusUnknown & "Create Object Error: " & Err.Description
   WScript.Quit
End If

Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\default", strUser, strPassword)
If Err <> 0 Then
   WScript.StdOut.Write statusUnknown & "connect error: " & Err.Description
   WScript.Quit
End If

Set objReg           = objSWbemServices.Get("StdRegProv")
If Err <> 0 Then
   WScript.StdOut.Write statusUnknown & "StdRegProv error: " & Err.Description
   WScript.Quit
End If

objReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strEntryName, strDate
If Err <> 0 Then
   WScript.StdOut.Write statusUnknown & "GetString error: " & Err.Description
   WScript.Quit
End If

WScript.StdOut.Write "scriptRes:Ok:" & strDate
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2833

PostPosted: Mon Jul 03, 2017 1:44 pm    Post subject: Reply with quote

Looks like your value is accessible only for 64 bit applications.

32 and 64 bit applications may retrieve 2 different values from the same registry key/value path.
You may test your key/value path using "Registry" test method (choose "use Win32 reg" then "use Win64 reg").

Another option for checking 32/64bit values is running script from 32/64bit command prompt (to start 32bit command prompt start %windir%\SysWoW64\cmd.exe)

If that's the case, you may modify your script to check 64bit registry values:

You need to replace
Code:
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\default", strUser, strPassword)


with:
Code:
Set arch = CreateObject("WbemScripting.SWbemNamedValueSet")
arch.Add "__ProviderArchitecture", 64
arch.Add "__RequiredArchitecture", True
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\default", strUser, strPassword,,,,arch)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kris



Joined: 12 May 2010
Posts: 254

PostPosted: Tue Jul 04, 2017 12:44 am    Post subject: Reply with quote

Works like a charm!

Thanks a lot!
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2833

PostPosted: Tue Jul 04, 2017 6:55 am    Post subject: Reply with quote

You are welcome!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index