Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stop services, Install patch

Status
Not open for further replies.

McZook

MIS
Sep 26, 2003
7
US
Hello folks,

I have been using this forum quietly to learn about scripting. This is a great resource!

I am modifying the following script from MS hoping to install the 043 patch on +200 servers (NT4 & 2K)


I need to stop some services before the patch installs and I need error checking so that the patch is NOT applied if any of the services did not stop.

Someone please point me in the right direction ?

Thanks in advance~

McZook
 
Hello McZook,

[1] You get hold of the exact unwelcome service names. That I suppose you have the good ideas already.
[2] Get the instances of the said services one-by-one. You do it with "On Error Resume Next" and trap the error. If error does occur, you can be sure that the service in question is not running. If the script raises an error, you use a routine to stop the service.
[3] To stop the service, you have to understand exactly the dependency. If there are services dependent on the service in question, you stop them first and then stop the parent service.
[4] After stop a particular service, verify again if the service is really stopped.
[5] Loop through the set of unwelcoming services one-by-one as mentioned.
[6] All the mechanics are performed under the cimv2 win32_service class service.

regards - tsuji
 
Correction:
A typo reversing the meaning. [2] should be read:

[2] Get the instances of the said services one-by-one. You do it with "On Error Resume Next" and trap the error. If error does occur, you can be sure that the service in question is not running. If the script raises no error, you use a routine to stop the service.

-tsuji
 
This is what I had written before as a tool for services...

**Code
strServer = InputBox(" Server name - without \\s"," Tell me what server?")
strService = InputBox(" The service to be effected ?"," Service to stop and start?")

Set ServiceSet = GetObject("winmgmts:").ExecQuery("select * from Win32_Service where Name= strService")

'to stop service
for each Service in ServiceSet
RetVal = Service.StopService()
if RetVal = 0 then
WScript.Echo " Service stopped"
elseif RetVal = 5 then
WScript.Echo " Service was not running"
end if
next

'to Start service

Set ServiceSet = GetObject("winmgmts:").ExecQuery("select * from Win32_Service where Name= strService")

for each Service in ServiceSet
RetVal = Service.StartService()
if RetVal = 0 then WScript.Echo " Service started"
if RetVal = 6 then WScript.Echo " Service has NOT been started"
if RetVal = 7 then WScript.Echo " Service did not respond to the start request in a timely fashion."
if RetVal = 10 then WScript.Echo " Service was already running"
If RetVal = 14 then WScript.Echo " Service is disabled"
if RetVal = 24 then WScript.Echo " service is currently paused in the system"

next

**End Code

(forgive the screen wrapping, it looks ok in preview)

I am having trouble melding it with the code for the patch install. I also need to change the patch script to apply to NT4/sp6. anyone know the OS Version # for that?

My eyes are starting to cross...
 
McZook,

I'm now only reasoning in abstract. To melt meaning to trigger the PatchInstall.vbs after you've done all the stopping tasks. If is done by fairly standard way.

You append something like this after
Code:
set wsh = createobject('WScript.Shell")
cmdline = "csript.exe //nologo patchinstall.vbs Ipfile.txt LocalPathToPatches"
wsh.run cmdline
set wsh = nothing
Details you have to look into. I just sketch the general framework.

-tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top