Results 1 to 3 of 3
  1. #1

    Thread Starter
    Join Date
    Nov 2008

    [Solved] Net Use with VB.Net


    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

    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
    This doesn't work, I get an error on the Process Start.

    I then found this code on MSDN but it's for C#

    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";
    I've tried to translate, but not getting anywhere ...

    Can someone please help?

    Last edited by Dave_e; Sep 17th, 2009 at 02:17 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Join Date
    Nov 2008

    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:
    1. Dim processInfo As New System.Diagnostics.ProcessStartInfo()
    3. processInfo.FileName = "C:\WINDOWS\system32\net"
    5. processInfo.Arguments = "use X: \\MYPC\Folder /USER:MYPC\TEST P@ssw0rd"
    7. 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


Click Here to Expand Forum to Full Width

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.