What string do I use in System.Diagnostics.Process.Start()?  
Author Message
b182f117





PostPosted: Visual C# General, What string do I use in System.Diagnostics.Process.Start()? Top

I found this method -- System.Diagnostics.Process.Start -- to log into a user's computer and in my case in order to download a file.

In a command window you can say something like:
net user z:\\IPaddress\SharedFolder password /user:computerName\userName

I tried doing this using the System.Diagnostics.Process.Start but I get this error:
Error message: System.ComponentModel.Win32Exception: The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
at FTPProgramWinApp2.Form1.ListFilesOnServer(String locationOfFolder, String password, String user) in C:\AAAWorkspace\FTPProgramWinApp2\Form1.cs:line 1745

I then changed the beginning to:
C:/WINDOWS/System32/net.exe

But got the same error. What should I use in the () of System.Diagnostics.Process.Start

Let's say I want to see what files are in 123.456.78.901's computer under the folder "shared" where their username is "hello" and their computer name is "mycomp" and finally their password is "p123". My original way would have been:
net use z: \\123.456.78.901\shared p123 /user:mycomp\hello

(if this code is not in the best forum to get an answer please let me know where to put it, or if you can move it for me. thanks!)




Visual C#8  
 
 
Brendan Grant





PostPosted: Visual C# General, What string do I use in System.Diagnostics.Process.Start()? Top

From the sounds of it you are executing a line that looks like:

System.Diagnostics.Process );

Instead, try breaking it up into two parts, the program and the arguments ala:

System.Diagnostics.Process.Start("net" );

Does this work better for you

The problem you are running into is forcing Start() to try to find a program with a name like what you specified... which doesn’t exist, however the net program does exist and takes in those arguments.



 
 
b182f117





PostPosted: Visual C# General, What string do I use in System.Diagnostics.Process.Start()? Top

Splitting it up does not work. If it matters to it looks like this:

System.Diagnostics.Process.Start( + locationOfFolder + " "

+ password + + user);

Where locationOfFolder is 123.456.78.901\shared, password is p123 and user is mycomp\hello. I tried putting the command line in one long string then putting the string in ( ) and I have tried putting the command line in the ( ) but neither worked (including your idea). :(

 

EDIT: I have it this way because it is a method that needs to work based off of user's input.



 
 
James Curran





PostPosted: Visual C# General, What string do I use in System.Diagnostics.Process.Start()? Top

I think you need to use several of the suggestions here.

System.Diagnostics.Process.Start( + locationOfFolder + " "+ password + + user);



 
 
b182f117





PostPosted: Visual C# General, What string do I use in System.Diagnostics.Process.Start()? Top

Whoops, missed that comma from before. Well, I am at home and do not have the program here, but will try again on monday and post on how it goes. Thanks!