Solved

NET USE command from batch file

Posted on 2009-03-30
13
12,638 Views
Last Modified: 2012-05-06
Hello

I have a simple batch file that I need to have a user run to connect to a shared folder, the details are below:

net use S: \\SERVERNAME\SHAREFOLDER\ /user:DOMAIN\USER

when this is run, I get the following error:

System error 1326 has occurred.

Logon failure: unknown user name or bad password.

Fine, I need to specify a password in the line.  No matter where I put the password as the two examples below show:

net use S: \\SERVERNAME\SHAREFOLDER\ password /user:DOMAIN\USER
or
net use S: \\SERVERNAME\SHAREFOLDER\ /user:DOMAIN\USER password

I get the following error:

The syntax of this command is:


NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
        [/USER:[domainname\]username]
        [/USER:[dotted domain name\]username]
        [/USER:[username@dotted domain name]
        [/SMARTCARD]
        [/SAVECRED]
        [[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]

I cannot figure out why it is not accepting the password!  If I run the first example without a password in the code, after three attempts, it locks the user out so I know it is connecting to the correct user account in AD.  The user has full permissions to the share

Any help would be appreciated

Thanks!
0
Comment
Question by:TheAnvilGroup
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 24019159
Try

net use S: \\SERVERNAME\SHAREFOLDER\ /user:DOMAIN\USER *
0
 
LVL 1

Author Comment

by:TheAnvilGroup
ID: 24019191
Same error:

The syntax of this command is: etc...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24019231
Share folder happen to have a space in it?

net use s: "\\servername\share folder" /user:Domain\User *
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 67

Expert Comment

by:sirbounty
ID: 24019239
Ah, could be that trailing backslash too - my last example doesn't have one, but if the space is not the problem, then try:

net use s: \\servername\sharefolder /user:domain\user *
0
 
LVL 1

Author Comment

by:TheAnvilGroup
ID: 24019266
Sorry, yes the share folder does have a space in it, my mistake in the example
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24019285
..and the last example I posted?
0
 
LVL 1

Author Comment

by:TheAnvilGroup
ID: 24019306
Still the same error after I removed the trailing backslash
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24019337
if you run it manually, outside of a batch file, does it work?

What do you get from:

net use s: <Enter>
net use s: \\server\share <Enter>
net use s: \\server\share /user:user@domain * <enter>
0
 
LVL 1

Author Comment

by:TheAnvilGroup
ID: 24019395
net use s: <Enter>
The network connection could not be found.

More help is available by typing NET HELPMSG 2250.

--------

net use s: \\server\share <Enter>

System error 1326 has occurred.

Logon failure: unknown user name or bad password.

--------

net use s: \\server\share /user:user@domain * <enter>

The syntax of this command is: etc...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24019439
Hmm - almost like it either has already tried with alternate credentials or is attempting to use pass-thru authentication.

As an example, if the server you were trying to connect to was ABC.Corp.com (\\ABC\TheShare), what do you get when trying this similarly on your system:

net use \\ABC\Ipc$ /delete <Enter>
(in case there's a leftover rpc connection).

Or, if you have no need for any mapped connections, clear them all using:
net use * /delete <enter>

to eliminate a conflict causing this problem.
Rebooting afterwards may also help...
0
 
LVL 31

Expert Comment

by:Paranormastic
ID: 24020331
Just in case it applies: if there is a & in the password it will get parsed out when run as a script...  If there is a space in the password you probably need to enclose it in quotes, but you might just want to make them change it.  Using the * should get rid of that though, as it would be prompting the user for input - but in a script if there is more data afterwards this might be submitted as a password...

run 'net use' and see if the path shows up as already mapped somewhere.

You can use just the username, the domain\username (make sure is NT domain name), or UPN user@sub.domain.local  ... check ADUC on the accounts tab to make sure you have the correct syntax.  technically the username could be different for nt domain vs. UPN, although this is rare.  Just a bare username is fine if the server is on the same domain as your locally logged in account - if different domains (e.g. on a test domain or subdomain) then you should submit the domain name.

Hopefully you are not putting in /user:domain\user password:pa$$w0rdEx@mple

what OS is this on?

syntax should be - with correct spacing and slash directions:
net use z: \\serverhostname\sharename /user:domain\username *

the * should be substituted with the password, but for manual entry into cmd is fine for testing.
0
 
LVL 6

Accepted Solution

by:
Justin_W_Chandler earned 500 total points
ID: 24030542
FIRST, if it's giving the error "Logon failure..." it means that you have attempted the connection with alternate credentials. Type NET USE by itself and see if the server shows up in the list. If so, then use NET USE /D to remove it.

SECOND, you CAN issue a password through a script that has reserved characters but it takes some tricks to do so. A password with % in it, for example, will require you to put %% instead. Another way to accomplish this is by using this simple workaround:

1. Place the password in another text file (pass.txt for example)
2. set an environment variable equal to the file's contents
   a) set /p var_thePassword=<pass.txt
3. issue the command NET USE \\SERVER\SHARE /USER:USERNAME %var_thePassword%

Good luck!
Justin Chandler
0
 
LVL 6

Expert Comment

by:Justin_W_Chandler
ID: 24108979
Any news?
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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

778 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