Solved

Batch script failing (noob problem)

Posted on 2014-03-06
2
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

733 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