Service Stop/Start 
Author Message
 Service Stop/Start

Can someone share some simple VBScript code with me to stop/restart a
service on a Remote NT server?

Thanks,
Troy



Sat, 14 Feb 2004 01:20:11 GMT  
 Service Stop/Start
Both ADSI and WMI support access to services to query status, stop/start, etc.

See Clarence's ADSI and WMI FAQs at

http://cwashington.netreach.net/script_repository/faqs.asp?topic=adsifaq
http://cwashington.netreach.net/script_repository/faqs.asp?topic=wmifaq

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> Can someone share some simple vbScript code with me to stop/restart a
> service on a Remote NT server?

> Thanks,
> Troy



Sat, 14 Feb 2004 03:56:26 GMT  
 Service Stop/Start
Thanks Michael.  I've seen those, but have 2 questions:

1.  How do I modify the script to execute against 'remote' NT machines.
2.  How do I check the 'return code' on stop/start requests??

Troy



Quote:
> Both ADSI and WMI support access to services to query status, stop/start,
etc.

> See Clarence's ADSI and WMI FAQs at

> http://cwashington.netreach.net/script_repository/faqs.asp?topic=adsifaq
> http://cwashington.netreach.net/script_repository/faqs.asp?topic=wmifaq

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --

> Please do not email questions - post them to the newsgroup instead.
> --




- Show quoted text -

Quote:
> > Can someone share some simple vbScript code with me to stop/restart a
> > service on a Remote NT server?

> > Thanks,
> > Troy



Sat, 14 Feb 2004 04:26:05 GMT  
 Service Stop/Start
Michael,

I've tried to use these examples, but seem to have two problems:

1.  How can I execute these against REMOTE machines
2.  How do I check the 'return code' of start/stop requests??

Thanks,
Troy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sat, 14 Feb 2004 04:27:40 GMT  
 Service Stop/Start
(Tip: if you use a fully qualified DNS name like "myserver.mycompany.com" instead of the NetBIOS
name "myserver" you'll get slightly better GetObject performance)...

For both ADSI and WMI you need to be in the Administrators group on the remote box.  For WMI, you
need WMI (preferably the same version) installed on both sides...

===============================================

RemoteComputer = "whatever"

Set MessengerServiceObj = GetObject("WinNT://" & RemoteComputer & "/messenger")
MessengerServiceObj.stop

===============================================

RemoteComputer = "whatever"

For each Service in GetObject("winmgmts:{impersonationLevel=impersonate}!//" & RemoteComputer)_
    .ExecQuery("select * from Win32_Service where Name='" & ServiceName & "'")
    Service.StopService
Next

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> Thanks Michael.  I've seen those, but have 2 questions:

> 1.  How do I modify the script to execute against 'remote' NT machines.
> 2.  How do I check the 'return code' on stop/start requests??

> Troy



> > Both ADSI and WMI support access to services to query status, stop/start,
> etc.

> > See Clarence's ADSI and WMI FAQs at

> > http://cwashington.netreach.net/script_repository/faqs.asp?topic=adsifaq
> > http://cwashington.netreach.net/script_repository/faqs.asp?topic=wmifaq

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > --

> > Please do not email questions - post them to the newsgroup instead.
> > --



> > > Can someone share some simple vbScript code with me to stop/restart a
> > > service on a Remote NT server?

> > > Thanks,
> > > Troy



Sat, 14 Feb 2004 05:29:01 GMT  
 Service Stop/Start
Michael,

I tried your second script and got the following error:

C:\TEMP\test.vbs(4, 1) Microsoft VBScript runtime error: ActiveX component
can't
 create object: 'GetObject'

I get this error on the "for each service" statement..  What's going on??
I'm running this on a Win2k Pro machine that was upgraded from NTW.

Troy



Quote:
> (Tip: if you use a fully qualified DNS name like "myserver.mycompany.com"

instead of the NetBIOS
Quote:
> name "myserver" you'll get slightly better GetObject performance)...

> For both ADSI and WMI you need to be in the Administrators group on the

remote box.  For WMI, you
Quote:
> need WMI (preferably the same version) installed on both sides...

> ===============================================

> RemoteComputer = "whatever"

> Set MessengerServiceObj = GetObject("WinNT://" & RemoteComputer &
"/messenger")
> MessengerServiceObj.stop

> ===============================================

> RemoteComputer = "whatever"

> For each Service in

GetObject("winmgmts:{impersonationLevel=impersonate}!//" & RemoteComputer)_
Quote:
>     .ExecQuery("select * from Win32_Service where Name='" & ServiceName &
"'")
>     Service.StopService
> Next

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --

> Please do not email questions - post them to the newsgroup instead.
> --




- Show quoted text -

Quote:
> > Thanks Michael.  I've seen those, but have 2 questions:

> > 1.  How do I modify the script to execute against 'remote' NT machines.
> > 2.  How do I check the 'return code' on stop/start requests??

> > Troy



> > > Both ADSI and WMI support access to services to query status,
stop/start,
> > etc.

> > > See Clarence's ADSI and WMI FAQs at

http://cwashington.netreach.net/script_repository/faqs.asp?topic=adsifaq
http://cwashington.netreach.net/script_repository/faqs.asp?topic=wmifaq

- Show quoted text -

Quote:

> > > --
> > > Michael Harris
> > > Microsoft.MVP.Scripting
> > > --

> > > Please do not email questions - post them to the newsgroup instead.
> > > --



> > > > Can someone share some simple vbScript code with me to stop/restart
a
> > > > service on a Remote NT server?

> > > > Thanks,
> > > > Troy



Sat, 14 Feb 2004 20:04:58 GMT  
 Service Stop/Start
Never mind.  I see what I did wrong.  I connected to a NT 4.0 machine that
isn't running WMI.

Thanks,
Troy


Quote:
> Michael,

> I tried your second script and got the following error:

> C:\TEMP\test.vbs(4, 1) Microsoft VBScript runtime error: ActiveX component
> can't
>  create object: 'GetObject'

> I get this error on the "for each service" statement..  What's going on??
> I'm running this on a Win2k Pro machine that was upgraded from NTW.

> Troy



> > (Tip: if you use a fully qualified DNS name like

"myserver.mycompany.com"

- Show quoted text -

Quote:
> instead of the NetBIOS
> > name "myserver" you'll get slightly better GetObject performance)...

> > For both ADSI and WMI you need to be in the Administrators group on the
> remote box.  For WMI, you
> > need WMI (preferably the same version) installed on both sides...

> > ===============================================

> > RemoteComputer = "whatever"

> > Set MessengerServiceObj = GetObject("WinNT://" & RemoteComputer &
> "/messenger")
> > MessengerServiceObj.stop

> > ===============================================

> > RemoteComputer = "whatever"

> > For each Service in
> GetObject("winmgmts:{impersonationLevel=impersonate}!//" &
RemoteComputer)_
> >     .ExecQuery("select * from Win32_Service where Name='" & ServiceName
&
> "'")
> >     Service.StopService
> > Next

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > --

> > Please do not email questions - post them to the newsgroup instead.
> > --



> > > Thanks Michael.  I've seen those, but have 2 questions:

> > > 1.  How do I modify the script to execute against 'remote' NT
machines.
> > > 2.  How do I check the 'return code' on stop/start requests??

> > > Troy



> > > > Both ADSI and WMI support access to services to query status,
> stop/start,
> > > etc.

> > > > See Clarence's ADSI and WMI FAQs at

> http://cwashington.netreach.net/script_repository/faqs.asp?topic=adsifaq

> http://cwashington.netreach.net/script_repository/faqs.asp?topic=wmifaq

> > > > --
> > > > Michael Harris
> > > > Microsoft.MVP.Scripting
> > > > --

> > > > Please do not email questions - post them to the newsgroup instead.
> > > > --



> > > > > Can someone share some simple vbScript code with me to
stop/restart
> a
> > > > > service on a Remote NT server?

> > > > > Thanks,
> > > > > Troy



Sat, 14 Feb 2004 20:30:58 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. services, stopping/starting, changing startup type

2. Starting, stopping and pauseing a service.

3. Start/Stop a NT Service using wsh/adsi

4. Starting and Stopping NT Services with ADSI,wsh, and VBScript

5. Stop and Starting Services on NT

6. stop/start a service in VBS

7. login script to start/stop service

8. start and stop services

9. How to start/stop a NT service

10. START/STOP/ displayed Services running on PC thu an ASP page

11. How to start/stop services with vbscript?

12. Problems with stopping/starting service

 

 
Powered by phpBB® Forum Software