Solved

NET USE command from batch file

Posted on 2009-03-30
13
12,854 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
[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
  • 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
Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

617 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