Set /p Username=

August 16, 2010 at 13:58:05
Specs: Windows 7
When run my batch and prompt for to type their username, if there is a space in the username the script fails when I press enter to accept the username.

echo "Enter an Administrator Username"
set /p UserName=
set "RunAsUser=%userdomain%\%username%"
if "%USERNAME%" NEQ "%RunAsUser%" (
RUNAS /user:%RunAsUser% "cmd /c c:\regocx\regocx.bat"||PAUSE
)


Why??? it runs fine with no spaces but I need it to run with spaces in the username also.

How can I RUNas using a username with a space (i.e John Doe)?


See More: Set /p Username=

Report •


#1
August 16, 2010 at 14:17:49
SET /p username=""

That will work for you, but username is a variable already used in windows, so a strongly reccomend that you use "_username" or something along those lines.

you might end up screwing up your profile!


Report •

#2
August 16, 2010 at 14:29:06
Nope....the " " show up in my request line and it still errors out.

All I want is the user to type a username then use it to RUNas the command prompt as that user.

With a space in the username it fails.


Report •

#3
August 16, 2010 at 14:49:05
Well, I'm not really familiar with RunAs, but how about enclosing the path in quotes?

"RUNAS /user:%RunAsUser%"


Report •

Related Solutions

#4
August 17, 2010 at 06:27:51
It already is.....thanks though.

Report •

#5
August 17, 2010 at 10:03:11
No... Unless you've posted a differed code, it isn't.

----

echo "Enter an Administrator Username"
set /p UserName=
set "RunAsUser=%userdomain%\%username%"
if "%USERNAME%" NEQ "%RunAsUser%" (
RUNAS /user:%RunAsUser% "cmd /c c:\regocx\regocx.bat"||PAUSE
)

----

Enclose the bolded portion in double quotes.

I also still suggest you use "_username" instead of just "username".


Report •


Ask Question