Solved

Batch script failing (noob problem)

Posted on 2014-03-06
2
233 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 83

Accepted Solution

by:
oBdA earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

930 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now