Script to get file versioin info on remote systems

M

Matt Williamson

I'm working on a script to get File version info for files on remote
systems. They way I'm doing it is by creating a script that determines
what fixed drives exist and running it remotely using psexec and parsing
the return info. I'm then taking the returned drives and doing a dir /s
on the remote unc path starting with the root drive so it returns all
files on that machine on all fixed drives that match. Then, I'm parsing
the output from the DIR looking for "Directory of" to get that path and
running Filever.exe on the file found at the path. So far, I have the
following script

[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]
[4]cd /d %~dp0
[5]
[6]:: Input 1 PC or get list of ALL in domain
[7]IF "%1"=="" (
[8] set arg='NET VIEW ^^^| FIND "\\"'
[9]) ELSE (
[10] set arg="\\%1"
[11])
[12]
[13]set yfn=OrionMgr.exe
[14]
[15]For /F %%a in (%arg%) do (
[16] set pcname=%%a
[17] ping -n 1 !pcname:\\=! |find "TTL=" >nul
[18] if errorlevel 1 echo.!pcname! is offline
[19] if not errorlevel 1 (
[20] echo.!pcname!
[21] :: get drive letters of fixed drives
[22] for /f "skip=4" %%b in ('psexec !pcname! -cf Drivetype.cmd') do (
[23] set drv=%%b
[24] if "!drv:~1,1!"==" " set drv=!drv:~0,1!
[25] set yfp=!pcname!\!drv!$\%yfn%
[26] for /f "tokens=3*" %%c in ('dir /s !yfp!^|find "Directory of"')
do (set path1=%%c %%d)
[27] set path1=!path1!\%yfn%
[28] if exist "!path1!" (
[29] for /f "Tokens=2*" %%f in ('filever /v "!path1!"^>nul
2^>^&1^|find "ProductVersion"') do (echo !path1! - %%f%%g)
[30] set path1=
[31] )
[32] )
[33] )
[34])

This is the DriveType.cmd Script

[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
[4] for /f "tokens=1" %%c in ('echo/%%b %%a') do (
[5] for /f "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
[6] if "%%d"=="Fixed" (
[7] set drv=%%c&set drv=!drv:~0,1!&echo.!drv!)
[8] )
[9] )
[10])

Right now when I run the main script, It's returning the path to the
file and version number, but it's also giving me "File or Network Path
not found" as well. I think it's because when I parse the return for
Drivetype from PsExec, it's getting extra junk. I can't figure out what
command that error is comming from so I can suppress it. Any insight on
this matter would be greatly appreciated.
 
M

Matt Williamson

Matt said:
I'm working on a script to get File version info for files on remote
systems. They way I'm doing it is by creating a script that determines
what fixed drives exist and running it remotely using psexec and parsing
the return info. I'm then taking the returned drives and doing a dir /s
on the remote unc path starting with the root drive so it returns all
files on that machine on all fixed drives that match. Then, I'm parsing
the output from the DIR looking for "Directory of" to get that path and
running Filever.exe on the file found at the path. So far, I have the
following script

[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]
[4]cd /d %~dp0
[5]
[6]:: Input 1 PC or get list of ALL in domain
[7]IF "%1"=="" (
[8] set arg='NET VIEW ^^^| FIND "\\"'
[9]) ELSE (
[10] set arg="\\%1"
[11])
[12]
[13]set yfn=OrionMgr.exe
[14]
[15]For /F %%a in (%arg%) do (
[16] set pcname=%%a
[17] ping -n 1 !pcname:\\=! |find "TTL=" >nul
[18] if errorlevel 1 echo.!pcname! is offline
[19] if not errorlevel 1 (
[20] echo.!pcname!
[21] :: get drive letters of fixed drives
[22] for /f "skip=4" %%b in ('psexec !pcname! -cf Drivetype.cmd')
do (
[23] set drv=%%b
[24] if "!drv:~1,1!"==" " set drv=!drv:~0,1!
[25] set yfp=!pcname!\!drv!$\%yfn%
[26] for /f "tokens=3*" %%c in ('dir /s !yfp!^|find
"Directory of"') do (set path1=%%c %%d)
[27] set path1=!path1!\%yfn%
[28] if exist "!path1!" (
[29] for /f "Tokens=2*" %%f in ('filever /v
"!path1!"^>nul 2^>^&1^|find "ProductVersion"') do (echo !path1! - %%f%%g)
[30] set path1=
[31] )
[32] )
[33] )
[34])

This is the DriveType.cmd Script

[1]@echo off
[2]setlocal ENABLEDELAYEDEXPANSION
[3]for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
[4] for /f "tokens=1" %%c in ('echo/%%b %%a') do (
[5] for /f "tokens=3" %%d in ('fsutil fsinfo drivetype %%c') do (
[6] if "%%d"=="Fixed" (
[7] set drv=%%c&set drv=!drv:~0,1!&echo.!drv!)
[8] )
[9] )
[10])

Right now when I run the main script, It's returning the path to the
file and version number, but it's also giving me "File or Network Path
not found" as well. I think it's because when I parse the return for
Drivetype from PsExec, it's getting extra junk. I can't figure out what
command that error is comming from so I can suppress it. Any insight on
this matter would be greatly appreciated.

Sorry, this was supposed to have cross posted to the alt.msdos.batch.nt
group. I'm just getting used to NG's in Thunderbird. Fixing now
 
A

Alexander Suhovey

-----Original Message-----
From: Matt Williamson [mailto:[email protected]]
Posted At: Friday, November 10, 2006 7:54 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: Script to get file versioin info on remote systems
Subject: Script to get file versioin info on remote systems
Didn't look into the code yet, but... Sorry if this is obvious, but did
you try to comment @echo off to see what happens during script
execution?

As a side note, I'd do the whole thing with WMI/WSH instead.
 
M

Matt Williamson

Didn't look into the code yet, but... Sorry if this is obvious, but did
you try to comment @echo off to see what happens during script
execution?

Yes. I toggle back and forth between them at different times. I'm still
not seeing where the error is comming from though
As a side note, I'd do the whole thing with WMI/WSH instead.

Do you have any examples of this type of script in
vbscript\WSH\JScript\Perl or anything else that would be more efficient?
 
A

Alexander Suhovey

-----Original Message-----
From: Matt Williamson [mailto:[email protected]]
Posted At: Friday, November 10, 2006 8:06 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: Script to get file versioin info on remote systems
Subject: Re: Script to get file versioin info on remote systems

Right now when I run the main script, It's returning the path to the
file and version number, but it's also giving me "File or Network Path
not found" as well. I think it's because when I parse the return for
Drivetype from PsExec, it's getting extra junk. I can't figure out what
command that error is comming from so I can suppress it. Any insight on
this matter would be greatly appreciated.

Matt,

psexec (at least the version I'm using which is 1.72) produces a summary
at the end of the output. It looks like:

%1 exited on %2 with error code %3.

where %1 is name of command executed by psexec.

My guess is that as a result of this summary string being parced by your
script too filever gets incorrect path like
\\mypc\Drivetype.cmd$\OrionMgr.exe
 
A

Alexander Suhovey

-----Original Message-----
From: Matt Williamson [mailto:[email protected]]
Posted At: Friday, November 10, 2006 8:34 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: Script to get file versioin info on remote systems
Subject: Re: Script to get file versioin info on remote systems
As a side note, I'd do the whole thing with WMI/WSH instead.

Do you have any examples of this type of script in
vbscript\WSH\JScript\Perl or anything else that would be more
efficient?

Well, I was answering a similair question on detecting file version
remotely with WMI recently somewhere else. I'll try to find that
example.
 
M

Matt Williamson

psexec (at least the version I'm using which is 1.72) produces a summary
at the end of the output. It looks like:

%1 exited on %2 with error code %3.

where %1 is name of command executed by psexec.

My guess is that as a result of this summary string being parced by your
script too filever gets incorrect path like
\\mypc\Drivetype.cmd$\OrionMgr.exe

Yes, that is what is happening. Any ideas what I can do to suppress the
error?
 
A

Alexander Suhovey

Matt Williamson said:
Yes, that is what is happening. Any ideas what I can do to suppress the
error?

Sure, just filter out psexec output like this:
for /f "skip=4" %%b in (
'psexec !pcname! -cf Drivetype.cmd' ^| find /v /i "Drivetype.cmd"
) do (whatever)
 
A

Alexander Suhovey

Alexander Suhovey said:
-----Original Message-----
From: Matt Williamson [mailto:[email protected]]
Posted At: Friday, November 10, 2006 8:34 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: Script to get file versioin info on remote systems
Subject: Re: Script to get file versioin info on remote systems
As a side note, I'd do the whole thing with WMI/WSH instead.

Do you have any examples of this type of script in
vbscript\WSH\JScript\Perl or anything else that would be more
efficient?

Well, I was answering a similair question on detecting file version
remotely with WMI recently somewhere else. I'll try to find that
example.

OK, here you go (formatted to avoid wrapping):

'===Start===
'Remote computer name
strComputer = "remotecomputer"

'File name and extension
strFileName = "cmd"
strFileExt = "exe"

strNamespace = "winmgmts:\\"+strComputer+"\root\cimv2"
strQuery = "SELECT Name,Version FROM CIM_DataFile " &_
"WHERE FileName = '"+strFileName+"' " &_
"and Extension = '"+strFileExt+"'"

Set colFile = GetObject(strNamespace).ExecQuery(strQuery)
For Each objFile in colFile
strOut = "Computer: "+strComputer+VbCrLf+_
"Full Path: "+objFile.Name+VbCrLf+_
"Version: "+objFile.Version+VbCrLf
WScript.Echo strOut
Next
'===End===

If computer you are running script from is XP or 2003, you can use
Win32_Pingstatus class to check if remote computer is reachable first to
speed up the process. In Windows 2000 you'll have to invoke ping to do that.
http://msdn.com/library/en-us/wmisdk/wmi/win32_pingstatus.asp
http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0914.mspx
 
M

Matt Williamson

OK, here you go (formatted to avoid wrapping):
'===Start===
'Remote computer name
strComputer = "remotecomputer"

'File name and extension
strFileName = "cmd"
strFileExt = "exe"

strNamespace = "winmgmts:\\"+strComputer+"\root\cimv2"
strQuery = "SELECT Name,Version FROM CIM_DataFile " &_
"WHERE FileName = '"+strFileName+"' " &_
"and Extension = '"+strFileExt+"'"

Set colFile = GetObject(strNamespace).ExecQuery(strQuery)
For Each objFile in colFile
strOut = "Computer: "+strComputer+VbCrLf+_
"Full Path: "+objFile.Name+VbCrLf+_
"Version: "+objFile.Version+VbCrLf
WScript.Echo strOut
Next
'===End===

If computer you are running script from is XP or 2003, you can use
Win32_Pingstatus class to check if remote computer is reachable first to
speed up the process. In Windows 2000 you'll have to invoke ping to do
that.
http://msdn.com/library/en-us/wmisdk/wmi/win32_pingstatus.asp
http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0914.mspx

Excellent, this helped a lot. Here is another way using CMD script that
I came up with based upon your reply.

[1]@echo off
[2]setlocal enabledelayedexpansion
[3]
[4]:: Input 1 PC or get list of ALL in domain
[5]IF "%1"=="" (
[6] set arg='NET VIEW ^^^| FIND "\\"'
[7]) ELSE (
[8] set arg="\\%1"
[9])
[10]
[11]For /F %%a in (%arg%) do (
[12] set Comp=%%a&set Comp=!Comp:\\=!
[13] WMIC /FAILFAST:ON /NODE:"!Comp!" DATAFILE WHERE
"FileName='OrionMgr' and extension='exe'" get CSName,Name,Version
[14])
 
A

Alexander Suhovey

-----Original Message-----
From: Matt Williamson [mailto:[email protected]]
Posted At: Monday, November 13, 2006 6:01 PM
Posted To: microsoft.public.win2000.cmdprompt.admin
Conversation: Script to get file versioin info on remote systems
Subject: Re: Script to get file versioin info on remote systems

Here is another way using CMD script that
I came up with based upon your reply.

Looks nice. I should have mention WMIC. Guess I will be using your
example next time I see similar queston in cmd-centric communities <g>.

Anyway, glad to be of help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top