Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

NET USE command from batch file

Posted on 2009-03-30
13
Medium Priority
?
13,068 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
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

877 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