Search code examples
c#windowsvirtual-machinexp-mode

Starting a vm "Windows XP Mode" programmatically through a C# program Windows 7


Ok, so I'm having an issue starting the the Windows XP mode VM through a c# program. The command I'm using is vmwindow -file "absolute path to vmcx file" , but the problem is that the command does not work with the cmd prompt that my program kicks off. So, it's very weird. I can go to command prompt on my computer and run this command on my computer and it works, but if i have the same command on my c# program, the command prompt that pops up tells me the "vmwindow" is not a recognized command. I even looked at the paths of each of the command prompts and they're different, but they still both contain "C:\Windows\system32\" which is where vmwindow.exe exists. So, I navigate on the command prompt window that my program populated and the file "vmwindow.exe" is not there, but if I open a command prompt window from my computer and navigate to that folder, it exists there. I can't think of anything else as I already made sure they're both running in administrator mode, and also i tried starting a bat file which contained that command instead of running the command directly. Hope anyone knows anything about this. Here is the code I'm using:

private void button1_Click(object sender, EventArgs e)
    { 

        Process process = new System.Diagnostics.Process();
        ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();

        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
        startInfo.FileName = "cmd.exe";
        startInfo.WorkingDirectory = @"<my path>";
        startInfo.Arguments = "/k vmwindow.exe -file \"<path to vcmx file>\\Windows XP Mode.vmcx\"";
        process.StartInfo = startInfo;
        process.Start();
    }

Solution

  • Probably it's because of the bitness setting you compile your program with. ("Platform target" and "Prefer 32-bit" settings under the build tab of the project). 32 and 64 bit processes see different files under System32. See https://stackoverflow.com/a/950011