troubleshooting Question

Syntax error on Sub Routine??

Avatar of sunnyd24
sunnyd24 asked on
Windows OSVB Script
6 Comments1 Solution511 ViewsLast Modified:
I have a script that deletes a key and all the sub keys as well.  It is :

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = InputBox("Computer Here")

strKeyPath = "SOFTWARE\Microsoft\SMS\Mobile Client\Software Distribution"

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

DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypath

Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath)
    objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys

    If IsArray(arrSubkeys) Then
        For Each strSubkey In arrSubkeys
            DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey
        Next
    End If

    objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath
End Sub






However I need the script to read from a list of machines and do the same thing for all the machines.  I came up with the following, but it is giving me a syntax error on the Sub line and I can't figure out why.

INPUT_FILE_NAME = InputBox("Computer List")

Const FOR_READING = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)

strComputers = objFile.ReadAll

objFile.Close

arrComputers = Split(strComputers, vbCrLf)

For Each strComputer In arrComputers

Const HKEY_LOCAL_MACHINE = &H80000002

strKeyPath = "SOFTWARE\Microsoft\SMS\Mobile Client\Software Distribution"

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

DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath

Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPath)
    objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys

    If IsArray(arrSubkeys) Then
        For Each strSubkey In arrSubkeys
            DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPath & "\" & strSubkey
        Next
    End If

    objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

End Sub
Next
ASKER CERTIFIED SOLUTION
Chris Dent
PowerShell Developer
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros