[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Batch script failing (noob problem)

Posted on 2014-03-06
2
Medium Priority
?
250 Views
Last Modified: 2014-03-06
Please tell me where this is going wrong.

SET /P new=Is this computer using an OEM license (Y or N)?
IF new=Y (
	GOTO Key_Request
	)
	ELSE GOTO NONOEM

:Key_Request
	ECHO[
	SET /P key=Please enter the key for Windows 7 with the dashes:
	ECHO[
	ECHO %key%
	SET /P answer=Is this key correct (Y or N)?
	ECHO[
	If %answer%=Y (
		%SystemDirectory%\slmgr.vbs /ipk %key%
		%SystemDirectory%\slmgr.vbs /ato
		END
		)
		ELSE (
			ECHO The wrong key was entered. Please enter the correct key.
			GOTO Key_Request
			)
:NONOEM
	c:\windows\system32\slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
	c:\windows\system32\slmgr.vbs /ato

Open in new window

0
Comment
Question by:Jeremy Tyre
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 39909198
Comparisons in batch are done with "==", not with "=", you should use case independent comparison, and in batch, you can't just distribute the lines as you feel like in if/else clauses. Try it like this; the slmgr.vbs commands will currently only echo to the screen, so that you can test it (remove the four uppercase ECHO to run it for real):
@echo off
setlocal
SET /P new=Is this computer using an OEM license ^(Y or N^)?
IF /i "%new%"=="Y" (
	GOTO Key_Request
) ELSE (
	GOTO NONOEM
)

:Key_Request
	echo.
	set Key=
	SET /P Key=Please enter the key for Windows 7 with the dashes:
	echo.
	echo %key%
	SET /P answer=Is this key correct ^(Y or N^)?
	echo.
	If /i "%answer%"=="Y" (
		ECHO %SystemDirectory%\slmgr.vbs /ipk %key%
		ECHO %SystemDirectory%\slmgr.vbs /ato
	) ELSE (
		echo The wrong key was entered. Please enter the correct key.
		GOTO Key_Request
	)
	goto DONE
:NONOEM
	ECHO c:\windows\system32\slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
	ECHO c:\windows\system32\slmgr.vbs /ato
:DONE

Open in new window

0
 
LVL 3

Author Closing Comment

by:Jeremy Tyre
ID: 39909471
Thank you very much.  It works perfectly!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 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