Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Shell("net use F: \\Servername\share")
End Sub


I understand there are other ways to do this but this is my question. Last time someone answered don't map a drive use UNC path and gave no example code and never answered my question. I am new to programming and this seems to be the easiest way.
Posted
Updated 13-Oct-15 7:05am
v2
Comments
phil.o 13-Oct-15 12:44pm    
You forgot to describe the problem... 'Not working' is not a valid issue description.
Member 11866893 13-Oct-15 13:09pm    
Where in my question did I say not working? I said isn't. I am asking if it will work or should work and if not what is wrong with it and how do I fix it? I tried it and when I click the button I get no errors and it doesn't map the drive.
phil.o 13-Oct-15 13:14pm    
Hum...
Your question is the title, in fact. This is the only element holding a question mark on its end.
And it says: 'Why isn't this working in Visual Basic?'

I would strongly recommend avoiding to use Basic-specific API at all, focusing on legitimate .NET FCL, where you can use, in particular, the class System.Diagnostics.Process:
https://msdn.microsoft.com/en-us/library/system.diagnostics.process%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
Comments
Maciej Los 13-Oct-15 13:07pm    
Hmmm... Seems you misunderstood OP's issue. I think Hi/She has got a problem with sharing forlders in LAN. But, can be wrong. Please, see my answer, Sergey.
Sergey Alexandrovich Kryukov 13-Oct-15 14:47pm    
Thank you for the note. You see, the inquirer did not properly formulate "not working" and still did not admit it — please see the comment to the question by phil.o.
And my advice to use pure .NET FCL is still valid and pretty useful, even if it wasn't a particular problem here (yet :-)...
Also note that the inquirer reported that my advice worked out.
—SA
Maciej Los 13-Oct-15 14:57pm    
I was wrong... Sometimes, when an issue is not well formulated, a guess what OP had meant is very random ;)
5ed!
Sergey Alexandrovich Kryukov 13-Oct-15 16:12pm    
Thank you, Maciej.
—SA
Net use command[^] connects a computer to or disconnects a computer from a shared resource, or displays information about computer connections.

In VB.NET you have to use ManagementClass class[^].

Please, see: How to share the folder using vb.net code[^]

Note: a user which runs such of programme need to have proper permissions to do that.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Oct-15 14:44pm    
5ed.
—SA
Maciej Los 13-Oct-15 14:57pm    
Thank you, Sergey.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900