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).

Script:
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.8.1.0.255.3
Echo ScriptLogic(R) %SLver% PFC initializing...
if "%PROCESSOR_ARCHITECTURE%"=="" goto 9x

:NT
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
*********%SYSTEMDRIVE%
*********%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

:NTstart
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

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

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

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

*********:9xEnd
*********cd %windir%
*********goto end

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

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

: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


:endTS

:NTLM Authentication for WDS COnnector
kis WDSConnector

: Proxy Server Settings
kis ProxySettings

: Proxy Server Exceptions
kis ProxyExceptions

@cls
@exit

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
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

VER | FINDSTR /IL "5.0" > NUL
IF %ERRORLEVEL% EQU 0 SET Version=2000

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

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

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

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

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

:winxp32

:winxp64

:win732

:win764

Open in new window

Avatar of ryan_johnston

ASKER

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.