Samba batch.bat script

Hello exerts ,

I need to know if it is possible to write batch.bat script for my win 98clients which will recognize who is going to log in and then run the appropriate command? Something like this:

if user foo then

net use commands

elseif user bar then

net use commands


net use commands

end if

but I do not know how to pass variable with user name to this script
how to setup smb.conf to run foo.bat batch file when foo user login and if bar user login run bar.bat file and if some others clients login run batch.bat file .



LVL 10
Who is Participating?
ozcokedrinkerConnect With a Mentor Commented:
Or you could use groups, with a batch file for each group of users.

you could use the following in you smb.conf:

login script = %G.bat

where %G is the group name.
You can use command switches I think its %u for username


net use h: \\server\%u

Set up a share called netlogon then use a dos editior (it must add the carrage return line feed symbols al la windows, you can use the linux tool "todos" on the file if you cant use a dos editor.) to create the batch file then save it in netlogon.
There is then an option in smb.conf logon script = yourfile.bat

Hope that helps
LuxanaAuthor Commented:
I'm now able to map my clients home drivers with:


smb.conf :
logon home = \\lindsor\%u
read only = no
browseable = no
writable = yes
valid users = %S
read only = no
create mode = 0600
directory mode = 0700

The point is that I need for user foo when he login to win98 map his home directory and also some other samba shares. But when user bar will logon it will map just his home directory.

this setting in smb.conf accept file batch.bat and %U.bat is ignored
logon script = %U.bat
logon script = batch.bat

this setting in smb.conf accept file %U.bat and batch.bat is ignored
logon script = batch.bat
logon script = %U.bat

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Only one log on script is allowed, to my knowlege, so the last one is used

Modify the foo.bat (%U.bat) startup script to do run the net use command in windows

Make the batch file in windows, as suggested by the samba team
If you use %u.bat as the files name samba will look for a logon script with the users name in it create a batch file called logon.bat with the contents

net use h:\ \\server\drive\%u
net use z:\ \\server\share

This should be executed for each user that logs on
LuxanaAuthor Commented:
if i understand clearly

net use h:\ \\server\drive\%u   -> this will run user home directory
net use z:\ \\server\share  -> this will run some other share

and also it means that I need to create batch file for all users each ?

how about :

if %u = foo then
net use commands
elseif %u = bar then
net use commands
net use commands

LuxanaAuthor Commented:

thanks for your alternative advise :) it was the best idea I think. What I did was that I created script to help me change my users primary group and then just put  login script = %G.bat to smb.conf and created two batch.bat files with different map commands.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.