I am new to this and I am trying to get the code below to:

1) delete a reg key value
""SOFTWARE\Intel\LANDesk\Virusprotect6\CurrentVersion\GUID

2) stop the SAV client servuce
3) Start the SAV client service

To a list of 2003 and 2000 servers. I am not sure how to consolidate the
three parts
Thanks


' Delete reg value

Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Intel\LANDesk\Virusprotect6\CurrentVersion"
strStringValueName = "GUID"

oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName



'Stop all service and dependents

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='NetDDE'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )

For Each objService in colServiceList
objService.StopService()
Next

Wscript.Sleep 20000

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='NetDDE'")
For Each objService in colServiceList
errReturn = objService.StopService()
Next



'start service and dependecies

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='NetDDE'")

For Each objService in colServiceList
errReturn = objService.StartService()
Next

Wscript.Sleep 20000

Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='NetDDE'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Dependent" )
For Each objService in colServiceList
objService.StartService()
Next
--
Thank You

Re: del Reg Key Value and stop and start service by Torgeir

Torgeir
Tue Apr 05 11:52:57 CDT 2005

BasilR wrote:

> I am new to this and I am trying to get the code below to:
>
> 1) delete a reg key value
> ""SOFTWARE\Intel\LANDesk\Virusprotect6\CurrentVersion\GUID
>
> 2) stop the SAV client servuce
> 3) Start the SAV client service
>
> To a list of 2003 and 2000 servers. I am not sure how to
> consolidate the three parts
Hi

Try the script below (Note: Not tested)...

'--------------------8<----------------------

' File containing server names, the names on separate lines
sInpFile = "C:\Servers.txt"

' Status will be written here
sStatusFile = "C:\UpdStatus.txt"


Const HKEY_LOCAL_MACHINE = &H80000002

' FileSystemObject.CreateTextFile
Const OverwriteIfExist = -1
Const FailIfExist = 0

' FileSystemObject.OpenTextFile
Const OpenAsDefault = -2
Const CreateIfNotExist = -1
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set oFSO = CreateObject("Scripting.FileSystemObject")

' Get server names into an array:
Set f = oFSO.OpenTextFile (sInpFile, _
ForReading, FailIfNotExist, OpenAsASCII)

Dim aServers()
i = 0
Do Until f.AtEndOfStream
sLine = Trim(f.ReadLine)
If Not sLine = "" Then
ReDim Preserve aServers(i)
aServers(i) = sLine
i = i + 1
End If
Loop
f.Close

' Create status file
Set fStatusFile = oFSO.CreateTextFile(sStatusFile, _
OverwriteIfExist, OpenAsASCII)

' Loop through the server array
' (testing if the servers are connectible using ping)

For Each sServer In aServers

If IsConnectible(sServer,"","") Then
On Error Resume Next

Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& sServer & "\root\default:StdRegProv")

Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sServer _
& "\root\cimv2")

If Err.Number <> 0 Then
sMsg = sServer & ", " & Now & ", " & "Could not connect with WMI," _
& "error # and description: " & Err.Number & ", " _
& Err.Description
Else
On Error Goto 0

strKeyPath = "SOFTWARE\Intel\LANDesk\Virusprotect6\CurrentVersion"
strStringValueName = "GUID"

oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName


'Stop all service and dependents

Set colServiceList = oWMI.ExecQuery("Associators of " _
& "{Win32_Service.Name='NetDDE'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )

For Each objService in colServiceList
objService.StopService()
Next

Wscript.Sleep 20000

Set colServiceList = oWMI.ExecQuery _
("Select * from Win32_Service where Name='NetDDE'")
For Each objService in colServiceList
errReturn = objService.StopService()
Next


'start service and dependecies

Set colServiceList = oWMI.ExecQuery _
("Select * from Win32_Service where Name='NetDDE'")

For Each objService in colServiceList
errReturn = objService.StartService()
Next

Wscript.Sleep 20000

Set colServiceList = oWMI.ExecQuery("Associators of " _
& "{Win32_Service.Name='NetDDE'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Dependent" )
For Each objService in colServiceList
objService.StartService()
Next

sMsg = sServer & ", " & Now & ", " & "Done."

End If
Else
sMsg = sServer & ", " & Now & ", " & "Could not connect with ping."
End If

fStatusFile.WriteLine sMsg
Next
fStatusFile.Close


Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP

' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used

If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750

Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\runresult.tmp"

oShell.Run "%comspec% /c ping -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True

Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)

sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)
IsConnectible = CBool(InStr(sResults, "TTL="))

End Function

'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx