|
View previous topic :: View next topic |
Author |
Message |
rj
Joined: 23 Dec 2009 Posts: 7
|
Posted: Fri Oct 15, 2010 8:50 am Post subject: value of vbscript variables when run by hostmonitor |
|
|
In order to test some registry key on a windows 2008x64 machine I've tried to use a vbscript calling a WMI stdRegProv method GetDWORD.
The script works fine when run from the commandline but from within Hostmonitor it doesn't.
Aparently the value of the variable "mydwValue" then seems to get lost, therefore the last IF statement in the script indifferently returns "statusBad" even when mydwValue should have been 1:
Code: | Option Explicit
const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
dim strComputer, oReg, strKeyPath, strValueName, mydwValue
strComputer = "."
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
strValueName = "AUOptions"
oReg.GetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,mydwValue
If mydwValue = 1 Then
WScript.StdOut.Write statusOk
Else
WScript.StdOut.Write statusBad
End if
|
|
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12800 Location: USA
|
Posted: Fri Oct 15, 2010 2:03 pm Post subject: |
|
|
H'm, regardles how we run this script (using HostMonitor or command line), it cannot access this specific registry key on our Windows 2008 system. It works fine with other registry keys and it works just fine on Windows XP, 2003 systems.
We checked user permissions, tried to use regedit - everything is fine.
Looks like some Windows "features"
BTW:
What exactly HostMonitor option do you use to run this script? Shell Script test method?
Note:
If you are running HostMonitor as service, please do not forget to provide admin account using options located on Service page in HostMonitor Options dialog
Regards
Alex |
|
Back to top |
|
|
rj
Joined: 23 Dec 2009 Posts: 7
|
Posted: Fri Oct 15, 2010 3:39 pm Post subject: |
|
|
Thanks a lot for diving in to this subject and responding quickly.
Indeed, I've been using the Shell Script test method. I also tested the script with the script manager and the "Lets try" option. To OS is: Microsof Windows Server 2008 R2 Enterprise Version 6.1.7600 and Hostmonitor is being run not as a seervice but started as a program when logged in as Administrator. I'll experiment reading some other keys and post the results here later.
Regards,
Robert |
|
Back to top |
|
|
rj
Joined: 23 Dec 2009 Posts: 7
|
Posted: Mon Oct 18, 2010 5:32 pm Post subject: |
|
|
Strangely the abovementionned script doesn't resolve the following two values when executed by Hostmonitor:
GetDWORDValue HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update.AUOptions
GetStringValue HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon.AutoAdminLogon
yet this one does give a correct reply:
GetDWORDValue HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl.AutoReboot
Maybe its because the first two keys contain a space character.
Just Mentioning: I thought to try a workaround and read the same registry value using a Powershell script. But the following command doesn't seem to work as expected either when run by 32bits powershell. Code: | get-itemproperty -path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" -name "AUOptions" |
|
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12800 Location: USA
|
Posted: Tue Oct 19, 2010 12:30 pm Post subject: |
|
|
No, space is not a problem.
I think there is some permission related issue. Could you try to disable UAC or start HostMonitor using "Run as adminitrator" option?
Actually HostMonitor uses manifest to get admin rights but may be this does not work in your case for some reason
May be you have installed some antivirus monitors or other security related 3rd party software?
Also, you may modify script a little bit (using On Error Resume Next command) and get error description.
E.g. Code: | Option Explicit
const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
dim strComputer, oReg, strKeyPath, strValueName, mydwValue
On Error Resume Next
strComputer = "."
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
If Err.Number=0 then
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
strValueName = "AUOptions"
oReg.GetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,mydwValue
If Err.Number=0 then
If mydwValue = 1 Then
WScript.StdOut.Write statusOk
Else
WScript.StdOut.Write statusBad
End if
else
WScript.StdOut.Write statusUnknown & Err.Description
end if
else
WScript.StdOut.Write statusUnknown & Err.Description
end if
|
Regards
Alex |
|
Back to top |
|
|
rj
Joined: 23 Dec 2009 Posts: 7
|
Posted: Tue Oct 19, 2010 5:23 pm Post subject: |
|
|
Hi Alex!
Thanks for the script improvements and debugging tips.
According to the taskmanager: the hostmon.exe*32 process was already running as Administrator. To be sure I've disabled UAC restarted the server and started HostMonitor using "Run as adminitrator". The machine runs without any 3rd party virusscanners / security tools, but maybe I should mention that its installed under a VMWare host.
I've copied your script including the error description. In it, i've took the liberty to add "& mydwValue" behind the status in the following lines:
Code: | If mydwValue = 1 Then
WScript.StdOut.Write statusOk & mydwValue
Else
WScript.StdOut.Write statusBad & mydwValue
End if |
Thereafter, running the script from Hostmonitor's Script Manager I get:
Quote: | [0:40:36] HostMonitor is going to execute "vbscript CheckAutoUpdateOff" script ...
[0:40:36] Script executed, correct result received:
----------
- Status: Bad
- Reply:
---------- |
Yet the same script from the commandline produces:
Quote: | Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>cscript /E:vbscript c:\scripts\CheckAutoUpdateOff.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
scriptRes:Ok:1 |
When I change the line Code: | If mydwValue = 1 Then | in Code: | If mydwValue = nil Then | then the result in Hostmonitor becomes:
Quote: | [0:43:23] HostMonitor is going to execute "vbscript CheckAutoUpdateOff" script ...
[0:43:23] Script executed, correct result received:
----------
- Status: Ok
- Reply:
---------- |
So, it still appears that when run from Hostmonitor mydwValue does not get properly assigned its value or looses its value outside some kind of scope. I've continued by trying to run the Hostmonitor application with compatability modes Windows 2008 and Windows XP, but this made no difference either.
Regards,
Robert |
|
Back to top |
|
|
Paul_NHS
Joined: 25 Feb 2009 Posts: 59
|
Posted: Wed Oct 20, 2010 2:32 am Post subject: |
|
|
"If mydwValue = nil Then" should not work unless you have set mydwValue to "nil". If you are testing for NULL you need to use "If mydwValue is nothing Then" or if it's an empty string it's "If mydwValue = "" Then".
cheers, Paul |
|
Back to top |
|
|
rj
Joined: 23 Dec 2009 Posts: 7
|
Posted: Wed Oct 20, 2010 3:02 am Post subject: |
|
|
Ok. I've been able to replicate the faulty behavior on the commandline using the 32bit version of cscript.exe
Using the following script: Code: | Option Explicit
const statusUnknown = "scriptRes:Unknown:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
Const HKEY_LOCAL_MACHINE = &H80000002
dim strComputer, oReg, strKeyPath, strValueName, mydwValue
On Error Resume Next
strComputer = "."
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
If Err.Number=0 then
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update"
strValueName = "AUOptions"
oReg.GetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,mydwValue
If Err.Number=0 then
If mydwValue = 1 Then
WScript.StdOut.Write statusOk & mydwValue
Else
WScript.StdOut.Write statusBad & mydwValue
End if
else
WScript.StdOut.Write statusUnknown & Err.Description
end if
else
WScript.StdOut.Write statusUnknown & Err.Description
end if |
Quote: | Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>%windir%\system32\cscript.exe /E:vbscript /NoLogo c:\scripts\CheckAutoUpdateOff.vbs
scriptRes:Ok:1
C:\Users\Administrator>%windir%\sysWOW64\cscript.exe /E:vbscript /NoLogo c:\scripts\CheckAutoUpdateOff.vbs
scriptRes:Bad:
C:\Users\Administrator> |
Thus, it is most probably related to the fact that hostmonitor uses the 32bit version of cscript. Is there some workaround for this or should I convince our sysadmin to provide a 32bit version of Windows for me?
Regards,
Robert |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12800 Location: USA
|
Posted: Thu Oct 21, 2010 4:11 pm Post subject: |
|
|
Theoretically its easy to configure HostMontior's Shell Manager to start 64bit version of cscript - just type
c:\windows\system32\csript.exe /E:VBScript %Script% %Params%
instead of
csript.exe /E:VBScript %Script% %Params%
But here is surprise - Windows starts c:\windows\sysWOW64\csript.exe even if 32bit application (e.g. HostMonitor) specifically calls another exe module (c:\windows\system32\csript.exe)!!
That's why we could not execute this script from command line - we used another 32bit application as shell.
We tried to modify script but still - 32bit cscript.exe on 64bit system cannot access this registry key
May be there is some simple Windows tweak that can fix the problem but we cannot find such information. Compatibility mode does not help...
Regards
Alex |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12800 Location: USA
|
Posted: Thu Oct 21, 2010 5:50 pm Post subject: |
|
|
That's why script and 32bit applications cannot access this registry key - Windows redirects requests to HKEY_LOCAL_MACHINE\Software tree
(and Windows "reflector" does not reflects everything... )
http://support.microsoft.com/kb/305097
BTW: if you copy cscript.exe from system32 folder into sysWOW64 then HostMonitor will be able to start 64bit script processor.
But I am not sure this is 100% safe for other 32bit applications that are using scripts on this system
Regards
Alex |
|
Back to top |
|
|
rj
Joined: 23 Dec 2009 Posts: 7
|
Posted: Fri Oct 22, 2010 3:08 am Post subject: |
|
|
Thanks a lot for your inputs Paul and Alex.
The solution to have Hostmonitor call the 64 bit version of cscript is just fine with me. I've copied and renamed cscript from %windir%\system32\cscript.exe to %windir%\SysWOW64\cscript64.exe leaving the origional 32bit version in place. Using the following line in Hostmonitor to start the script then solves the problem.
Quote: | cscript64.exe /B /E:VBScript %Script% |
|
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12800 Location: USA
|
Posted: Fri Oct 22, 2010 1:15 pm Post subject: |
|
|
Nice solution!
And we found another one. There is script that can check 64bit registry tree from 32bit application.
Code: |
Option Explicit
const statusAlive = "scriptRes:Host is alive:"
const statusDead = "scriptRes:No answer:"
const statusUnknown = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"
const HKEY_LOCAL_MACHINE = &H80000002
dim sData, OS, objArgs, keyPath, keyName
Set objArgs = WScript.Arguments
if objArgs.count <> 4 then
WScript.StdOut.Write statusUnknown & "expected parameters: <Path to registry key> <Key name> <registry type: 32 | 64> <value to compare>"
WScript.Quit
end if
keyPath = objArgs(0)
keyName = objArgs(1)
if objArgs(2) = "64" then
OS = 64
else
OS = 32
End if
sData = ReadRegStr (HKEY_LOCAL_MACHINE, keyPath, keyName, OS)
if CStr(sData) = objArgs(3) then
WScript.StdOut.Write statusOk & sData
else
WScript.StdOut.Write statusBad & sData
end if
Function ReadRegStr (RootKey, Key, Value, RegType)
Dim oCtx, oLocator, oReg, oInParams, oOutParams
Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
oCtx.Add "__ProviderArchitecture", RegType
Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")
Set oInParams = oReg.Methods_("GetDwordValue").InParameters
oInParams.hDefKey = RootKey
oInParams.sSubKeyName = Key
oInParams.sValueName = Value
Set oOutParams = oReg.ExecMethod_("GetDwordValue", oInParams, , oCtx)
ReadRegStr = oOutParams.uValue
End Function |
Parameters: <Path to registry key> <Key name> <registry type: 32 | 64> <value to compare>"
Regards
Alex |
|
Back to top |
|
|
|
|
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
|