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 ...
-
19th October 2010, 12:32 PM #1 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.
-
-
IDG Tech News
-
19th October 2010, 12:47 PM #2 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.
-
-
19th October 2010, 12:52 PM #3 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

Originally Posted by
SYNACK
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.
-
-
19th October 2010, 01:39 PM #4 
Originally Posted by
mrbios
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
-
-
21st October 2010, 08:41 AM #5 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: 
Similar Threads
-
By s1mon321 in forum Wireless Networks
Replies: 8
Last Post: 8th September 2010, 11:54 AM
-
Replies: 19
Last Post: 18th December 2009, 11:15 AM
-
By korifugi in forum Wireless Networks
Replies: 1
Last Post: 16th September 2009, 01:43 PM
-
By LeonieCol in forum Wireless Networks
Replies: 5
Last Post: 20th May 2009, 12:35 PM
-
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
-
Forum Rules