Solved

Batch script failing (noob problem)

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

743 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

14 Experts available now in Live!

Get 1:1 Help Now