mbrunt Posted November 10, 2014 Posted November 10, 2014 Hi there, I'd like a batch file that opens and prompts a user for their username and password, this then will map their active directory user name. Is this possible? Thanks Martin
sted Posted November 10, 2014 Posted November 10, 2014 something like echo off rem mapdrive prompt v3 20-09-13 net use r: /delete net use u: /delete net use v: /delete set /p str=Enter Username: rem echo %str% set str2=%str:~0,1% rem echo %str2% rem echo %stra% rem decide what year group by first character if %str2%==1 goto equals1 if %str2%==2 goto equals2 if %str2%==3 goto equals3 if %str2%==4 goto equals4 if %str2%==5 goto equals5 if %str2%==6 goto equals6 if %str2%==7 goto equals7 if %str2%==8 goto equals8 if %str2%==9 goto equals9 if %str2%==0 goto equals0 rem echo not 0-9 so presumably staff net use u: \\server\users$\staff\%str% /user:%str% * net use r: \\server\resources$ net use v: \\server\users$ rem echo %mapu% goto end :equals1 net use u: \\server\users$\2011\%str% /user:%str% * net use r: \\server\resources$ goto end :equals2 net use u: \\server\users$\2012\%str% /user:%str% * net use r: \\server\resources$ goto end :equals3 net use u: \\server\users$\2013\%str% /user:%str% * net use r: \\server\resources$ goto end :equals4 net use u: \\server\users$\2014\%str% /user:%str% * net use r: \\server\resources$ goto end :equals5 net use u: \\server\users$\2015\%str% /user:%str% * net use r: \\server\resources$ goto end :equals6 net use u: \\server\users$\2006\%str% /user:%str% * net use r: \\server\resources$ goto end :equals7 net use u: \\server\users$\2007\%str% /user:%str% * net use r: \\server\resources$ goto end :equals8 net use u: \\server\users$\2008\%str% /user:%str% * net use r: \\server\resources$ goto end :equals9 net use u: \\server\users$\2009\%str% /user:%str% * net use r: \\server\resources$ goto end :equals0 net use u: \\server\users$\2010\%str% /user:%str% * net use r: \\server\resources$ goto end :end pause
hallb15 Posted November 10, 2014 Posted November 10, 2014 (edited) Yes. Something along the lines of: NET USE X: \\server\%username% I'm curious why you want to do this though? EDIT: @sted went into way more detail! Edited November 10, 2014 by hallb15
sted Posted November 10, 2014 Posted November 10, 2014 Yes. Something along the lines of: NET USE X: \\server\%username% I'm curious why you want to do this though? EDIT: @sted went into way more detail! well cut n pasted it from a script ive written for surface rt's lol
Garacesh Posted November 10, 2014 Posted November 10, 2014 (edited) @sted, you really don't need all that lark. Our usernames are formatted YYSurnameI (Where YY is a 2-number year-of-entry, Surname is obvious, and I is first initial.).. I do document access by PowerShell (Put in username, automatically explorer.exe to their home folder) but I used to do it by Batch.. Here's an adaptation of it that should work (alter as required for however your usernames are formatted) @echo off :begin echo. set /p user=Username? if %user%==exit ( goto :eof ) set year=%user:~0,2% if not exist "\\server\users$\20%year%\%user%\" ( echo User not found. Check username. echo. pause cls goto :begin ) ELSE ( net use u: \\server\users$\20%year%\%user% /user:%user% * net use r: \\server\resources$ ) Edit: I guess you'd need more if you wanted it to differentiate between staff and pupils Edited November 10, 2014 by Garacesh
sted Posted November 10, 2014 Posted November 10, 2014 @sted, you really don't need all that lark. Our usernames are formatted YYSurnameI (Where YY is a 2-number year-of-entry, Surname is obvious, and I is first initial.).. I do document access by PowerShell (Put in username, automatically explorer.exe to their home folder) but I used to do it by Batch.. Here's an adaptation of it that should work (alter as required for however your usernames are formatted) @echo off :begin echo. set /p user=Username? if %user%==exit ( goto :eof ) set year=%user:~0,2% if not exist "\\server\users$\20%year%\%user%\" ( echo User not found. Check username. echo. pause cls goto :begin ) ELSE ( net use u: \\server\users$\20%year%\%user% /user:%user% * net use r: \\server\resources$ ) Edit: I guess you'd need more if you wanted it to differentiate between staff and pupils and needed to be easily edited for different schools so yes its inelligant and longwinded but it works
Garacesh Posted November 10, 2014 Posted November 10, 2014 Eh, guess so. Just struck me as odd that you used :~0,1 at the start, but then did each character individually I guess it all depends on how @mbrunt has their usernames formatted.
mbrunt Posted November 10, 2014 Author Posted November 10, 2014 Thanks for your replies. Ok basically I've got a computer in a recording studio that does not logon to our domain but we do require students to be able to access their F drive. The usernames are formatted as 1400000 and 1300000 and 1200000 - depending on what year they started. Each year has a different location for their home drives, so 14 students are located on \\server\students\2014\username and 13 students \\server\students\2013\username. Soooooo how do I go about doing that? Thank you
Garacesh Posted November 10, 2014 Posted November 10, 2014 My code above should work perfectly fine for that if you modify the first half of the path. In short, you give it a string (For example.. 14Bloggs).. The script checks the first 2 characters and adds that to the path (20XX) and then the entire string after.. So by entering 14Bloggs you'd get \\server\students\2014\14Bloggs - Be aware there is only a miniscule amount of error checking - All it does is check that the path exists, but realistically that ought to be enough.. Question! If there's no logging on to the domain.. How are you going to authenticate? Students could use this script to grab someone else's home drive.
hallb15 Posted November 11, 2014 Posted November 11, 2014 I'd echo what @Garacesh said above. This is not a secure method. You'd have to create a script that deleted the F: drive map - or schedule a task to do it at the end of every lesson maybe? Otherwise the next time a student uses the computer in question, they may still have the previous user's F: drive still mapped. Could you create a music shared drive on the domain and map it during startup on the recording studio PC? That way, at least only the student's music work would be at risk, not their whole home area. You could also look at a cloud-based solution like dropbox or one drive.
Garacesh Posted November 12, 2014 Posted November 12, 2014 I, personally, wouldn't recommend allowing students to run batch files as a rule.. But if there's no logging on to the domain, that's not exactly enforceable (unless you apply it as a machine policy..) It might be possible to restrict access via NTFS permissions.. I think (but please double-check) that if you do not have any kind of NTFS permission set for the local account on the recording studio machine, NTFS permissions will kick in and ask for a username and password. If the user puts their normal network credentials in, it should allow them access.. Provided your permissions are set correctly on your student shares, using correct network credentials would still deny them access to the folder (pulled by the script with explorer.exe).. There's got to be a better way of doing it, though.. I think you might need to go further than a batch file.
hallb15 Posted November 12, 2014 Posted November 12, 2014 What is it on the student's F: drive that they need to access from the recording studio PC? Is there another way you could look at this?
Garacesh Posted November 12, 2014 Posted November 12, 2014 I presumed backing tracks they've previously composed in music lessons that they'll play, sing onto, and then save the compilation back to their F: drive. Easiest solution would be memory sticks, truth be told
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now