Hi,
I need to poll a number of machines on the network to determine if the
remote machine has any "set" files.
These are plain text files that are used by MS Dynamics GP, as an ini file
(structure is a little different though).
I want to read the contents of the file and put it into a database so that I
standardize or customize the GP environment for various users.
I ping the remote machine before I query it using WMI. Some machines
respond, but I am not able to connect to others.
I am logged in as the DomainAdmin, all target machines are part of this
domain.
I will post my entire code if needed. Meanwhile, the relevant snippet is
pasted below.
Thanks in advance for your help.
Regards
Habib
----------------------------------------------------
'**** check if computer is alive ****
Set objshell = CreateObject("WScript.Shell")
Set objScriptExec = objshell.Exec("ping -n 2 -w 1000 " & strComputer)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
'**** if alive, connect to it ****
If InStr(strPingResults, "reply from") Then
Set objWMIService =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer &
"\root\cimv2")
'----------Here is the problem: some machines respond, others reply
with err 429 - unable to contact remote server
'**** get a list of .SET files ****'
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile
where Extension= 'set'")
If colFiles.Count > 0 Then ' Yes, files found
For Each objFile In colFiles
FileID = FileID + 1 ' increment file counter
strPath = Left(objFile.Name, InStrRev(objFile.Name, "\") -
1) ' get the path of the file
strFile = Mid(objFile.Name, InStrRev(objFile.Name, "\") + 1,
Len(objFile.Name)) ' and just the filename
'create a temporary share on the remote machine with the
path of the file
Set objNewShare = objWMIService.Get("Win32_Share")
intResponse = objNewShare.Create(strPath, "SetFile",
FILE_SHARE, MAXIMUM_CONNECTIONS, "Temp share to grab set file.")
strRemFile = "\\" & strComputer & "\SetFile\" & strFile
'build the unc filename
Set objSetFile = objFSO.opentextfile(strRemFile, ForReading,
False) 'open file
arrFileData = Split(objSetFile.ReadAll, vbCrLf) 'read file