Solved

NET USE command from batch file

Posted on 2009-03-30
13
12,791 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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