Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file help  (Read 5864 times)

0 Members and 1 Guest are viewing this topic.

colomtnbkr

    Topic Starter


    Newbie

    Batch file help
    « on: March 11, 2010, 09:48:41 AM »
    At work we are in the middle of a laptop security update project and it takes us a while due to having to check versions of the programs that are installed. I would like to know if there is a way to create a batch file that will run and create a print out of all the selected program versions.
    We are running on Windows XP SP3.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Batch file help
    « Reply #1 on: March 11, 2010, 10:03:33 AM »
    Go into the Program Fles directory,
    Quote
    Microsoft Windows XP [Version 5.1.2600]

    E:\Program Files>dir *.exe /tw /s
    The command in purple gives the last time each EXE file was written. But it does NOT tell if that was the date of the latest update.We only think it could be.

    Perhaps somebody else has an idea.  :)

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Batch file help
    « Reply #2 on: March 11, 2010, 10:10:17 AM »
    a Batch file to list the version number of a file:
    Code: [Select]
    @echo off
    setlocal
    set vbs="%temp%\filever.vbs"
    set file=%1

    echo Set oFSO = CreateObject("Scripting.FileSystemObject") >%vbs%
    echo WScript.Echo oFSO.GetFileVersion(WScript.Arguments.Item(0)) >>%vbs%

    for /f "tokens=*" %%p in (
    'cscript.exe //Nologo %vbs% %file%') do set filever=%%p

    del %vbs%
    echo %file% : %filever%

    endlocal


    I was trying to dereference Null Pointers before it was cool.

    colomtnbkr

      Topic Starter


      Newbie

      Re: Batch file help
      « Reply #3 on: March 11, 2010, 10:16:18 AM »
      Does this print to a text file? All I get when I run it is a flicker of a CMD screen.  ???

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Batch file help
      « Reply #4 on: March 11, 2010, 12:28:57 PM »
      No. the code I provided merely echoes the version number of the filename passed on the commandline. The idea was that you would expand this... but I take it your experience with batch is limited.

      Anyway-

      two files:


      Save this is "filever.vbs"...
      Code: [Select]
      Dim cFileVersions
      Dim sFilename

      Set oFSO = CreateObject("Scripting.FileSystemObject")

      set cFileVersions = oFSO.GetFile(WScript.Arguments.Item(0))

      set fileverstream = CFileVersions.OpenAsTextStream(1,0)

      On Error resume next
      Do Until fileverstream.AtEndOfStream
      sFilename = fileverstream.readLine()

      if trim(sfilename) <> "" then
      err.clear
      WScript.Echo sfilename & ":" & chr(9) &  oFSO.GetFileVersion(sFilename)

      if err.Number <> 0 then
      WScript.Echo sfilename & ":" & chr(9) & "(File Inaccessible)"

      end if
      end if
      Loop


      save this as "filever.bat"

      Code: [Select]
      cscript /NOLOGO %~dp0\filever.vbs "%1" > versionoutput.txt&&notepad "versionoutput.txt"
      exit

      create a text file with a list of the filenames whose versions you need.

      drag the text file you created (with the list) onto the filever.bat file; after a few seconds (depending how long your list was) it should come back with a list of the files and their file versions in notepad.
      I was trying to dereference Null Pointers before it was cool.

      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: Batch file help
      « Reply #5 on: March 11, 2010, 04:45:31 PM »
      BC, you may want to enclose

      %~dp0\filever.vbs

      in quotes, or even remove %~dp0\ all together.
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Batch file help
      « Reply #6 on: March 11, 2010, 04:51:33 PM »
      in quotes, or even remove %~dp0\ all together.

      Then the batch won't work.
      I was trying to dereference Null Pointers before it was cool.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Batch file help
      « Reply #7 on: March 11, 2010, 05:18:41 PM »
      Hey BC. That was  among you best posts ever!
      I learned a lot from seeing how you do vbs, Had no idea you could do all that in a few lines of code.  ;)

      greg



        Intermediate

        Thanked: 7
        Re: Batch file help
        « Reply #8 on: March 11, 2010, 05:26:43 PM »
        Print out of all the selected program versions.
        We are running on Windows XP SP3.

        http://www.belarc.com/free_download.html


        Software Versions & Usage

          2007 Microsoft Office system Version 12.0.6502.5000
          Adobe AIR 1.5.3 Version 1.5.3
          Adobe Reader Version 9.3.0.148
          ArcSoft, Inc. - PhotoStudio Version 5.5.0.93
          Belarc, Inc. - Advisor Version 8.1k
          CA - Host Intrusion Prevention System Version 1, 5, 0, 1
          CA - Host Intrusion Prevention System Version 1.5
          CA Anti-Virus Version 10.0.0.230
          CA Security Suite Version 5.0.0.626
          CA, Inc. - CCProvSP Version 5.0.0.626
          CA, Inc. - CCUpdate Version 5.0.0.626
          CANON INC. - CNSLMAIN.EXE Version 1, 2, 0, 0
          CANON INC. - Easy Guide Viewer Version 1.0.1.0
          CANON INC. - MP Navigator EX Version 2, 0, 0, 0
          Cinematronics - 3D Pinball Version 5.1.2600.5512
          Computer Associates Antivirus Version 9.0.0.0
          Corel Corporation Limited - WordPerfect (R) Office 2000 Version 9.0.0.528
          DataSafeOnline Version 1.1.0.8998
          EIPC - Alarm Clock 4 Free Version 1.00
          Google Update Version 1.2.131.7
          Google Updater Version 2.4.1441.4352.beta
          IrfanView Uninstaller Version 1, 0, 0, 3
          IrfanView Version 4.23
          Malwarebytes' Anti-Malware Version 1.44
          Microsoft (R) Windows Script Host Version 5.7.0.18066
          Microsoft Application Error Reporting Version 12.0.6010.5000
          Microsoft Clip Organizer Version 11.0.8164
          Microsoft Corp. - Windows Live Writer Version 14.0.8050.1202
          Microsoft Corporation - Internet Explorer Version 8.00.6001.18702
          Microsoft Corporation - Office Source Engine Version 11.0.5525

            Microsoft Corporation - SelfCert Version 11.0.8164
          Microsoft Corporation - Windows Installer - Unicode Version 3.1.4001.5512

             
          Microsoft Corporation - Windows Live Call Version 14.0.8050.1202
          Microsoft Corporation - Windows Live Mail Version 14.0.8050.1202
          Microsoft Corporation - Windows LiveŽ Photo Gallery Version 14.0.8051
          Microsoft Corporation - Windows Movie Maker Version 2.1.4027.0
          Microsoft Corporation - Windows XP Video Decoder Checkup Utility Version 1.0.0.1
          Sun Microsystems, Inc. - Java(TM) Platform SE 6 U15 Version 6.0.150.3
          SupportSoft, Inc. - Dell Support Center Version 7.0.1710.0

        « Last Edit: March 11, 2010, 05:47:58 PM by greg »
        Have a Nice Day

        Salmon Trout

        • Guest
        Re: Batch file help
        « Reply #9 on: March 12, 2010, 12:26:43 AM »
        Then the batch won't work.

        You can call a vbs by name just like a batch but you need to get a couple of things right first. Just make sure the default script engine (cscript or wscript) is the one you intended. You can set the default script engine & logo / nologo behaviour so that afterwards just using the script's name with no extension is enough if the script is in the same folder or else on the PATH.


        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Batch file help
        « Reply #10 on: March 12, 2010, 07:12:23 AM »
        You can call a vbs by name just like a batch but you need to get a couple of things right first. Just make sure the default script engine (cscript or wscript) is the one you intended. You can set the default script engine & logo / nologo behaviour so that afterwards just using the script's name with no extension is enough if the script is in the same folder or else on the PATH.



        yes. that would work at the prompt.

        However, the intention was to allow for simply dragging a text file over the batch file, in which case, the current directory will probably not be the folder containing the batch. In my case, it stayed as my userprofile folder.
        I was trying to dereference Null Pointers before it was cool.