Solved

System.Diagnostics.Process.Start

Posted on 2006-06-12
14
2,648 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 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
Is there a shell command that will allow me to login into the network drive?

0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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
 

Author Comment

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

Expert Comment

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

Author Comment

by:chellert
Comment Utility
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 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:chellert
Comment Utility
Now I receive this error "The parameter is incorrect"
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Does it say which The parameter is incorrect? which line?
0
 

Author Comment

by:chellert
Comment Utility
       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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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 62

Expert Comment

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

Author Comment

by:chellert
Comment Utility
Thank you for your time and patience.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Only glad to help.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now