Jump to content

can batch file be made to detect OS?


CWD

Recommended Posts

I have a batch file for a simple software installation. The only way I have found to create a desktop shortcut as part of the installation is with a nifty utility called Shortcut.exe found here for free:

http://www.optimumx.com/download/#Shortcut

Problem is, there is a different Shortcut.exe for each version of Windows, which I have downloaded and renamed them like shortcut_XP.exe, shortcut_2000.exe etc.

I am running on XP Pro and it works great with the shortcut_XP.exe, but I will need a way to direct the action to the correct version of the shortcut.exe by detecting the basic windows os being used.

I can use VER to get the os version, but then that includes some very specific version info as well in the string. I cannot find a way of parsing the string and extracting just the "XP" to use in a variable. Is something like this even possible in a batch file?

If not, any suggestions as to how to approach this differently?

Link to comment
Share on other sites


ECHO OFF
VER | FIND "XP" >NUL
IF ERRORLEVEL == 1 GOTO NOTXP
XP.exe
GOTO END
:NOTXP
VER | FIND "2000" >NUL
IF ERRORLEVEL == 1 GOTO NOT2000
2000.exe
GOTO END
:NOT2000
VER | FIND "98" >NUL
IF ERRORLEVEL == 1 GOTO NOT98
98.exe
GOTO END
:NOT98
...

:END

Probably you'll have to retype the pipes (|), since phpBB is doing something strange with them.

Edited by Mijzelf
Link to comment
Share on other sites

It's more to do with the dodgy interface at Optimum X. The drop-down list is not really a selector at all, but just a way of hiding information. All of the downloads point to the same file. You don't really need to do anything more than look for the presence of explorer.exe for this program. Windows NT 3.x does not always have this file.

Link to comment
Share on other sites

Autoit can do this very simply.

The Built in Macros:

@OSVersion Returns one of the following: "WIN_VISTA", "WIN_2003", "WIN_XP", "WIN_2000", "WIN_NT4", "WIN_ME", "WIN_98", "WIN_95"

@OSType Returns "WIN32_NT" for NT/2000/XP/2003/Vista and returns "WIN32_WINDOWS" for 95/98/Me

@OSBuild Returns the OS build number. For example, Windows 2003 Server returns 3790

@OSServicePack Service pack info in the form of "Service Pack 3" or, for Windows 95, it may return "B"

Link to comment
Share on other sites

You can create shortcuts using the built in windows tools, VBScript (.vbs) and Setup Information Files (.inf) both of which were available in different versions of Windows. The methods used to do so are available in several locations throughout these forums.

Autoit can do this very simply.

The Built in Macros:

@OSVersion Returns one of the following: "WIN_VISTA", "WIN_2003", "WIN_XP", "WIN_2000", "WIN_NT4", "WIN_ME", "WIN_98", "WIN_95"

@OSType Returns "WIN32_NT" for NT/2000/XP/2003/Vista and returns "WIN32_WINDOWS" for 95/98/Me

@OSBuild Returns the OS build number. For example, Windows 2003 Server returns 3790

@OSServicePack Service pack info in the form of "Service Pack 3" or, for Windows 95, it may return "B"

Then again, if you were going to do this you'd probably be able to ignore all that and just use FileCreateShortcut in AutoIt instead
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...