+ Post New Thread
Results 1 to 9 of 9
Scripts Thread, VB - Mapping extra pupil drive problems in Coding and Web Development; Hi, I am currently trying to map an extra network drive for pupils on log on. We use simple bat ...
  1. #1
    phughes's Avatar
    Join Date
    Oct 2007
    Location
    Burnley
    Posts
    77
    Thank Post
    11
    Thanked 4 Times in 2 Posts
    Rep Power
    14

    Post VB - Mapping extra pupil drive problems

    Hi,

    I am currently trying to map an extra network drive for pupils on log on.

    We use simple bat files normally and this works fine for us for now, however I am trying to use a VB as this script needs to be a little more complex.

    The script checks the first two characters of the computer name and then only allows a network drive to map for certain machines (by room number).

    I can get this to work with any admin or staff account, but not a pupil account. I believe that this is due to restrictions we have set up to 'lockdown' our network. I have tried researching adding user credentials into the script but always receive the same error message when running the code.
    "Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.."
    Following this message I have tried a bit of script to remove cached user credentials, to no avail.

    Here is my script so far... maybe a little messy, but i'm only just learning.

    PHP Code:
    set shell WScript.CreateObject"WScript.Shell" )

    computername shell.ExpandEnvironmentStrings("%COMPUTERNAME%")

    If (
    left(computername,2)) = "D2" Or (left(computername,2)) = "D3" Or 

    (
    left(computername,2)) = "D4" Or (left(computername,2)) = "D5" Then

    wscript
    .echo ("This test was a success!")

    Dim objNetworkstrRemotePath1strDriveLetter1

    strDriveLetter1 
    "T:"
    strRemotePath1 "\\Server\Share"
    On Error Resume Next
    Set objNetwork 
    CreateObject("WScript.Network"
    objNetwork.MapNetworkDrive strDriveLetter1strRemotePath1

    ElseIf  (left(computername,2)) = "SV" Then

    wscript
    .echo ("This test was a successful failure!")

    Else

    wscript.echo ("This test was a failure!")

    wscript.Quit
    End 
    if 
    I beleive this to remove cached credentials, but as I said, I couldn't get it to work.

    PHP Code:
    strServer "servername"
    strCommand "cmd /c cmdkey /delete:" strServer
    objShell
    .Run strCommand0True 
    And finally the adding user credentials section.

    PHP Code:
    Set objNetwork WScript.CreateObject("WScript.Network")
    strDriveLetter1 "L:"
    strRemotePath1 "\\server\share"
    strPer1 "FALSE"
    strUsr1 "username"
    strPas1 "password"
    objNetwork.MapNetworkDrive strDriveLetter1strRemotePath1strPer1strUsr1strPas1 
    Any help would be greatly appreciated, or even just tell me that i'm going the wrong way about achieving what I set out to.

    Thanks,
    Pete

  2. #2
    DrPerceptron's Avatar
    Join Date
    Dec 2008
    Location
    In a house
    Posts
    911
    Thank Post
    34
    Thanked 133 Times in 113 Posts
    Rep Power
    40
    Are the permissions on the share correct?

    I have a test student account which loads the default profile etc, but doesn't apply any of the lockdown settings so I can emulate a student, but also have the ability to get to areas I need - in this case, I would see if I could manually map the drive as a student.

    My VB head has floated away the last few days...

    I've always used the network object to obtain the computer name and username should I be that way inclined, but I suspect it doesn't really make any difference.

  3. #3
    phughes's Avatar
    Join Date
    Oct 2007
    Location
    Burnley
    Posts
    77
    Thank Post
    11
    Thanked 4 Times in 2 Posts
    Rep Power
    14
    I have set the NTFS permissions on the share. They are set at full control for now, and i'll lock down later.

    When trying to map to the drive manually, I get an error of this has been disable / not allowed, something like that. Which I took to mean the group policies we have do not allow students to perform this action.

    When testing without our lockdown policy enabled, the script works beautifully.

    I figured that running the script as admin would bypass this policy, but I couldn't get it to work.

    Cheers for the quick responce,
    Pete

  4. #4

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    The credentials is not to do with cached credentials, it's just that you can't have 2 connections to the same server using different usernames

    this means that you can't do:
    Code:
    net use X: \\server1\share1 /user:steve password
    net use Y: \\server1\share2 /user:fredd password
    What restrictions do you have on connecting network drives? There's nothing wrong with the idea of your script.

  5. #5
    phughes's Avatar
    Join Date
    Oct 2007
    Location
    Burnley
    Posts
    77
    Thank Post
    11
    Thanked 4 Times in 2 Posts
    Rep Power
    14
    Ah, I see. So that would never work.

    Pupils are able to map network drives when they log-on. They get 3 drives mapped normally with no problems, just using a net use bat file GP applied to the Pupil OU.

    I could map this drive to all users everywhere in school just adding to this bat file, but as I want to run this more complex VB script. I just tested this and the drive was mapped, permissions must not be a problem.

    Could I use the bat to call the VB script? or something like that?

    Any ideas?

    Cheers,
    Pete

  6. #6

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    Quote Originally Posted by phughes View Post

    Could I use the bat to call the VB script? or something like that?
    No problem; just add:

    Code:
    cscript \\server\share\mappingscript.vbs
    to your existing batch file.

    You could also do it all in a batch file if you prefer:

    Code:
    if %computername:~0,2% ==  D2 net use T: \\server\share
    if %computername:~0,2% ==  D3 net use T: \\server\share
    if %computername:~0,2% ==  D4 net use T: \\server\share
    if %computername:~0,2% ==  D5 net use T: \\server\share
    The ~ operator does string slicing; you take the variable computername and slice it, starting at position 0 and taking 2 characters

  7. Thanks to srochford from:

    phughes (20th May 2009)

  8. #7
    phughes's Avatar
    Join Date
    Oct 2007
    Location
    Burnley
    Posts
    77
    Thank Post
    11
    Thanked 4 Times in 2 Posts
    Rep Power
    14
    That's great!

    Thank you very much, i'll use the bat file.

    I was quite proud that the VB worked, even though it didn't work through pupil accounts. I'm very new to it.

    Finally, again probably very easy but, how do I get a message box on screen saying "Done" and a click ok box?

    ECHO [message] - only brings it up in cmd.
    MSGBOX - says not recognised as a command. (found it on a website somewhere)

    Thanks,
    Pete

  9. #8

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    msgbox works in vbscript - you could have 1 line vbs file saying
    Code:
    msgbox "OK"
    and then call that from your batch file. Pretty sure you can't do Windows messages from a command script without calling another program. You can do:
    Code:
    pause Done
    which will then stop and wait for you to press a key but it's not obvious if you're not looking for it.

    Good luck with it all - it does eventually become really useful and (maybe!) fun :-)

  10. #9
    phughes's Avatar
    Join Date
    Oct 2007
    Location
    Burnley
    Posts
    77
    Thank Post
    11
    Thanked 4 Times in 2 Posts
    Rep Power
    14
    Cheers :-)

SHARE:
+ Post New Thread

Similar Threads

  1. Citrix Client Drive Mapping
    By Geoff in forum Thin Client and Virtual Machines
    Replies: 15
    Last Post: 27th May 2009, 02:25 PM
  2. Mapping H Drive
    By LeonieCol in forum Wireless Networks
    Replies: 5
    Last Post: 20th May 2009, 12:35 PM
  3. CC3 - how is drive mapping actually done?
    By Nozza in forum Network and Classroom Management
    Replies: 18
    Last Post: 7th April 2009, 04:26 PM
  4. Mapping Local My Docs to H Drive
    By LeonieCol in forum Windows
    Replies: 3
    Last Post: 28th October 2008, 07:55 AM
  5. Help with drive mapping script edit
    By Andie in forum Scripts
    Replies: 2
    Last Post: 6th October 2008, 09:05 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •