troubleshooting Question

Need to change this as a startup script.

Avatar of bsharath
bsharathFlag for India asked on
Scripting LanguagesVB Script
14 Comments2 Solutions379 ViewsLast Modified:
Hi,

Need to change this as a startup script.
I want this to be used as a startup script so they are recorded into a txt file into a UNC path.

Regards
Sharath
MachineName = "c:\Machines.txt"
OutputFile = "c:\SophosStatus.txt"
Group = "SophosAdministrator"
 
ON ERROR RESUME NEXT
Const ForReading = 1, ForWriting = 2
 
Set fso = CreateObject("Scripting.FileSystemObject")
 
Set objMachineFile = fso.OpenTextFile(MachineName, ForReading)
Set objOutputFile = fso.OpenTextFile(OutputFile, ForWriting, True)
 
Do While objMachineFile.AtEndOfStream <> True
    strComputer = objMachineFile.ReadLine
 '   wscript.echo "Working on: " + strComputer
    if WMIPing(strComputer) then
        Set objGroup = GetObject("WinNT://" & strComputer & "/" & Group & ",group")
        if isempty(objGroup) then
            objOutputFile.Writeline strComputer + ",permission error or Sophos Adminstrators group does not exist"
        else
            Members=False
            For Each objUser in objGroup.Members
                Members=True
            Next
            If Members then
                objOutputFile.Writeline strComputer + ",yes"
            else
                objOutputFile.Writeline strComputer + ",no"
            end if
        end if
    else
        objOutputFile.Writeline strComputer + ",Switched off"
    end if
Loop
objMachinefile.Close
objOutputFile.Close
 
 
Function WMIPing(strComp)
On Error Resume Next 
 
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_PingStatus " & _
        "Where Address = '" & strComp & "'")
 
WMIPing=False
For Each objItem in colItems
    If objItem.StatusCode = 0 Then 
'        WScript.Echo "Reply received."
        WMIPing=True         
    End If
Next
 
End Function
ASKER CERTIFIED SOLUTION
Mark Pavlak

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 14 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 2 Answers and 14 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