WMI Script for stop service deleting files, starting service

WMI Script for stop service deleting files, starting service

Post by Ymhha3Nhc » Tue, 28 Aug 2007 15:10:00


I am trying to create a WMI script for stoping service, deleting few files
and starting the service for multiple computers. But when I am running the
.vbs file, I am receiving the following error:

C:\>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

C:\test.vbs(9, 1) Microsoft VBScript runtime error: The remote server machin
does not exist or is unavailable: 'GetObject'

Const ForReading = 1
Const ForAppending = 8
'
strFile = "c:\computers.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, ForReading)
Do Until objFile.AtEndOfStream
strComputer = Trim(objFile.ReadLine)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& strComputer &

"\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ='Messenger'")
For Each objService in colListOfServices
objService.StopService()
Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("c:\temp\123.txt")
objFSO.DeleteFile("c:\temp\abc.txt")
objFSO.DeleteFile("c:\temp\sec.txt")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ='jacservice'")
For Each objService in colListOfServices
objService.StartService()
Next
Loop
objFile.Close

Kindly check my script and do the needfull
 
 
 

WMI Script for stop service deleting files, starting service

Post by CarlosBrow » Tue, 28 Aug 2007 16:15:48

Are you sure that the file c:\computers.txt is OK?
Be careful with the blank lines and the names of the servers.

Regards

bhaksar escribi:

 
 
 

WMI Script for stop service deleting files, starting service

Post by Ymhha3Nhc » Tue, 11 Sep 2007 00:42:01

Thanks for the update, Yes I am sure with computers.txt file, I created new
file with 2 computer names for testing, still I have the same issue

Thanks in advance

Regards,
Bhaksar