Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

System.Diagnostics.Process.Start

Posted on 2006-06-12
14
Medium Priority
?
2,870 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 64

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 64

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
Technology Partners: 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 64

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 64

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 64

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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

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 64

Expert Comment

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

Featured Post

Independent Software Vendors: 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

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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

609 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