?
Solved

Batch script failing (noob problem)

Posted on 2014-03-06
2
Medium Priority
?
247 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 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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

764 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