Hi There
I just wrote a script to check if a machine has a pending reboot. https://github.com/TS-Steff/PRTG-GetComputerRebootStatus
'https://www.winvistatips.com/threads/how-can-i-write-a-script-to-read-a-remote-registry-using-different-credentials.760483/ '##### ' 0 - OK, no reboot pending ' 1 - Reboot pending ' 2 - Wrong argument count ' 3 - Connection Error On Error Resume Next Err.Clear Const HKCR = &H80000000 'HKEY_CLASSES_ROOT Const HKCU = &H80000001 'HKEY_CURRENT_USER Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE Const HKUS = &H80000003 'HKEY_USERS Const HKCC = &H80000005 'HKEY_CURRENT_CONFIG Dim strComputer, strUser, strPassword Dim objSWbemLocator, objSWbemServices, objReg Dim strKeyPath, strEntryName, strValue Dim rebootReuired Set objArguments = WScript.Arguments 'arguments 'https://www.clearbyte.ch/vb-script-parameter-uebergabe/ rebootRequired = 0 strComputer = "" strUser = "" strDomain = "" strPassword = "" strDomainUser = "" strKeyPathWUPD = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" strKeyPathCBS = "SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" 'check argument count if objArguments.Count <> 4 Then WScript.echo "2:Wrong argument Count" WScript.Quit else strComputer = objArguments(0) strUser = objArguments(1) strDomain = objArguments(2) strPassword = objArguments(3) strDomainUser = strDomain & "\" & strUser end if 'connect to server Set objSWbemLocator = CreateObject("wbemScripting.SwbemLocator") Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\default", strDomainUser, strPassword) if Err.Number <> 0 Then WScript.echo "3:" & Err.Description WScript.Quit end if Set objReg = objSWbemServices.Get("StdRegProv") if Err.Number <> 0 Then WScript.echo "3:" & Err.Description WScript.Quit end if 'check if WUPD or CBS reboot flagged if objReg.EnumKey(HKLM, strKeyPathWUPD, arrSubKeys) = 0 OR objReg.EnumKey(HKLM, strKeyPathCBS, arrSubKeys) = 0 Then '*** Reboot Required *** WScript.echo "1:Reboot Pending" else '*** NO REBOOT REQUIRED WScript.echo "0:OK" end if
If i add the custom sensor the script sucessfully checks the machine and returns the correct value such as "0:OK"
However. If the system needs a reboot, registry value available, the sensor does not change it's state and stucks at 0:OK. The log-data from the specific sensor also returns 0:OK If I recreate the sensor the state is 1:reboot pending. After the reboot, and manually checking the reg-keys (which are not there anymore), the sensor keeps in state 1:reboot pending.
If I run the script directly from the probe, it always returns the correct value.
Why does the probe always return the last state?
Thanks for your help.
Add comment