Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have at the moment a logon.cmd script, that I'm using to map network drives to the users profile. It looks like this:

::Onboarding
net use m: /delete
net use m: \\BOB\onboarding 
::Bookings
net use n: /delete
net use n: \\BOB\bookings 

::Accounts
net use j: /delete
net use j: \\BOB\accounts 

It works fine up until it gets up to a folder that the current user cannot access, it then asks for a username and password instead of erroring and continuing.

Notes: This very script used to work on another Samba PDC network, but I've moved it over to another server (Still Samba PDC) and now its breaking.

Is there anyway for it to ignore the username/password prompt and just continue?

share|improve this question
    
Gotta ask - Why are you running a script to map drives that the user may not have a access to? –  John Gardeniers Oct 16 '12 at 6:24
    
Logon.cmd is the only script that can be ran during boot, and it has no way of knowing who should have access to what, so, it has to try to map everything otherwise it would get skipped –  Mattisdada Oct 16 '12 at 8:25
    
I don't use Samba, so I'm not fully familiar with it, but are you saying that all users must have the same script? Can't you set a logon script on a per-user basis? –  John Gardeniers Oct 16 '12 at 12:23
    
Unfortunately no :/, Samba is a lot more basic than your normal AD PDC, you have one script for everyone on logon. –  Mattisdada Oct 17 '12 at 2:34
1  
And this is a prime example of why it's usually not a good idea to try and replace Active Directory with something that isn't Active Directory. –  MDMarra Oct 26 '12 at 2:19

2 Answers 2

up vote 2 down vote accepted

I was never able to find a finite solution to the problem. But a usable (but very hacky and unclean) work around is using this command:

::Helpdesk
copy /Y NUL "\\BOB\helpdesk\.writable"
IF %ERRORLEVEL%==0 ( 
    del \\BOB\helpdesk\.writable
    GOTO:ALLOWEDHELPDESK
 ) 

GOTO:SECT2
:ALLOWEDHELPDESK
net use k: /delete
net use k: \\BOB\helpdesk 
:SECT2

::Onboarding
copy /Y NUL "\\BOB\onboarding\.writable" 
IF %ERRORLEVEL%==0 ( 
    del \\BOB\onboarding\.writable
    GOTO:ALLOWEDONBOARDING
 ) 

GOTO:SECT3
:ALLOWEDONBOARDING
net use m: /delete
net use m: \\BOB\onboarding 
:SECT3

::Etc,etc,etc

Basic explanation: It checks to see if a folder is writeable first by coping a blank file .writable, if it succeeds it executes the command, if it fails it skips the command and continues on.

This is purely a workaround....

share|improve this answer
    
Hey @Mattisdada, I'm adding an answer that extends yours. Maybe a community wiki would make sense here; I'm not sure. Thanks for posting question/answer. Your solution was the best fix I could find for my problem and I just hope my answer can add a little value. –  bnjmn May 30 '13 at 20:22

Extending Mattisdada's answer, this script will make it a bit easier to modify any drive mappings by simply adding, deleting or changing the mapDrive function calls. Additionally, this function checks for read access by calling DIR (instead of writing the temp file) and maps accordingly:

@ECHO off

setlocal
set SHARE=BOB
CALL:mapDrive K: helpdesk
CALL:mapDrive M: onboarding
CALL:mapDrive Z: watercooler
endlocal

net use
ECHO Mapping Complete. Thank You.
PAUSE&GOTO:EOF

:mapDrive
DIR \\%SHARE%\%~2 > nul 2>&1
IF %ERRORLEVEL%==0 ( 
    net use %~1 /DELETE > nul 2>&1
    net use %~1 \\%SHARE%\%~2
)
GOTO:eof
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.