locked
Script to determinate OS RRS feed

  • Question

  • hello everyone!

    Let me explain my scenario:

    I want to create a batch file that detects my OS and if it is W7 install a file but it is XP gives me a warning message and not install nothing.

    I hope explain myself.

    Thanks for your time!



    • Edited by sam.xyz Tuesday, March 11, 2014 10:21 PM
    Tuesday, March 11, 2014 10:04 PM

Answers

  • You could use the ver command. On my Windows 7 machine it returns Microsoft Windows [Version 6.1.7601].
    • Proposed as answer by Peter Ziganki Wednesday, March 12, 2014 9:11 AM
    • Marked as answer by Bill_Stewart Monday, May 19, 2014 9:58 PM
    Tuesday, March 11, 2014 10:27 PM

All replies

  • You could use the ver command. On my Windows 7 machine it returns Microsoft Windows [Version 6.1.7601].
    • Proposed as answer by Peter Ziganki Wednesday, March 12, 2014 9:11 AM
    • Marked as answer by Bill_Stewart Monday, May 19, 2014 9:58 PM
    Tuesday, March 11, 2014 10:27 PM
  • If you can use an external utility, I recommend a small program I wrote called OSTest.exe:

    http://www.westmesatech.com/wast.html

    Example:


    ostest -p nt -g -v 6.0 -r workstation

    This command will return an exit code of 1 if you're running NT workstation 6.0 (i.e., Windows Vista) or newer.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, March 12, 2014 1:35 AM
  • If it should be a batch, try it with a wmic call:

    wmic os get caption, OSArchitecture | find /i /v "caption"

    Or take the VER command as Forest brook said


    Wednesday, March 12, 2014 9:09 AM
  • I think WMI provides a neater format, however to make the code more clear:

    $OSWIMI = Get-WmiObject Win32_OperatingSystem
    "Operating System: $($OSWIMI.Caption)"

    Thursday, March 13, 2014 12:17 AM
  • I think WMI provides a neater format, however to make the code more clear:

    $OSWIMI = Get-WmiObject Win32_OperatingSystem
    "Operating System: $($OSWIMI.Caption)"


    That's right, powershell is more flexible than batches - but his wish was a batch
    Thursday, March 13, 2014 7:01 AM
  • Totally missed that bit! Who uses batch?

    Kieran Jacobsen @kjacobsen http://aperturescience.su

    Thursday, March 13, 2014 10:16 AM
  • Who uses batch? Shell scripts (batch files) are still useful in some contexts. Here are two off the top of my head:

    * Down-level operating systems such as Vista (and older) that do not have PowerShell installed by default

    * Locked down-environments where PowerShell script execution is unavailable

    PowerShell is preferable is most cases but sometimes a shell script is required. It depends on the context.

    Bill


    -- Bill Stewart [Bill_Stewart]

    Thursday, March 13, 2014 2:15 PM