Solved

System.Diagnostics.Process.Start

Posted on 2006-06-12
14
2,686 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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