Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need help getting this batch script to work

Posted on 2009-02-09
5
Medium Priority
?
866 Views
Last Modified: 2013-11-10
hi all,

I've been fighting a batch file that uninstalls symantec anti virus and installs forefront. the fact that forefront isn't supported by windows XP SP1, it's very important that the script makes sure that the operating system is windows XP SP2 or higher before removing symantec anti virus and then installs forefront.
the scripts should abort if windows XP1 or lower is installed.

I've got the script that will do the work, but for some reason it's not working. the exact part that's not working is this:

Start Script =================================================
 
for /f "tokens=1-20" %%x in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v ProductName ^| find "ProductName"') do @set ProductName = %%x
Rem
if "ProductName" geq "Microsoft Windows XP" goto XP
exit
:XP
cls
Echo This computer is running Microsoft Windows XP
Pause
Rem
for /f "tokens=1-14" %%j in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v CSDVersion ^| find "CSDVersion"') do @set CSDVERSION = %%j
Rem
if "CSDVERSION" geq "Service Pack 2" goto SP2
exit
:SP2
cls
Echo This computer is running Microsoft Windows XP with Service Pack 2
Pause
 
End ScriptScript ==============================================
Start Script =================================================
 
for /f "tokens=1-20" %%x in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v ProductName ^| find "ProductName"') do @set ProductName = %%x
Rem
if "ProductName" geq "Microsoft Windows XP" goto XP
exit
:XP
cls
Echo This computer is running Microsoft Windows XP
Pause
Rem
for /f "tokens=1-14" %%j in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v CSDVersion ^| find "CSDVersion"') do @set CSDVERSION = %%j
Rem
if "CSDVERSION" geq "Service Pack 2" goto SP2
exit
:SP2
cls
Echo This computer is running Microsoft Windows XP with Service Pack 2
Pause
 
End ScriptScript ==============================================

Open in new window

0
Comment
Question by:Medquest
  • 3
5 Comments
 
LVL 17

Expert Comment

by:OriNetworks
ID: 23596801
Is the computer service pack 3 maybe? maybe you should check for "service pack 2" OR "service pack 3"
0
 

Author Comment

by:Medquest
ID: 23597643
checking for both service packs is fine too.
0
 
LVL 10

Accepted Solution

by:
GuruGary earned 2000 total points
ID: 23597786
I see a few issues.
1) I don't think you want to set your tokens to 1-20 in your FOR loop.  Probably 3-5 or better yet, 2*
2) Not sure why you are starting your variable with x, but you may run past z before you get what you need
3) I don't think you want spaces in your SET command
4) You need to compare to your environment variable which will be surrounded in %
5) Since there are spaces in your comparisons, you should put quotes around them
6) Comparing strings with GEQ in this case is probably not a good idea. Use EQU instead
7) As previously suggested, you should probably check for SP2 or SP3

And similar issues with ProductName and CSDVersion.

Try something like:

Start Script =================================================
 
for /f "tokens=2*" %%a in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v ProductName ^| find "ProductName"') do set ProductName=%%b
Rem
if "%ProductName%" EQU "Microsoft Windows XP" goto XP
exit
:XP
cls
Echo This computer is running Microsoft Windows XP
Pause
Rem
for /f "tokens=2*" %%a in ('reg query "hklm\software\microsoft\windows nt\currentversion" /v CSDVersion ^| find "CSDVersion"') do set CSDVERSION=%%b
Rem
if "%CSDVERSION%" EQU "Service Pack 2" goto SP2
if "%CSDVERSION%" EQU "Service Pack 3" goto SP3
exit
:SP2
cls
Echo This computer is running Microsoft Windows XP with Service Pack 2
Pause
:SP3
cls
Echo This computer is running Microsoft Windows XP with Service Pack 3
Pause
 
End ScriptScript ==============================================

Open in new window

0
 

Author Closing Comment

by:Medquest
ID: 31544838
Thanks God for smart people like you.

Thanks a lot for your help and God bless you
0
 

Author Comment

by:Medquest
ID: 23602735
GuruGary,
I have couple of questions to ask and it's really not directly related to the original questin I posted.
  1. sometimes in my batch files, I have a very long line and I am having to use word wrap to be able to see it on the same page, but this causes some problem. so my question what do I need to do to break the line in to mutiple lines and yet the system reads it as a single line?
  2. you seem to be very knowledgable with batch scripts, and I was wondering if this something you learned on your own or was there some sort of book you learned from?
Thanks again for all your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question