troubleshooting Question

Permission error with this vbs script.

Avatar of bsharath
bsharathFlag for India asked on
Programming Languages-OtherScripting LanguagesVB Script
18 Comments1 Solution329 ViewsLast Modified:
Hi,

I get the below error some times on some machine. Can this be skipped or sorted.

Line 5
Char 1
Permission denied

Any help is of great help.

Regards
Sharath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
Const intForAppending = 8
OutputFile = "\\sophos\InterChk\Sophos_Results.txt"
Set objLog = objFSO.OpenTextFile(OutputFile, intForAppending, True)
 
temp = objNetwork.ComputerName
If per(temp) Then
	objLog.WriteLine temp & ": Attempting to add SYSTEM to Admin group"
	AddUserToAdmin temp
Else
	objlog.WriteLine temp & ": You don't have permission"
End If
  
objLog.Close
wscript.quit
 
Sub AddUserToAdmin (strPC)
        On Error Resume Next 
        Set objGroup = GetObject("WinNT://" & strPC & "/SophosAdministrator")
        If Err.Number <> 0 Then
        objlog.WriteLine strPC & ": SophosAdministrator doesn't exist or exist in non english language"
        On Error Goto 0
        Else
        On Error Goto 0
        
        For Each objUser In objGroup.Members
                objGroup.Remove(objUser.AdsPath)
        Next 
 
        objGroup.Add("WinNT://SYSTEM")
 
  If Err.Number <> 0 Then
    objLog.WriteLine vbTab & strPC & ": An error has occured:  " & Err.Description
  Else
    objLog.WriteLine vbTab & strPC & ": ...added successfully."
  End If
 
  Set objGroup = Nothing
End if 
End Sub 
Function per(computer)
        strcomputer = computer
        On Error Resume Next
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        If err.number <> 0 Then
                err.Clear
                per = False
                On Error goto 0
        Else
                per = True
                On Error goto 0
        End If
End Function
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 18 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 18 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