Announcement

Collapse
No announcement yet.

Script to display file ver.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to display file ver.

    Need to "parse" 350+ workstations and 45 servers for a file with a specific date.

    Need to output file with computer name and file version/date info.

    This script gets the file ver on the local pc and writes it to a file on the local pc c:\version.txt

    Dim fso, ts, fname, v
    Set fso = CreateObject("Scripting.FileSystemObject")
    set ts = fso.CreateTextFile("C:\version.txt", 1)
    on error resume next
    v = fso.GetFileVersion("file name")
    fname = fso.GetFilename("file name")
    ts.writeline fname & " " & v
    ts.close
    set ts = nothing

    Would like to run this against Domain (can use login Via GP)
    but would like it to return


    -batch file example

    echo %COMPUTERNAME% >>X:\%computername%.txt

    -VBS example

    Set wshShell = WScript.CreateObject( "WScript.Shell" )
    strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
    WScript.Echo "Computer Name: " & strComputerName




    where computername is the name of the .txt file that it creates--with the file version

    Thanks in advance
    Last edited by jdeguerre; 24th February 2009, 18:56. Reason: More info

  • #2
    Re: Script to display file ver.

    Originally posted by jmasat View Post
    Would like to run this against Domain (can use login Via GP)
    I find your question hard to understand, but I think you'd like to run the script for several computers with single a command, no?

    Would a logon script do? Just add the reporting part to the script and wait for users to log on to the systems.

    Another way would be based on a list of computers and a loop. In vbscript:
    Code:
    option explicit
    
    dim computers(3), computer
    Const OpenFileForAppending = 8 
    
    computers(0) = "server01"
    computers(1) = "server02"
    computers(2) = "workstation01"
    computers(3) = "workstation02"
    
    const targetFile = "\somedir\myFileToCheck.ext"
    
    for each computer in computers
      call checkFileVer(computer, "\\" & computer & "\c$" & targetFile)
    next
    
    function checkFileVer(comp, file)
      Dim fso, ts
      Set fso = CreateObject("Scripting.FileSystemObject")
      set ts = fso.CreateTextFile("c:\fileVersions\" & comp & ".txt", OpenFileForAppending)
      ts.writeline file & " " & fso.GetFileVersion(file)
      ts.close
      set ts = nothing
    end function
    So the idea is that you put all the computer names into an array or whatnot and run the version check command against each computer by accessing the file via c$ admin share.

    -vP

    Comment


    • #3
      Re: Script to display file ver.

      Sorry- if not clear-

      Would even prefer to run with remote tool (psexec or the like)

      psexec @list.txt -c filever.vbs

      The filever.vbs would be responsible for getting the results
      Dim fso, ts, fname, v
      Set fso = CreateObject("Scripting.FileSystemObject")
      set ts = fso.CreateTextFile("C:\version.txt", 1)
      on error resume next
      v = fso.GetFileVersion("file name")
      fname = fso.GetFilename("file name")

      and then writing the results back to a file location

      ts.writeline fname & " " & v

      Ex. z:\%computername%.txt

      so each of the 350 computers and each of the 40 servers would have their own results file

      Comment


      • #4
        What is the syntax to create the txt file with wildcard

        Please let me explain- I was asking too much--

        What I need to do is have a script that will create the .txt file named the computer name (think wildcard %computername%) so that the ts.writeline fname & " " & v writes the results to that file.

        Dim newFIle
        Dim FSO
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set newFile = FSO.CreateTextFile("%computername%",true,false)


        above Obviously does not work



        the rest of the script works perfect--




        Dim fso, ts, fname, v
        Set fso = CreateObject("Scripting.FileSystemObject")
        set ts = fso.CreateTextFile("C:\version.txt", 1)
        on error resume next
        v = fso.GetFileVersion("file name")
        fname = fso.GetFilename("file name")
        ts.writeline fname & " " & v
        ts.close
        set ts = nothing
        Last edited by jdeguerre; 27th February 2009, 01:39. Reason: new info

        Comment


        • #5
          Re: What is the syntax to create the txt file with wildcard

          Originally posted by jmasat View Post

          Set newFile = FSO.CreateTextFile("%computername%",true,false)
          Well, you can't use shell variables in VBScript directly, so no wonder it won't work. But you already answered your own question above:

          Set wshShell = WScript.CreateObject( "WScript.Shell" )
          strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
          WScript.Echo "Computer Name: " & strComputerName
          So just use that piece of code.


          If you still have problems, post the whole script that does almost all you need so it can be looked into. Just mark the problematic parts with comments.

          -vP

          Comment


          • #6
            What is the syntax to create the txt file with wildcard

            Dim fso, ts, fname, v
            Set fso = CreateObject("Scripting.FileSystemObject")
            set ts = fso.CreateTextFile("C:\version.txt", 1)
            on error resume next
            v = fso.GetFileVersion("%windir%\file")
            fname = fso.GetFilename("%windir%\file")
            ts.writeline fname & " " & v
            ts.close
            set ts = nothing

            Thanks for the answer, but I need to have the file in line 3 of the script to be created with the name of the local computer. Tried the options set below with no success.

            1- have to have the file created with local computername
            2-have to have the script write the data from lines 5 and 6 to text file created in line 3.

            Comment


            • #7
              Re: Script to display file ver.

              When the vbscript is executed on the target computer it self (by using psExec from your computer), then you can do this:
              Code:
              Dim wshShell
              Dim strComputer, windir
              Dim fso, ts
              Dim sFile, f, fver, fnme, fmod
              
              Set wshShell = WScript.CreateObject ("WScript.Shell")
              strComputer = wshShell.ExpandEnvironmentStrings ("%COMPUTERNAME%")
              windir = wshShell.ExpandEnvironmentStrings ("%WINDIR%")
              
              Set fso = CreateObject ("Scripting.FileSystemObject")
              set ts = fso.CreateTextFile ("D:\DATA\[" & strComputer & "].txt", TRUE)
              
              sFile = "winhelp.exe"
              
              On Error Resume Next
              Set f = fso.GetFile (windir & "\" & sFile)
              If err.Number = 0 Then
                fver = fso.GetFileVersion (windir & "\" & sFile)
                fnme = f.name
                fmod = f.DateLastModified
              Else
                err.Clear
                fver = "unknown"
                fnme = "file not found"
              End If
              On Error Goto 0
              
              ts.write fnme & " [" & fmod & "]" & vbTab & " version: " & fver
              ts.close : set ts = nothing
              Note, the script will be executed "runas" on the remote computer and therefore it is not able to use the currently mapped drives that might exist on that computer (just telling this in case z:\%computername%.txt would be on a share on the network).

              \Rems

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment

              Working...
              X