-
Sep 17th, 2009, 07:12 AM
#1
Thread Starter
Member
[Solved] Net Use with VB.Net
Hi
I'm trying to map a network drive within VB.Net and not sure how close I am to achieving it
I basically want to do this (which can be done from a command prompt)
net use s: \\Volume\Directory
and tried to do it by using this code
Code:
Dim startInfo As System.Diagnostics.ProcessStartInfo
Dim pStart As New System.Diagnostics.Process
startInfo = New System.Diagnostics.ProcessStartInfo("net use s: \\Volume\Directory")
pStart.StartInfo = startInfo
pStart.Start()
This doesn't work, I get an error on the Process Start.
I then found this code on MSDN but it's for C#
Code:
System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo();
processInfo.FileName = @"C:\WINDOWS\system32\net";
processInfo.Arguments = @"use X: \\MYPC\Folder /USER:MYPC\TEST P@ssw0rd";
System.Diagnostics.Process.Start(processInfo);
I've tried to translate, but not getting anywhere ...
Can someone please help?
Thanks
Last edited by Dave_e; Sep 17th, 2009 at 02:17 PM.
-
Sep 17th, 2009, 07:27 AM
#2
Re: Net Use with VB.Net
As you can see from that C# code, you have to specify the file to execute and the commandline arguments separately. When you create your ProcessStartInfo you are passing a single string containg both, which won't work. Just look at the ProcessStartInfo class documentation and see the different ways you can do that. If you actually look at the C# code you should see it because there is very little difference between the two. Just look at each line of the C# code and ask yourself what it's doing, functionality wise, then just write code to implement that same functionality in VB. You don't have to "convert" the code. You just have to write VB code that accomplishes the same outcome.
-
Sep 17th, 2009, 08:09 AM
#3
Thread Starter
Member
Re: Net Use with VB.Net
Cheers jmcilhinney, I was looking and in the end trying some silly things.
Here's my solution for anyone else that needs to do this ...
vb Code:
Dim processInfo As New System.Diagnostics.ProcessStartInfo()
processInfo.FileName = "C:\WINDOWS\system32\net"
processInfo.Arguments = "use X: \\MYPC\Folder /USER:MYPC\TEST P@ssw0rd"
System.Diagnostics.Process.Start(processInfo)
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
|
Click Here to Expand Forum to Full Width
|