Question

  Asked: Apr 18 2008   12:24 AM GMT
  Asked by: Naaz


Need vbscript that can pop up alert when services go down on a remote computer


VBScript, Scripting, Windows scripting

Hi,

I have tried many scripts at my local machine. It gave pop up when service for one particular application went down. But the same thing is not happening for the remote computer. Please look at the script below:

strComputer = "."
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
objPolicy.FirewallEnabled = FALSE

Set objAdminSettings = objPolicy.RemoteAdminSettings
objAdminSettings.Enabled = TRUE

Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputerName& "\root\cimv2")
Set colRunningServices = oWMIService.ExecQuery _
("SELECT * FROM Win32_Service)

For Each oService in colRunningServices
Wscript.Echo oService.DisplayName & VbTab & oService.State
Next

I have tried without the firewal and admin rights settings as well in the above code and giving the IP address of the remote computer in strcomputer="IP Address"

It doesn't work. Could you please help me out in knowing the problem with the above or give me some code which can do the purpose.
Awaiting eagerly for your response.

Many Thanks.
Naaz.

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+3
Click to Vote:
  •   3
  •  0



Naaz,

There were a couple things wrong. You didn't have Select * from Win32_Service terminated with a quote and there were several variations of variables dor the "computer name" (strComputer, sComputerName, etc). I also don't know that you need to use HNetCfg.FwMgr nessisarily, I've disabled it in the code by remarking the two lines that change the settings-- you can unremark them if you need to-- but it seems to work with out it on my system

I've fixed the code and it is below:

Option explicit
Dim sComputer, objFirewall, ObjPolicy, objAdminSettings
Dim oService, oWMIService, colRunningServices

sComputer = "."
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
'objPolicy.FirewallEnabled = FALSE

Set objAdminSettings = objPolicy.RemoteAdminSettings
'objAdminSettings.Enabled = TRUE

Set oWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set colRunningServices = oWMIService.ExecQuery _
("SELECT * FROM Win32_Service")

For Each oService in colRunningServices
Wscript.Echo oService.DisplayName & VbTab & oService.State
Next


This doesn't help. Please see the discussion below
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development and Microsoft Windows.

Looking for relevant Development Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Jlees  |   Apr 18 2008  1:13PM GMT

Be sure and check out my blog here on ITKE for more Network administration and VBSCRIPT tips.
The VBScript Network and Systems Administrator’s Cafe

 

Naaz  |   Apr 21 2008  4:25PM GMT

Hi Jlees,

Thanks for your help on this.

But i get error message as “There are no more endpoints available from the endpoint mapper.”

Also, it would be great of you if you can give modified code that can tell me the status of service on a remote computer but not on a local computer.

Thanks much in advance. But m very much in need of your answer on this. Please reply to this asap.

Regs,
Naaz.