Solved

System.Diagnostics.Process.Start

Posted on 2006-06-12
14
2,727 Views
Last Modified: 2008-01-09
I don't know if I am doing this incorrect.  I am trying to connect to a network drive using this command in VB.NET and passing a username and password.  

The network drive is already connected but after a fresh restart of the computer, it wants a password.

I am using:
System.Diagnostics.Process.Start("X:", "username", "password")

Am I doing something wrong because I keep receiving a compile error:  Overload resolution failed because no accessible 'start' accepts this number of arguments.
0
Comment
Question by:chellert
  • 8
  • 6
14 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16887865
Hi chellert;

The reason why you are getting the error is that the System.Diagnostics.Process.Start take 0, 1 or 2 parameters. So to start it with arguments the command should be

System.Diagnostics.Process.Start("X:", "username password")

But I am not sure that the username and password are going to be passed to the login screen. If the login screen does not accept parameter input it will not work.

Fernando
0
 

Author Comment

by:chellert
ID: 16888041
Is there a shell command that will allow me to login into the network drive?

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16888576
Hi chellert;

I do not know. I have did a little research and I think you may be able to do what you need using the net use command

    System.Diagnostics.Process.Start("net", "use X: \\ComputerName\ Other info from the Documentation")

Documentation for Net Use

    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/net_use.mspx?mfr=true

I hope that this helps;

Fernando
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:chellert
ID: 16987520
I am still having my original problem, where I have to start the program twice to just connect properly.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16988642
Sorry but I am not sure how else you can get around the problem
0
 

Author Comment

by:chellert
ID: 16994370
OK, I have tried this:

    Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
    Dim pw As New System.Security.SecureString
   
    For Each ch As Char In "password"
            pw.AppendChar(ch)
    Next

        myProcess.StartInfo.Arguments = "X:"
        myProcess.StartInfo.FileName = "\\toonvhcl10_vol5_server\vol5\BVTS"
        myProcess.StartInfo.UserName = "username"
        myProcess.StartInfo.Password = pw
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        myProcess.Start()

Once I hit the myProcess.Start(), I receive this message  "The Process object must have the UseShellExecute property set to false in order to start a process as a user."

What does this mean???
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16994563
Hi chellert;

Read the comment near the bottom.

        Dim myProcess As System.Diagnostics.Process = New System.Diagnostics.Process()
        Dim pw As New System.Security.SecureString

        For Each ch As Char In "password"
            pw.AppendChar(ch)
        Next

        myProcess.StartInfo.Arguments = "X:"
        'myProcess.StartInfo.FileName = "\\toonvhcl10_vol5_server\vol5\BVTS"
        myProcess.StartInfo.FileName = "notepad.exe"
        myProcess.StartInfo.UserName = "username"
        myProcess.StartInfo.Password = pw
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

        ' You need to set this to False in able to start the process as a user
        ' as defined in myProcess.StartInfo.UserName not being an empty string.
        myProcess.StartInfo.UseShellExecute = False ' <== Need to set to False

        myProcess.Start()


Fernando
0
 

Author Comment

by:chellert
ID: 16994596
Now I receive this error "The parameter is incorrect"
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16994683
Does it say which The parameter is incorrect? which line?
0
 

Author Comment

by:chellert
ID: 16994727
       myProcess.StartInfo.Arguments = "X:"
        myProcess.StartInfo.FileName = "file.txt"
        myProcess.StartInfo.UserName = "cdncmo"
        myProcess.StartInfo.WorkingDirectory = "\\toonvhcl10_vol5_server\vol5\BVTS"
        myProcess.StartInfo.Password = pw
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        myProcess.StartInfo.UseShellExecute = False
        myProcess.Start()
        myProcess.WaitForExit()

The error comes at myProcess.Start() again
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 16994996
The thing about having to have myProcess.StartInfo.UseShellExecute = False is that the variable myProcess.StartInfo.FileName needs to be a exe type file because you are not using the system shell.
So if you want to open a text file then you need to do it something like this

        myProcess.StartInfo.Arguments = "\\toonvhcl10_vol5_server\vol5\BVTS\file.txt"
        myProcess.StartInfo.FileName = "notepad.exe"
        myProcess.StartInfo.UserName = "cdncmo"
        myProcess.StartInfo.WorkingDirectory = "c:\Windows\system32"
        myProcess.StartInfo.Password = pw
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        myProcess.StartInfo.UseShellExecute = False
        myProcess.Start()
        myProcess.WaitForExit()
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16995241
I am glad that you were able to work through the problem. You have a good day. :=)
0
 

Author Comment

by:chellert
ID: 16995271
Thank you for your time and patience.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 16995348
Only glad to help.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question