Solved

NET USE command from batch file

Posted on 2009-03-30
13
12,577 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
Comment Utility
Try

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

Author Comment

by:TheAnvilGroup
Comment Utility
Same error:

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

Expert Comment

by:sirbounty
Comment Utility
Share folder happen to have a space in it?

net use s: "\\servername\share folder" /user:Domain\User *
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
Sorry, yes the share folder does have a space in it, my mistake in the example
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
..and the last example I posted?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:TheAnvilGroup
Comment Utility
Still the same error after I removed the trailing backslash
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Any news?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now