| |
mwebb
Posts: 35
Score: 0
Joined: 1/30/2007
Status: offline
|
I am trying to use a Boolean statement to test connections using "ping" When I tested the following script it worked fine: ----------------------------------------- 'Ping Script Dim PINGFlag strComputer = "dc01" Set WshShell = CreateObject("WScript.Shell") If CheckConnection(strComputer) = True Then WScript.Echo strComputer & " is connected" & PINGflag Else WScript.Echo strComputer & " is not connected" & PINGflag End if WScript.Echo "Done!!" WScript.Quit Function CheckConnection(strComputer) PINGFlag = Not CBool(WshShell.run("ping -n 1 " & strComputer, 0, True)) IF PINGFlag = True Then WScript.Echo "Successful Ping" & " " & PINGFlag Else WScript.Echo "Unsuccessful Ping" & " " & PINGFlag End If CheckConnection = PINGFlag End Function --------------------------------------------------------------- But when I put it a larger program I cannot get a boolean PINGFlag value Below I tried it both as a function and in the main program with the same results no True or False value for PINGFlag I am stumped why is works in one place but not another The problem area has a puzzled face. ----------------------------------------- 'Processor and memory query. 'This script queries each computer in the domain for info on the processor and 'physical memory on the computer. The results are written to a text file. Option Explicit On Error Resume Next 'Setup variables Dim objComputer Dim objItem Dim strComputerName(5) Dim strNewName Dim strPassName Dim strNewPassName Dim intCounter Dim intLength Dim objWMI Dim colItems Dim objItem2 Dim strProcessor Dim strMemory Dim strComputer Dim strTextF, strTextFile Dim objFSO Dim objTextF Dim intI Dim intMemory Dim intMaxSpeed Dim strProcName Dim PINGFlag 'Get computer names from AD and place into a str array intCounter = 0 Set objComputer = GetObject("LDAP://cn=Computers,dc=colfalls,dc=loc") WScript.Echo "Storing Names in Array" For Each objItem in objComputer 'WScript.Echo objItem.Name strNewName = StringStuff(objItem.Name) strComputerName(intCounter) = strNewName 'WScript.Echo "name from array " & strComputerName(intCounter) intCounter = intCounter + 1 Next ReDim strComputerName(intCounter) strTextFile = "C:\MemProcInfo2.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set WshShell = CreateObject("WScript.Shell") For intI = 0 to (intCounter-1) strComputer = strComputerName(intI) WScript.Echo "Check Connection response: " PINGFlag = Not CBool(WshShell.Run("ping -n 1" & StrComputer, 0, True)) WScript.Echo PINGflag If PINGFlag = False Then WScript.Echo "not connected: " & strComputer & PINGflag intMemory = 0 intMaxSpeed = 0 strProcName = "no connection" QueryToText Else Wscript.Echo "connected " & strComputer & PINGflag Set objWMI = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2") 'WScript.Echo strComputer Set colItems = objWMI.ExecQuery("Select * From Win32_ComputerSystem",,48) For Each objItem2 in colItems intMemory = objItem2.TotalPhysicalMemory 'WScript.Echo intMemory Next Set colItems = objWMI.ExecQuery("Select * From Win32_Processor",,48) For Each objItem2 in colItems intMaxSpeed = objItem2.MaxClockSpeed strProcName = objItem2.Name 'WScript.Echo intMaxSpeed & " " & strProcName Next QueryToText End If Next WScript.Echo "Done!!!" WScript.Quit 'This funtion strips out "cn=" from the computername and returns the result Function StringStuff(strPassName) 'WScript.Echo "in sub " & strPassName intLength = len(strPassName) intLength = intLength -3 strNewPassName = right(strPassName, intLength) 'WScript.Echo "new name " & strNewPassName StringStuff = strNewPassName End Function 'This sub writes the Info a text file sub QueryToText Set objTextF = objFSO.OpenTextFile(strTextFile, 8, True) objTextF.WriteLine strComputer objTextF.WriteLine "Total Physical Memory: " & intMemory objTextF.WriteLine "Processor Max Speed: " & intMaxSpeed objTextF.WriteLine "Processor Nomenclature: " & strProcName objTextF.WriteLine objTextF.Close end Sub 'This function pings strComputer and returns a false if the ping was unsuccessful 'Function CheckConnection(strComputer) 'PINGFlag = Not CBool(WshShell.Run("ping -n 1" & strComputer, 0, True)) 'WScript.Echo "in CheckConnection" 'WScript.Echo "PINGFlag: " & PINGflag 'CheckConnection = PINGFlag 'End Function
|
|