Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Read remote file

7 views
Skip to first unread message

NickB

unread,
Nov 23, 2009, 6:21:01 PM11/23/09
to
I ahve searched for a solution for sdays...no luck.
I have a script that goes to remote machines and using WMI gets the domain
name and PC name and IP address. Now I want it to get a certain file on the
remote machine and open it for reading and get some inforamtion from it.

Set fileItems = objSWbemServices.ExecQuery("Select * FROM CIM_DataFile
WHERE Drive = 'C:' AND Path = '\\the path\\xxx\\xxxx\\' AND Extension =
'INI'")
If Err.number <> 0 Then
wscript.echo "Problem with DataFile set"
End If

for each objItem in fileItems
'Get version
strFileName = "the File I want"
If objItem.FileName = strFileName Then
strFileName = "C:\\path\xxxx\xxxx\" &strFileName &".ini"
wscript.echo "File Name to be opened : " &strFileName
Set objTextFile = objFSO.OpenTextFile(strFileName, ForReading)
If Err.number <> 0 Then
wscript.echo "Problem opening the file"
End If
Do Until ObjTextFile.AtEndOfStream
strNextLine = objTextFile.ReadLine
intLineFinder = InStr(strNextLine, "Installed Version=")
If intLineFinder <> 0 Then
strVersion = Mid(strNextLine, 19, 10)
objExcel.Cells(intRow,7).Value= strVersion
End If
Loop
End If

This lists all the files on the remote machine if I want it to, but will not
open the file. Is this at all possible?

Thomas Moeller Nexoe

unread,
Jan 11, 2010, 4:07:04 AM1/11/10
to
On 24-11-2009 00:21, NickB wrote:
> I ahve searched for a solution for sdays...no luck.
> I have a script that goes to remote machines and using WMI gets the domain
> name and PC name and IP address. Now I want it to get a certain file on the
> remote machine and open it for reading and get some inforamtion from it.
>
> Set fileItems = objSWbemServices.ExecQuery("Select * FROM CIM_DataFile
> WHERE Drive = 'C:' AND Path = '\\the path\\xxx\\xxxx\\' AND Extension =
> 'INI'")
> If Err.number<> 0 Then
> wscript.echo "Problem with DataFile set"
> End If
>
> for each objItem in fileItems
> 'Get version
> strFileName = "the File I want"
> If objItem.FileName = strFileName Then
> strFileName = "C:\\path\xxxx\xxxx\"&strFileName&".ini"

> wscript.echo "File Name to be opened : "&strFileName
> Set objTextFile = objFSO.OpenTextFile(strFileName, ForReading)
> If Err.number<> 0 Then
> wscript.echo "Problem opening the file"
> End If
> Do Until ObjTextFile.AtEndOfStream
> strNextLine = objTextFile.ReadLine
> intLineFinder = InStr(strNextLine, "Installed Version=")
> If intLineFinder<> 0 Then
> strVersion = Mid(strNextLine, 19, 10)
> objExcel.Cells(intRow,7).Value= strVersion
> End If
> Loop
> End If
>
> This lists all the files on the remote machine if I want it to, but will not
> open the file. Is this at all possible?

If you can list the files on the remote machine - and provided the
remote user who executes the files has read and execute file permissions
on the remote host - you should in fact be able to open and read the
file content.

--
Best regards,

Thomas Moeller Nexoe
--------------------------------------
Website: http://www.winfrastructure.dk
Blog: http://www.winfrastructure.net

0 new messages