Cant Start Process with Exe and path arguments

redrooster

New member
Joined
Oct 16, 2023
Messages
1
Programming Experience
10+
Hi,

I am trying to start a VMWare instance from inside my c# application. I am using the new System.Diagnostics.Process class.

The problem I have is how to start the VM instance if cmd.exe is the executbale I want to run, and I also want to run VMrun.exe from it, and pass in some startup arguments to vmrun.

Basically I want to run this

U:\Program Files (x86)\VMware\VMware Player\vmrun.exe start I:\VMWare\Virtual Machines\Ubuntu_Embedded_Pico\Ubuntu 64-bit (2).vmx

I've tried setting the working folder to the vmrun.exe files location, and specifying vmrun.exe as the filename, and tried cmd.exe as the filename etc. But I just can not seem to get he backslashes, quotes, commands and paths all correct. Any help would be greatly appreciated.

Starting a VM Instance from C# Code:
var process = new System.Diagnostics.Process();

string args = " /K \"U:\\Program Files (x86)\\VMware\\VMware Player\\vmrun.exe\" start \"I:\\VMWare\\Virtual Machines\\Ubuntu_Embedded_Pico\\Ubuntu 64-bit (2).vmx\"";
var startInfo = new System.Diagnostics.ProcessStartInfo
{
    WorkingDirectory = @"C:\Windows\System32",
    WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
    FileName = @"C:\Windows\System32\cmd.exe",
    Arguments = args,
    UseShellExecute = true
};
process.StartInfo = startInfo;
process.Start();
break;

Any clues on how to do this ?

Thanks.
 
That args value you're passing in would be interpreted as four arguments to cmd, not two arguments where the second also contains a command and two arguments. Not sure whether you can wrap another set of quotes around the subcommand or whether you'd have to pass that in via stdin after the process is running. Something for you to test.

The thing is, that's nothing to do with C#. Basically, Process.Start mimics what you can do in a console window or via Run. Get it working there first, then write code equivalent to what you did there.
 
Why cmd.exe? vmrun.exe is already executable.
 
Why cmd.exe? vmrun.exe is already executable.

I was wondering the same thing but I figured that the "/K" created some required behaviour that didn't occur otherwise. That may not actually be the case though.
 
All the "/K" does is keep cmd.exe running after it executes the commands. No other magic like loading profiles or environment variables. Why you would want an ugly CMD window hanging around doesn't make sense unless the developer wants to see any failure messages from failing to start the executable and they don't know how to capture those errors.
 
Surely one can just start the process and redirect the stdXXX, hassle as though it is to read from them simultaneously ..?
 

Latest posts

Back
Top Bottom