Link to home
Start Free TrialLog in
Avatar of ryan_johnston
ryan_johnstonFlag for United States of America

asked on

Batch Scripting to check for OS version and go to a specific line

I have a batch file that runs as a log on script.  It is pasted below.  It has a lot of garbage in it but that's just due to it being a scriptLogic script and does it's own kind of processor detection.   My overall objective is this:  This script needs to run for all users on their desktops and terminal servers.  But, it has to run a registry edit a different way for the terminal service users due to UAC being enabled on the Terminal Servers (the CEO and COO don't want it off) and not their desktops.  

Everything in the beginning of the script needs to run but based on the OS, when it goes to :end, I need it to go to the :end or :endTS based on if they are on a server OS or desktop OS.

Desktops are either XP or 7 and terminal servers are 2008.

The :endTS is already in there and it works.  I tried duplicating all the commands it's running and just putting :NTclientTS and :NTStartTS to differentiate the two and put the OS Version commands at the top but that didn't work.

The ******* out sections are things I know the script isn't doing when it's running and I know I don't have to be concerned with it (I just did that to make it easier to read and determine what actually needs to be ran in the script.  I can comment them out when the script runs).

REM @echo off
Rem SLogic.bat -- ScriptLogic(R) Pre-Flight-Check
Rem Copyright(C) 1997-2005 ScriptLogic Corporation. All rights reserved.
REM Last replicated Tuesday, July 03, 2012 - 08:06:53
if "%WINDIR%"=="" goto end
set SLVer=Ver.DA.
Echo ScriptLogic(R) %SLver% PFC initializing...

if exist %SYSTEMDRIVE%\SLbypass.* goto NtBypass

rem // test version
if exist %SYSTEMDRIVE%\ScriptLogic\%SLver% goto NTstart

*********Rem // create folder on client if it does not exist
*********if not exist %SYSTEMDRIVE%\ScriptLogic\NUL MD %SYSTEMDRIVE%\ScriptLogic
*********if not exist %SYSTEMDRIVE%\ScriptLogic\NUL goto NTserver

*********rem // outdated version, purge client files
*********%0\..\xdel.exe /d %SYSTEMDRIVE%\ScriptLogic
*********if exist %SYSTEMDRIVE%\ScriptLogic\slstart.exe goto NTserver

*********rem // create new version stamp
*********Echo ScriptLogic client files will be updated.
*********Echo ScriptLogic %SLver% > %SYSTEMDRIVE%\ScriptLogic\%SLver%
*********if not exist %SYSTEMDRIVE%\ScriptLogic\%SLver% goto NTserver

if exist %SYSTEMDRIVE%\ScriptLogic\SLstart.exe goto NtClient
Echo Copying the ScriptLogic loader...
copy %0\..\SLstart.exe %SYSTEMDRIVE%\ScriptLogic\SLstart.exe >NUL
if exist %SYSTEMDRIVE%\ScriptLogic\SLstart.exe goto NtClient

*********Echo Launching ScriptLogic from server...
*********%0\..\SLstart.exe %1 %2 /v %SLver% /lp %0\..\ /np %0\..\
*********goto end

Echo Launching ScriptLogic from client...
%SYSTEMDRIVE%\ScriptLogic\SLstart.exe %1 %2 /v %SLver% /lp %SYSTEMDRIVE%\ScriptLogic\ /np %0\..\
goto end

*********if exist C:\SLbypass.* goto 9xBypass
*********goto 9xEnd

*********cd %windir%
*********goto end

*********if exist %SYSTEMDRIVE%\SLbypass.cmd %SYSTEMDRIVE%\SLbypass.cmd
*********if exist %SYSTEMDRIVE%\SLbypass.BAT %SYSTEMDRIVE%\SLbypass.BAT
*********goto end

*********if exist C:\SLbypass.bat c:\SLbypass.bat
*********goto end


:NTLM Authentication for WDS COnnector
regedit.exe /s \\cascade\netlogon\wds_connector.reg

: Proxy Server Settings
regedit.exe /s \\cascade\netlogon\proxy_settings.reg

: Proxy Server Exceptions
regedit.exe /s \\cascade\netlogon\Proxy_exceptions.reg


:NTLM Authentication for WDS COnnector
kis WDSConnector

: Proxy Server Settings
kis ProxySettings

: Proxy Server Exceptions
kis ProxyExceptions


Open in new window

Avatar of oBdA

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Very very true oBdA and is a good way to go
But to answer the question with a script
SET Version=Unknown

IF %ERRORLEVEL% EQU 0 SET Version=2000

VER | FINDSTR /IL "5.1." > NUL

VER | FINDSTR /IL "5.2." > NUL
IF %ERRORLEVEL% EQU 0 SET Version=2003

VER | FINDSTR /IL "6.0." > NUL

VER | FINDSTR /IL "6.1." > NUL

IF DEFINED ProgramFiles(x86) ( Set Bit=X64
) ELSE (
Set Bit=X32 )

echo Windows %Version% %Bit%

if "%Version% %Bit%"=="XP X32" goto winxp32
if "%Version% %Bit%"=="XP X64" goto winxp64
if "%Version% %Bit%"=="7 X32" goto win732
if "%Version% %Bit%"=="7 X64" goto win764
if "%Version%"=="Unknown" goto unknown





Open in new window

Avatar of ryan_johnston


oBdA, thank you!  That worked perfectly.  Makes the registry changes I needed and no UAC prompt, probably works even faster than it did before.

Also, I tried the OS version script provided but I couldn't get it to work.  It kept running both :end statements.  I more than likely didn't put the info in the right place, but it seems irrelevant now.