VS 2008 [Solved] Net Use with VB.Net-VBForums
Results 1 to 3 of 3

Thread: [Solved] Net Use with VB.Net

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    48

    [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.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    87,798

    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.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    48

    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()
    2.  
    3. processInfo.FileName = "C:\WINDOWS\system32\net"
    4.  
    5. processInfo.Arguments = "use X: \\MYPC\Folder /USER:MYPC\TEST P@ssw0rd"
    6.  
    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.