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!

Same script on different domain/workgroup gives different results 1

Status
Not open for further replies.

JustScriptIt

Technical User
Oct 28, 2011
73
US
I have created the following script to troubleshoot issue on our network:

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

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")

On Error Resume Next

'Step through the lines
For Each strLine in arrLines

  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.Caption
     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 

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

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

  objFile.WriteLine(strComputer & "," & strName & "," & strCfree & "," & strDfree & "," & strHDfree & "," & _ 
                    strMember & "," & strVersion & "," & intComm & "," & strGroup & _  
                    "," & strPolicy & "," & strHardware  & "," &  strVirus & "," & strIPS & "," & intNTP)
 

Next

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

'Cleanup
Set objInputFSO=Nothing
Set objOutputFSO=Nothing


The input file of IP addresses are exactly the same.

The script reads data from WMI, and registry key values.

When I run it on our computer Domain, it outputs one set of data. When I run it on a computer connected to a WORKGROUP, it outputs one set of data.

Why does this happen? How can I get the script to output consistent data, regardless of which Domain/WORKGROUP I am logged into.

For instance, the computer name of the IP address differs, and so does the free disk space on C:, etc, etc.



HELP!!!
 
I would start with removing the "On Error Resume Next" and see if you are getting errors. May be a permissions issue.
 
The reason I included "On Error Resume Next" was because, when some computers were unreachable, (due to permissions issues), the script would terminate.....
 
You have three options when it comes to runtime errors. The default is, the script stops at the first runtime error. The second is, use "On Error Resume Next" which suppresses all runtime errors, and in your case, continues executing code on a computer it could not connect to, giving unexpected results.

The third (much better) option is, on lines of code that could cause a runtime error:
1) disable runtime errors (On Error Resume Next)
2) execute the line, check for an error (If Err.Number <> 0 Then)
3) handle the error
4) turn runtime errors back on (On Error Goto 0).

For example, you can start with trapping the first attempt to connect to the computer:
Code:
Dim bErrorFound 
For Each strLine in arrLines
   [COLOR=green]' code ....[/color]
   bErrorFound = False
   [COLOR=blue]On Error Resume Next[/color]
   Set oReg=GetObject( _
      "winmgmts:{impersonationLevel=impersonate}!\\" &_
      strComputer & "\root\default:StdRegProv")
   [COLOR=blue]If Err.Number <> 0 Then[/color]
      wscript.echo strComputer & " is unreachable"
      bErrorFound = True
   [COLOR=blue]End If
   On Error Goto 0[/color]
   If Not bErrorFound Then
      [COLOR=green]' remainder of the code in the loop.[/color]
   
   End If
Next


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top