public static void SearchVM(ref List <VirtualMachine> VMList) { /* * type=0 VMware Workstation * type=1 VMware Player */ int type = 0; for (type = 0; type < 2; type++) { string ConfigDir, ConfigFile, name; VMXFile config; List <string> values; ConfigDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VMware"); if (type == 0) { ConfigFile = Path.Combine(ConfigDir, "inventory.vmls"); name = "index\\d+.id"; } else { ConfigFile = Path.Combine(ConfigDir, "preferences.ini"); name = "pref.mruVM\\d+.filename"; } if (File.Exists(ConfigFile) == false) { continue; } config = new VMXFile(ConfigFile); values = config.ReadValues(name); foreach (string path in values) { bool AlreadyExist = false; foreach (VirtualMachine vm in VMList) { if (vm.Path == path) { AlreadyExist = true; break; } } if (AlreadyExist || !File.Exists(path)) { continue; } var VMX = new VMwareVM(path); VMList.Add(VMX); } } }
//按照文件后缀判断格式并打开 private void DetectAndOpen(string file) { VirtualMachine VM = null; switch (Path.GetExtension(file)) { case ".vmx": VM = new VMwareVM(file); break; case ".vbox": VM = new VBoxVM(file); break; case ".vmc": VM = new VirtualPC_VM(file); break; } if (VM != null) { OpenVM(VM); } }