Solved

System.Diagnostics.Process.Start

Posted on 2006-06-12
14
2,765 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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