Question

Login Batch File to logon to Shared Folder

Asked by: eazy123

Hi guys I have made a batch file so that the user when loading up windows is logged on to the following mapped drives,

 the only thing is I would like him to be prompted for the user name and password for the shared folders - everytime he boots the computer,

 with this code it does prompt him because there is no password and it needs a passwords but the first thing that comes up is that the password is invalid and then you must put a password in.

@echo off
Net Use S: \\SERVER\Seb /Persistent:yes
Net Use T: \\SERVER\Db /Persistent:yes

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-05-28 at 00:52:29ID21005402
Tags

batch

,

file

,

login

,

logon

,

folder

Topic

Windows NT Networking

Participating Experts
5
Points
500
Comments
23

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. batch compare
    I would like to have a batch file during logon that compares a patch against a file. ex: -------------------- logon.bat: @echo off start patch.bat ------------------- patch.bat: @echo off setlocal set PATHTOFIXES=\\server\scripts$\qchain\patches %PATHTOFIXES%\kb822150.exe ...
  2. Batch File
    OK Guys...here's a good one, I'm a consultant that works at many places but with most of my time spent at 4 specific places My Laptop is XP Pro...latest and greatest...etc I have batch files built that I can dbl-click on and which will map drives - printers based on where...
  3. batch file will work as a logon and not as startup.
    Hi guys, I have this little batch file: @echo off regedit /s \\server\share\regfile.reg this batch file works fine as a logon script but I have to logon as administrator. I tried to make it work as a startup script instead but it didn't work. can any Expert help me out f...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: kz20flPosted on 2004-05-28 at 01:43:54ID: 11178312

If it's a Windows 2000 machine, you can prompt for user input in your login script using set /p and then pass the variables to the net use command

If it's an earlier version of Windows get the user input with a simple VBScript and them pass them to the batch file

 

by: nazirahmedPosted on 2004-05-28 at 02:52:18ID: 11178696

Hi
well...i think if the machines are part of the workgroup and they have different user names then on the server, then it should prompt them for user name and password by default on all clients. When a user tries to open a share, his/her user credentials are mathed with the ACL on the sharing server, if it matches, it gives proper rights, if it doesnt, it will prompt for user name and password.
make sure your win9x clients are setup to logon to Microsoft Network, so that they are intially prompted for a user name and password (which should be different from the server or atleast the password should be different so that the only Enter password text box appears) and when the script runs, it wil prompt user for user name and password.

 

by: oBdAPosted on 2004-05-28 at 03:38:33ID: 11178920

If you map it during every logon anyway, there's no need to use /persistent:yes; in fact, it's rather counterproductive.
To prompt for the password, simply specify a "*" instead of the password. This will try to use the resource with the current user name, though. If you're using a different account for access to the resource (but the same one for different users), you can add it at the end:

@echo off
net use S: /delete 1>NUL 2>NUL
net use T: /delete 1>NUL 2>NUL
net use /persistent:no
Net Use S: \\SERVER\Seb * /user:SomeUser
Net Use T: \\SERVER\Db * /user:SomeUser

 

by: sirbountyPosted on 2004-05-28 at 05:21:25ID: 11179524

Or, just check for the presence of the mapped drives and only act if they're not there...

If not exist S:\nul net use s: \\server\seb * /user:username
if not exist T:\nul net use t: \\server\db * /user:username

 

by: eazy123Posted on 2004-05-28 at 09:37:34ID: 11181944

your missing the point I am trying to make - or maybe I didnt explain myself clear.....I need to change my script so that the user gets prompted for a user name and password.......it then logs on to all the selected mapped drives.....I dont want to have to put a password for each drive ..... like if i use the * then it will ask me several times......

I basically need to sorta create a login screen and then the user has like all his or hers mapped drives .

 

by: nazirahmedPosted on 2004-05-28 at 14:55:08ID: 11184532

well..havnt seen this before..or atleast havnt seen someone asking for such mapping...:) just an idea..try this script. i am not expert on vb script but its just my idea..will need proper script for it..someone can help through the exact code

Pasword="password"
resp = InputBox("Enter password to run the login script:")
If resp=Password then
batch file or login script for mapping drives goes here
end

now, your users should know this password..i dont know how you are going to inform them and what users/groups will have access to which login script..or will be general login script for all who knows the password to run them. anyone to write a proper script for it???

 

by: oBdAPosted on 2004-05-29 at 05:03:29ID: 11186718

Sorry, but "I basically need to sorta create a login screen and then the user has like all his or hers mapped drives ." is far from being enough information.
What OSes are used to connect to the share? What is your general setup; a domain, a workgroup, a domain with a stand-alone server? What is the account used to logon the the server; is this one general account that all users use, or are there different accounts for every user? Are these local accounts on the server? How do people logon to their worktsations; local accounts, domain accounts? Is this a domain logon script you're running, a local logon script, something from the startup folder?

 

by: eazy123Posted on 2004-05-29 at 09:57:13ID: 11187817

Okay sorry for the vague responses, I will be very specific now....

I have a file server that basically is on the workgroup and has several shared folders....the permission for certain shared folders are setup so only certain users can access those folders, and all accounts have passwords.

I basically want a batch login script kinda like this in the startup folder.... i just dont know how to make it work....

Please enter user name for File Server
 - User enters name

Verifying User Name.........

Please enter password
 - User enters password

Verifying passwork

then I jsut need to use like net use to map the certain folders to the drives which is pretty simply

 

by: kz20flPosted on 2004-05-29 at 11:24:24ID: 11188080

You could try this:-
-------------- logonscript

call vbscript.vbs

-------------- vbscript.vbs

dim username, password

' Create WshShell object.
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

username = inputbox ("Enter username for share xxx.", "Enter username")

if username = "" then
      msgbox "User cancelled function.", 48, "Exit"
      WScript.Quit
end if

password = inputbox ("Enter password for share xxx.","Enter password")

if password = "" then
      msgbox "User cancelled function.", 48, "Exit"
      WScript.Quit
end if

Set WShShell = WScript.CreateObject("WScript.Shell")
WShShell.Run "x:\pathtologonscript.bat " & username & " " & password

-----------------------------

This will pass the user input for username and password to the logon script as %1 and %2

----------------------------- logon script

net use \\servername\sharename %2 /user:%1
net use \\servername\sharename %2 /user:%1
etc.

-------------------------------

If username and password are wrong the mapping will fail. If you want you could put some errorchecking in to loop back to the start if this happens. Is this the sort of thing you are looking for? If it is, and you need some further help putting bells and whistles on, just let me know...

 

by: kz20flPosted on 2004-05-29 at 11:30:33ID: 11188104

Or, if Windows 2000 clients, just do this batch script

@echo off
setlocal
setlocal enableextensions
set usr=
set pwd=

:start
cls
set /p usr=Enter username for share
if not defined usr goto :error1
goto :pwd

:pwd
set /p pwd=Enter password for share
if not defined pwd goto :error2
goto :map

:error1
cls
echo You have not entered a valid username
pause
goto :start

:error2
cls
echo You have not entered a valid password
pause
goto :start

:map

net use \\server\share %pwd% /user:%usr%
if not errorlevel 0 goto :error3

net use \\server\share %pwd% /user:%usr%
if not errorlevel 0 goto :error3
goto :end

:error3
cls
Echo Your username and/or password were incorrect
goto :start (if you wish to prompt again) or goto :end (if you wish to exit without mapping)

:end
cls
Echo Exiting script
set usr=
set pwd=
endlocal

 

by: eazy123Posted on 2004-05-30 at 21:15:52ID: 11194114

kz20fl - I like the batch file you just wrote the only thing when you enter incorrect password or username it does not go back to start - it basically just goes to end?

other than that it works can you suggest a fix for that?

 

by: kz20flPosted on 2004-05-31 at 03:18:28ID: 11195323

I wonder if my errorchecking is a bit off. I've just got out of bed (it's a Bank Holiday in England), let me test that for you.

 

by: kz20flPosted on 2004-05-31 at 03:24:22ID: 11195343

Change the line after the net use commands to

if errorlevel 1 goto :error3

I hope that should sort it out.

 

by: eazy123Posted on 2004-05-31 at 17:30:42ID: 11199423

still didnt do anything.....now if I have that line it just keeps going back to start and doesnt even map the second drive etc...

 

by: kz20flPosted on 2004-06-01 at 00:46:09ID: 11200857

Try just checking for the existence of the drive then:-

if not exist s: goto :error3

if not exist t: goto :error3

You'll just have to make sure that you add the /persistent:no switch onto your mapped drives in this instance

Not the best way to do things but should work

 

by: kz20flPosted on 2004-06-01 at 06:40:51ID: 11202620

I knew my errorchecking was off

The line after the net use command should read

if %errorlevel% NEQ 0 goto :error3

%errorlevel% will only be 0 if the drive mapped successfully

Hopefully that should work OK?

 

by: eazy123Posted on 2004-06-01 at 23:31:19ID: 11209771

yes it did thanks - if i have any problems I will let you know cheers
also how can I put this in the windows registry so that it only starts this script for the specified user name etc..

 

by: kz20flPosted on 2004-06-02 at 00:25:59ID: 11209963

Best idea would be to use the logon script field in User Manager - specify the logon script for the users that you wish this to run for.

The only other way to get it user-specific would be to use the Startup folder. As far as I am aware the Registry only supports HKLM\Software\Microsoft\Windows\CurrentVersion\Run which is a setting for all users.

Using the logon script field is the best idea though because it ties everything in with the domain and stores the logon script on the netlogon share on the domain controller.

 

by: eazy123Posted on 2004-06-02 at 17:04:47ID: 11217991

yeah but im not running a domain controller. - can i still do it?

 

by: kz20flPosted on 2004-06-03 at 00:49:11ID: 11219947

Yes, but it will have to be for the users on the local machine. If they are Windows NT run musrmgr.exe, if they are Windows 2000 you will have to set the properties for each user through Computer Management. Use Properties | Profile | Logon Script.

 

by: eazy123Posted on 2004-06-03 at 00:54:39ID: 11219981

yeah i did that but the login script didnt execute - I may jsut use the start up folder and wack it in there.

 

by: kz20flPosted on 2004-06-03 at 00:59:54ID: 11220003

The logon script box normally looks for a netlogon share on a domain controller - you may need to specify the full path in the absence of a DC or alternatively put the logon script into c:\winnt\system32\repl\import\scripts

 

by: ontljoshiPosted on 2008-01-25 at 14:07:46ID: 20746790

hi, i want to do the same thing but here there is different scenario....

here the PC is the local system i.e not a part of network
and i want a kind of script which automatically connects to server and its map drive upon computer startup





20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...