Host Monitor as a service - Shell Script returns no results

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
JoelD
Posts: 6
Joined: Thu Sep 01, 2011 3:09 pm

Host Monitor as a service - Shell Script returns no results

Post by JoelD »

I'm having an issue trying to get any Shell Script test to run successfully whenever HostMonitor is running as a service. Even the most basic VBScript results in a reply of "Error: Script returns no results". The Shell Script will run fine when running HostMonitor interactively, but not when it is running as a service.

Some details:
  • - I am running HostMonitor v8.86 on Windows 2008 R2.
    - I have the HostMonitor service set to log on as Local System account.
    - I tried "Allow service to interact with desktop" both checked and unchecked
    - I have a domain user account and password configured in HostMonitor's Options Service tab.
    - That domain account is a member of the local Administrators group on the server.
    - The test works when I am logged into the server as that domain account and I run HostMonitor interactively.
To eleminate any VBScript code as the problem, I stripped down to a one line test script:

Code: Select all

WScript.StdOut.Write "scriptRes:Ok:0"
Using the following 'Start cmd':

Code: Select all

cmd /c cscript /B /E:VBScript %Script%
(I also tried using the full paths to C:\Windows\SysWOW64\cmd.exe and C:\Windows\SysWOW64\cscript.exe in the 'Start cmd', which made no difference.)

I used the SysInternals ProcMon (Process Monitor) tool to see what was going on - and hopefully discover some obvious problem - when the test executed in each instance (HostMonitor running as a service, and HostMonitor running interactively). When running interactively ProcMon showed the 'cmd' process running and then the 'cscript' subprocess running, as expected. But when HostMonitor was running as a service the 'cmd' process ran but no 'cscript' subprocess ever started.
(Unfortunately ProcMon didn't reveal any obvious problem that I could see. The 'cmd' process just ended with no 'cscript' process ever appearing, and no indication that the 'cmd' process had any problem.)

Any suggestions on what might be the cause and/or other things to try to help determine the cause?

Thanks.
JoelD
Posts: 6
Joined: Thu Sep 01, 2011 3:09 pm

Post by JoelD »

Ah, ha. Just discovered some additional information.

I hadn't ever seen any "errors" in any of the Event logs when troubleshooting this. No indication at all of any problem.

But...

I just noticed an entry in the System Event log, which I didn't notice before because I was looking for errors or warnings and this one is simply an "Information" event:
Application popup: cmd.exe - Application Error : The application was unable to start correctly (0xc0000142). Click OK to close the application.
I have verfied that this event gets logged whenever the test executes when HostMonitor is running as a service, and it does not get logged when I run HostMonitor interactively and execute the test.

Now if I can just figure out why 'cmd.exe' is "unable to start correctly".
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

I have the HostMonitor service set to log on as Local System account.
- I have a domain user account and password configured in HostMonitor's Options Service tab.
- That domain account is a member of the local Administrators group on the server
Sounds good.
Actually for Windows 2008 you may try to specify local admin account for service using Windows Services applet. Anyway services cannot interact with desktop on Windows 2008 and you have to use RCC.

We never seen this error but according to Google a lot of people have similar problems with different programs. Answers suggest that some system files corrupt but do not say what exactly files.
Why it works when HostMonitor started as application? I don't know :(
Could you try to create new user account and specify this account for HostMonitor service?

Regards
Alex
JoelD
Posts: 6
Joined: Thu Sep 01, 2011 3:09 pm

Post by JoelD »

Well...

I tried creating and using a new local account (added it to local Administrators), but that didn't make any difference. :-( I suspect there is some obscure security policy or permission on my server that is causing this, but it may be like trying to find a needle in a haystack to track it down.

But...

When I changed the HostMonitor service to run under my local admin account (instead of Local System account), as you suggested, my simple script test ran successfully! :-) (I didn't think of the fact that there's no problem running the HostMonitor service under our local admin account since on Windows 2008 services cannot interact with the desktop and we have to use RCC anyway. Thanks.)

Unfortunately...

When I tried replacing the simple VBScript with the actual VBScript that we ultimatley want to execute, it did not run successfully ("Error: script timed out"). :-( I suspected that was because we are using the Internetexplorer.Application object and it was having an issue. I did some troubleshooting and verified that the script was indeed timing out at the call to create the Internetexplorer.Application object.

So...

I started thinking "what other way could I do this"... And decided to try it as an Active Script. It immediately didn't work because our VBScript uses WScript. I found a post in the forums where it was suggested to use WScript.Shell.Run to have an Active Script run a VBScript that uses WScript. So I tried that, and it worked! :-)

But...

I really needed my VBScript to be able to return that status string to HostMonitor, and WScript.Shell.Run only returns a return code. :-(

So...

I did a little research and found that WScript.Shell.Exec is similar to WScript.Shell.Run but it returns an object that provides access to StdOut, among other things. I changed my Active Script to use WScript.Shell.Exec, and I set PerformTest equal to ".StdOut.ReadAll" of the object returned by the WScript.Shell.Exec call.

Success! :-D



(I'd still like to figure out why Shell Script works with HostMonitor interactively but doesn't work with HostMonitor as a service. I'll probably troubleshoot that some more at some point. But at least I now have a method that works.)
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Complicated :wink:
There is one trick with Shell Script test method (I don't think it will help in this case but it can help when you use some external programs). You may
tell HostMonitor do not use Windows Pipes mechanism: add SScript_UseWindowsPipe=0 line into [Misc] section of hostmon.ini file and restart HostMonitor.

Regards
Alex
JoelD
Posts: 6
Joined: Thu Sep 01, 2011 3:09 pm

Post by JoelD »

As a follow-up, just to let you know... as you suspected, that trick didn't help in this case.


Luckily my Active Script verison is still working great and doing everything I need it to do.

Thanks for your help.
Post Reply