Question Locked

A Batch file to run at login

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi

am after a batch file to run when users log in to there machines. I want the batch file to map network drives and network printers. I know this will include wildcards but cant seem to write a batch file that works could anyone make some surgestions of how to write one that works? Oh and its on a mixed windows enviroment.

Thanks in Advance

6 replies

by thumbsup2

... someone to write the batch file for you? I don't think anyone here would be willing to write a script without knowing the particulars of your network.

Since I don't understand how someone can attain the position of LAN Administrator (indicated in your profile) without knowing how to write their own scripts, my advice would be to hire a consultant and admit to your supervisors that you don't know what you're doing.

by Former member

1).
Often it is asked how to create a batch frile to map network drives for users at logon. Here's how I did it at one site where I had a small number of users, but each user had a different set of mapped drives they needed to access.
Note, in this posting,??sbs1? is the name of my SBS server. Substitue your SBS server name accordingly!
Location of script: The default SBS login script is located at c:\windows\sysvol\sysvol\sbs1\scripts and the script file is SBS_LOGIN_SCRIPT.bat.
Note: a quick way to get to this directory is?to click Start > Run, and then enter \\sbs1\netlogon - and you will be right there, with no further drilling down any subdirectories!

1. First thing you want to do is to make a backup copy of the .bat file - just in case!

2. Next,?edit the contents of the default .bat file so it looks like this, and then save it.

Rem Default SBS Login Script for users
\\sbs1\netlogon\%username%.BAT

3. I then created a new .bat file for each user. The name of the .bat file explicitly matched their actual logon name. So, if you logged on as JohnDoe, then the batch file was named JohnDoe.bat
Here is the content of one such user batch file:
Rem Batch? File for user John Doe
NET USE Q: \\sbs1\Quickbooks
NET USE S: \\sbs1\SharedCompany
NET USE T: \\sbs1\Access
So, what happens is that when John Doe logs in, the default SBS script is started and immediately starts up the script file johndoe.bat, which has the various mapped drives to be declared.

4. Now, all you need to do is to create a new batch file for each user - no need to mess with the default SBS script any more. And no need to modify the name of the startup login script from within AD.
Add a new user? Simply add a new batch file!.
.......................................
2).
If you want to map to the shared drive within Windows then click on the
"connect using a different user name" link in the map network drive
window. Enter the other computer's name/administrator or
domainname/domainadmin and the password in the password box.

To do this on the command prompt or .bat file type:

net use drive letter \\computer_name\shared folder name or root folder
/user:domain name or computer name password

For a domain:
net use z: \\server1\shared$ /user:mydomain\domainadmin
4super-secret.passsword!

To map the "D" drive at the root:
net use z: \\server1\d$ /user:mydomain\domainadmin
4super-secret.passsword!

For a local computer:
net use z: \\computername\shared$ /user:administrator
4super-secret.passsword!

I don't know if you use the $ after your shared folders or not. The $
makes the folder hidden in the My Network Places / Network Neighborhood
otherwise you will be able to see all the shared folders listed for the
computer.

If you have spaces in your folder names you will need to put the remote
target location in quotes.

Please post back if you have anymore problems or questions.

by Former member

It does more than just setup new computers, you add.
It also reapplies some sbs gpo's in case they have been altered, amongst other things. It also is used by the add software Wizard should you run it.

If you are going to be adding lines to the deafult logon script, I would highly recomend adding each line as a call statement, rather than just a line. other wise if you add 2 or more lines, there is the potential for some of them to not fire off. By using call you force the focus back to the defalut logon script after excecution of your new line.
So to use Kevin's example you would add

Call \\sbs1\netlogon\%username%.BAT

So your new default logon script would read

Rem Default SBS Login Script (First Line Always)
Call \\SBS1\Clients\Setup\setup.exe /s SBS1

Rem Default SBS Login Script for users
Call \\sbs1\netlogon\%username%.BAT

Rem Default SBS Login Script for Additional Command
Call \\SBS1\netlogon\AnotherBatchFile.bat

This will ensure all the lines in your logon script get a chance to fire off.

Please post back if you have anymore problems or questions.

by batchmagicman

there is a simple way to do this that does not require any more batch programming in the file. All you have to do is go to My Computer, in the start menu, click on the local disk C, then to documents and settings, then all users, then start menu, then startup then add what you want.

by Wizard57M-TR

Hmm, I wonder if the OP is still looking? It's been almost 5 (five) years!
Leave the zombies alone.
Wizard57M
TR Moderator

This discussion is closed to new replies.