Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why Can't I Reset Values for Next Loop Iteration

Status
Not open for further replies.

JustScriptIt

Technical User
Oct 28, 2011
73
US
I've spent a week trying to troubleshoot my code.

At first, I thought the computer was pointed to the wrong DNS server, and that's why I'm getting inconsistent output.

But, when I try each IP address individually, I either get the accurate result, or no result at all (because computer cannot authenticate to it, which is acceptable).

Below is the code in it's entirety. Even after attempting to reset and echo the reset values onto the standard output, the script still outputs incorrect values.

This script takes a text file of IP addresses and outputs it to a CSV file.

Can you point out any glaring mistakes?

Thank you for all your help so far...

Code:
Option Explicit

Dim objInputFSO, objOutputFSO, objFile
Dim strInputFile, strData, arrLines, strLine
Dim objWMISvc, colItems, objItem, strComputerDomain, strMember
Dim strComputer, strKeyPath, strValueName, oReg, strValue, dwValue 
Dim objLogicalDisk, strCfree, strDfree, strHDfree
Dim strName, strVersion, intComm, strGroup, strPolicy, strHardware, strVirus, strIPS, intNTP, strSEPM
Dim strArray

const ForAppending = 8
const strOutputFile = "output_for_sep_statistics.csv"
const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002

'Create an Input File System Object
Set objInputFSO = CreateObject("Scripting.FileSystemObject")

'Name of the input text file
strInputFile = InputBox("What is the name of file with list of computers?")

'Open the text file - strData now contains the whole file
strData = objInputFSO.OpenTextFile(strInputFile,1).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Create an Output File System Object
Set objOutputFSO = CreateObject("Scripting.FileSystemObject")

'Create Output File
Set objFile = objOutputFSO.CreateTextFile(strOutputFile)

objFile.WriteLine("IP Address, Computer Name, Free Space on C,Free Space on D,Free Space on Hard Drive," & _
                  "Membership, Current SEP Version,0=Offline 1=Online,Group," & _
	          "Policy Serial Number,Hardware ID,Virus Definition,IPS Signature,0=NTP Off 1=NTP On, SEPM 

Server")



On Error Resume Next

'Step through the lines
For Each strLine in arrLines

  Wscript.echo strComputer & "," & strName & "," & strCfree & "," & strDfree & "," & strHDfree & "," & _ 
                    strMember & "," & strVersion & "," & intComm & "," & strGroup & _  
                    "," & strPolicy & "," & strHardware  & "," &  strVirus & "," & strIPS & "," & intNTP & 

"," & _
  		    strSEPM

  strComputer = strLine

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


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

  Set objLogicalDisk = objWMISvc.Get("Win32_LogicalDisk.DeviceID='C:'")
  strCfree = Int(objLogicalDisk.FreeSpace / 1048576) & " MB"

  Set objLogicalDisk = objWMISvc.Get("Win32_LogicalDisk.DeviceID='D:'")
  strDfree = Int(objLogicalDisk.FreeSpace / 1048576) & " MB"

  Set objLogicalDisk = objWMISvc.Get("Win32_LogicalDisk.DriveType=3")
  strHDfree = Int(objLogicalDisk.FreeSpace / 1048576) & " MB"


  Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", ,48 )
   For Each objItem in colItems
     strComputerDomain = objItem.Domain
     strName = objItem.Name
     If objItem.PartOfDomain Then
       strMember = "Computer Domain: " & strComputerDomain
     Else
       strMember = "Workgroup: " & strComputerDomain
     End If
   Next
  



  strKeyPath = "SOFTWARE\Symantec\Symantec Endpoint Protection\SMC"
  strValueName = "ProductVersion"
  oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  strVersion = strValue

  strKeyPath = "SOFTWARE\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink"
  strValueName = "PolicyMode"
  oReg.GetDWORDValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
  intComm = dwValue 

  strKeyPath = "SOFTWARE\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink"
  strValueName = "CurrentGroup"
  oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  strGroup = strValue 

  strKeyPath = "SOFTWARE\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink"
  strValueName = "SerialNumber"
  oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  strPolicy = strValue 

  strKeyPath = "SOFTWARE\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink"
  strValueName = "HardwareID"
  oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  strHardware = strValue 

  strKeyPath = "SOFTWARE\Symantec\SharedDefs"
  strValueName = "DEFWATCH_10"
  oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  strVirus = strValue 

  'Extract actual virus definition
  strVirus = Split(strVirus, "\")(UBound(Split(strVirus, "\")))

  strKeyPath = "SOFTWARE\Symantec\SharedDefs\SymcData-cndcipsdefs"
  strValueName = "cndcIps"
  oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  strIPS = strValue 

  'Extract actual IPS definition
  strIPS = Split(strIPS, "\")(UBound(Split(strIPS, "\")))

  strKeyPath = "SOFTWARE\Symantec\Symantec Endpoint Protection\SMC"
  strValueName = "smc_engine_status"
  oReg.GetDWORDValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
  intNTP = dwValue 

  strKeyPath = "SOFTWARE\Symantec\Symantec Endpoint Protection\SMC\SYLINK\SyLink"
  strValueName = "LastServerIP"
  oReg.GetStringValue _
   HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
  strSEPM = strValue 


  objFile.WriteLine(strComputer & "," & strName & "," & strCfree & "," & strDfree & "," & strHDfree & "," & _ 
                    strMember & "," & strVersion & "," & intComm & "," & strGroup & _  
                    "," & strPolicy & "," & strHardware  & "," &  strVirus & "," & strIPS & "," & intNTP & "," & _
		    strSEPM)
 
  ' initialize values for next iteration of loop
  strComputer = null
  strName = null
  strCfree = null
  strDfree = null
  strHDfree = null
  strMember = null
  strVersion = null
  intComm = null
  strGroup = null
  strPolicy = null
  strHardware = null
  strVirus = null
  strIPS = null
  intNTP = null
  strSEPM = null



Next

  Wscript.echo "Output is located at output_for_sep_statistics.csv"

'Cleanup
Set objInputFSO=Nothing
Set objOutputFSO=Nothing
 
I figured it out.

I also have to reset the WMI objects.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top