+ Post New Thread
Results 1 to 5 of 5
Coding Thread, VB help - mapping drive using variable in Coding and Web Development; I've made a small window in visual basic 2010 with just a textbox and a submit button What i want ...
  1. #1
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,458
    Thank Post
    349
    Thanked 256 Times in 211 Posts
    Rep Power
    98

    VB help - mapping drive using variable

    I've made a small window in visual basic 2010 with just a textbox and a submit button

    What i want to happen is: Kids enter their username in to the textbox, then click submit and it maps a drive to \\server\share\"username they entered in to text box"

    I also want it to create the folder if one doesn't already exist.

    At the moment i have a batch file doing this:
    IF EXIST Z:\*.* net use H: /Delete /y
    IF NOT EXIST \\server\share\%USERNAME% MKDIR \\server\share\%USERNAME%
    NET USE Z: \\server\share\%USERNAME%

    The reason i can't carry on using that is because im having all kinds of issues with adobe premiere elements 9 in our media room (only 10 PCs) and so im setting up a temporary fix of a local account on the machines and each kid connecting their media storage (which is different to their home folders) via this little vb program.

    At the moment i've got as far as:
    System.Diagnostics.Process.Start("Net", "Use Z: \\server\share")

    That maps Z: to the root of the share, now i just need to be able to create and map to a specific folder specified by the test box.


    Problem 2:
    At the moment the textbox is set to max characters: 9, which is the length of our usernames. How can i make it so that it has to be a minimum and maximum of 9 (or rather: fixed at 9 characters and have the submit button locked until 9 characters are entered?

    I know i can do button.enabled = false and if textbox.textlength > 8 then button.enabled = true but for some reason when i do that the submit button is enabled when i start the program, its then disabled after i have clicked it and becomes re-enabled once more than 8 characters have been entered o_O
    Last edited by mrbios; 19th October 2010 at 12:39 PM.

  2. #2

    SYNACK's Avatar
    Join Date
    Oct 2007
    Posts
    11,084
    Thank Post
    853
    Thanked 2,679 Times in 2,272 Posts
    Blog Entries
    9
    Rep Power
    769
    Why not just use My Documents redirection in group policy, as long as the student accounts have rights to create folders which from the looks of the script they do it will do all of this automagicly without intervention and also redirect the docs while its at it.

  3. #3
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,458
    Thank Post
    349
    Thanked 256 Times in 211 Posts
    Rep Power
    98
    Ah i've sorted problem 2

    Problem 1 i now have the username being taken and it maps the folder if the folder exists, if the folder doesn't exist though then it doesn't create one
    Quote Originally Posted by SYNACK View Post
    Why not just use My Documents redirection in group policy, as long as the student accounts have rights to create folders which from the looks of the script they do it will do all of this automagicly without intervention and also redirect the docs while its at it.
    Well, they'll be logging on as a local user on the PCs, and they work in groups so need to be able to access each others media folders depending on whos username it's made under. Just works out for everyone this way

    So far i have this:
    If System.IO.Directory.Exists(path:="\\fs1\media\" + username.Text) Then
    System.Diagnostics.Process.Start("Net", "Use Z: \\fs1\media\" + username.Text)
    End If

    Do i need an elseif for createdirectory or is there another more suitable method for this?


    EDIT:

    Yay i've done it, been 5 years since i last did anything in visual basic, takes me ages to get my head around it again:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
    If Directory.Exists(path:="\\fs1\media\" + username.Text) = True Then
    Process.Start("Net", "Use Z: \\fs1\media\" + username.Text)
    ElseIf Directory.Exists(path:="\\fs1\media\" + username.Text) = False Then
    Directory.CreateDirectory(path:="\\fs1\media\" + username.Text)
    Process.Start("Net", "Use Z: \\fs1\media\" + username.Text)
    End If
    End Sub

    Now the last thing i want to do is have a pop up appear to say "succes" or "failed" and if it's successful i want an ok button underneath that on click closes the program
    Last edited by mrbios; 19th October 2010 at 01:38 PM.

  4. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,723
    Thank Post
    3,248
    Thanked 1,049 Times in 971 Posts
    Rep Power
    364
    Quote Originally Posted by mrbios View Post
    Ah i've sorted problem 2

    Problem 1 i now have the username being taken and it maps the folder if the folder exists, if the folder doesn't exist though then it doesn't create one


    Well, they'll be logging on as a local user on the PCs, and they work in groups so need to be able to access each others media folders depending on whos username it's made under. Just works out for everyone this way

    So far i have this:
    If System.IO.Directory.Exists(path:="\\fs1\media\" + username.Text) Then
    System.Diagnostics.Process.Start("Net", "Use Z: \\fs1\media\" + username.Text)
    End If

    Do i need an elseif for createdirectory or is there another more suitable method for this?
    I would do it the other way around myself

    If it does not exist

    create directory with relevant username ( from the text field )
    System.Diagnostics.Process.Start("Net", "Use Z: \\fs1\media\" + username.Text)
    else
    System.Diagnostics.Process.Start("Net", "Use Z: \\fs1\media\" + username.Text)
    End If

    That way if it does not exist it creates it and maps to it in the first part - otherwise the folder must exist so its just a case of mapping to it
    That way if it does not exist it creates it

  5. #5
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,458
    Thank Post
    349
    Thanked 256 Times in 211 Posts
    Rep Power
    98
    I've now decided i want to change my program to run under a local machine account, which means i need to add a username and password in there (as either a prompt or built in, which ever is easier) This is what i have:
    Code:
        If Directory.Exists(path:="\\fs1\media\" + username.Text) = True Then
                Process.Start("Net", "Use Z: \\fs1\media\" + username.Text)
            ElseIf Directory.Exists(path:="\\fs1\media\" + username.Text = False Then
                Directory.CreateDirectory(path:="\\fs1\media\" + username.Text)
                Process.Start("Net", "Use Z: \\fs1\media\" + username.Text)
            End If
    Is there anything i can add in there to make it use a domain account for authentication to the share?

SHARE:
+ Post New Thread

Similar Threads

  1. Group Policy - Drive Mapping
    By s1mon321 in forum Wireless Networks
    Replies: 8
    Last Post: 8th September 2010, 11:54 AM
  2. Macs drive mapping
    By fil_b in forum Mac
    Replies: 19
    Last Post: 18th December 2009, 11:15 AM
  3. Drive Mapping woes
    By korifugi in forum Wireless Networks
    Replies: 1
    Last Post: 16th September 2009, 01:43 PM
  4. Mapping H Drive
    By LeonieCol in forum Wireless Networks
    Replies: 5
    Last Post: 20th May 2009, 12:35 PM
  5. 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

Thread Information

Users Browsing this Thread

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

Posting Permissions

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