Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

VB help - mapping drive using variable


Recommended Posts

Posted (edited)

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

Edited by mrbios
Posted
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.
Posted (edited)

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

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

Edited by mrbios
Posted
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

Posted

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:

    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?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...