Page 1 of 1

[Solved] NET USE Password Issues

Posted: 08 Jun 2011 16:24
by alleypuppy
Hello all,

I want to create a batch file to automate the process of restoring images using Imagex, but I'm running into a problem.

Normally, what we (my school) would do is type

Code: Select all

net use * \\servername.domain\drive$

and then log in using

Code: Select all

domain\administrator

and type in the password.

What I want to do is create a file that prompts for password input, and then adds that password to the command by using

Code: Select all

net use * \\servername.domain\drive$ /user:administrator %password%

However, the password does not work! Even if I go to Command Prompt and type everything in the correct way, it still does not work. I researched this issue online and couldn't find the answer I'm looking for.

Thanks for any help!

Re: NET USE Password Issues

Posted: 08 Jun 2011 18:19
by Ed Dyreen
does the password contains special chars ? like !&|

Re: NET USE Password Issues

Posted: 08 Jun 2011 18:51
by alleypuppy
Ed Dyreen wrote:does the password contains special chars ? like !&|

Just an exclamation mark.

Re: NET USE Password Issues

Posted: 08 Jun 2011 19:12
by Ed Dyreen

Are u using delayed expansion ?

Code: Select all

set "User.%%~!.Passw=something^!"

Code: Select all

>nul 2>&1    net use *    /delete /yes
>nul 2>"%%~?" net Use /Persistent:No !Drive.%ServerReferName%! "%%~!" "!User.Administrator.Passw!" /user:Administrator

Re: NET USE Password Issues

Posted: 08 Jun 2011 19:42
by alleypuppy
Ed Dyreen wrote:
Are u using delayed expansion ?

Code: Select all

set "User.%%~!.Passw=something^!"

Code: Select all

>nul 2>&1    net use *    /delete /yes
>nul 2>"%%~?" net Use /Persistent:No !Drive.%ServerReferName%! "%%~!" "!User.Administrator.Passw!" /user:Administrator

I'm not too familiar with DelayedExpansion. In the part that says

Code: Select all

set "User.%%~!.Passw=something^!"

do you want me to specify the password in place of "something"?

Re: NET USE Password Issues

Posted: 10 Jun 2011 05:45
by orange_batch
Try putting quotation marks around %password%. I would help more, but I have no time right now.

Re: NET USE Password Issues

Posted: 10 Jun 2011 20:16
by alleypuppy
I got it. Thanks for the help!