NET USE command in a Batch File. *SOLVED*

Cal166

Diamond Member
May 6, 2000
5,081
8
81
OK, here's my problem.

I can perfectly type this in the command line:

NET USE Y: \\SERVER\FOLDER /USER:Domain\Testaccount pass word

But when putting it in a *.bat file the and running the bat file,

The space btw the pass word does not work.

I tried the common stuff like putting it in "pass word" and used Ascii code to input the space.

Any one have an idea?

Thanks


I Solved it, apparently DOS used a similar command in SQL by using the: %%
 

mzkhadir

Diamond Member
Mar 6, 2003
9,509
1
76
Connects or disconnects your computer from a shared resource or displays information about your connections.
NET USE [drive: | *] [\\computer\directory [password | ?]]
[/SAVEPW:NO] [/YES] [/NO]
NET USE [port:] [\\computer\printer [password | ?]]
[/SAVEPW:NO] [/YES] [/NO]

NET USE drive: | \\computer\directory /DELETE [/YES]
NET USE port: | \\computer\printer /DELETE [/YES]
NET USE * /DELETE [/YES]

NET USE drive: | * /HOME



drive Specifies the drive letter you assign to a shared directory.
* Specifies the next available drive letter. If used with /DELETE, specifies to disconnect all of your connections.
port Specifies the parallel (LPT) port name you assign to a shared printer.
computer Specifies the name of the computer sharing the resource.
directory Specifies the name of the shared directory.
printer Specifies the name of the shared printer.
password Specifies the password for the shared resource, if any.
? Specifies that you want to be prompted for the password of the shared resource. You don't need to use this option unless the password is optional.
/SAVEPW:NO Specifies that the password you type should not be saved in your password-list file. You need to retype the password the next time you connect to this resource.
/YES Carries out the NET USE command without first prompting you to provide information or confirm actions.
/DELETE Breaks the specified connection to a shared
resource.
/NO Carries out the NET USE command, responding with NO automatically when you are prompted to confirm actions.
/HOME Makes a connection to your HOME directory if one is specified in your LAN Manager or Windows NT user account.

To list all of your connections, type NET USE without options.
 

Jzero

Lifer
Oct 10, 1999
18,834
1
0
Try using single quotes around the password?

I love it when people ask for help on a command and someone just posts the help file as if it magically contained the answer.
 

FoBoT

No Lifer
Apr 30, 2001
63,084
15
81
fobot.com
are you saying the password contains a space? that is dumb

you need to use quotes to deprecate the items that contain spaces
 

Cal166

Diamond Member
May 6, 2000
5,081
8
81
Yes the password for the account had a space, security purposes.

I did used quotes to replace the space. still no go
 

MixMasterTang

Diamond Member
Jul 23, 2001
3,167
176
106
Create a .txt file containing the password (since you obviously are putting it in clear text anyways if you are doing this through a batch file) and do

net use z: \\server\share /user:Domain\username <password.txt
 

conjur

No Lifer
Jun 7, 2001
58,686
3
0
Originally posted by: FoBoT
are you saying the password contains a space? that is dumb

you need to use quotes to deprecate the items that contain spaces
Hey...no need for cussing now.




;)
 

MixMasterTang

Diamond Member
Jul 23, 2001
3,167
176
106
Originally posted by: Cal166
Yes the password for the account had a space, security purposes.

I did used quotes to replace the space. still no go

What security purpose could that serve if you plan on putting it in a batch file in clear text?
 

dcaron

Junior Member
Sep 1, 2005
19
0
0
What about putting the whole line in quotes? I've had problems with batch files and paths that included spaces, and putting the whole thing in quotes solved my problem.
 

Jzero

Lifer
Oct 10, 1999
18,834
1
0
Originally posted by: Cal166
No go, as i tried the "pass word"

Yes put did you try the 'pass word' or the "net use ... pass word" or the 'net use ... pass word' or the "net use ... 'pass word'" or the 'net use ... "pass word"' ?
 

djheater

Lifer
Mar 19, 2001
14,637
2
0
Originally posted by: Cal166
OK, here's my problem.

I can perfectly type this in the command line:

NET USE Y: \\SERVER\FOLDER /USER:Domain\Testaccount pass word

But when putting it in a *.bat file the and running the bat file,

The space btw the pass word does not work.

I tried the common stuff like putting it in "pass word" and used Ascii code to input the space.

Any one have an idea?

Thanks

Try pass^ word or "pass^ word"
I've seen a carat used to make a literal, though I'd have thought simply enclosing it in quotes would resolve it.

Are you sure it's failing on the password?

 

Cal166

Diamond Member
May 6, 2000
5,081
8
81
tried all of those, still no go

when using pass^word....the result is password...
 

sao123

Lifer
May 27, 2002
12,653
205
106
Dos will not accept passwords with spaces in them.
dos strong password rules are as follows:

CAPS, small, number, Symbol (!@#$%^&*_)
 

Cal166

Diamond Member
May 6, 2000
5,081
8
81
%% placed in btw pass%%word, i was able to run the command in the batch file.
 

GeekDrew

Diamond Member
Jun 7, 2000
9,099
19
81
Originally posted by: Cal166
%% placed in btw pass%%word, i was able to run the command in the batch file.

bwhaahahahahaha

That's an ingenious idea. ;)