我有一个应用程序,可以在目录中从多个MSI(相同的MSI,不同版本)中进行选择,并且我将能够从此应用程序中安装或卸载。

我列入MSI的名单,并带有完整的路径,

string MSILocation = @"C:\test\";
string[] MSIFiles = Directory.GetFiles(MSILocation, "*.MSI", SearchOption.TopDirectoryOnly);

从这里,我填充了一个listView,一旦选择了一个,我点击了安装按钮。但是,当我浏览我的安装代码时,逐字化似乎搞砸了。

string MSIname = lboMSIList.SelectedItem.ToString();
Process p = new Process();
p.StartInfo.FileName = "MSIEXEC.EXE";
p.StartInfo.Arguments = @"/i " + MSIname;
p.Start();

即使ListView显示了单个 /最终结果的文件,但始终带有Double /

在其中的某个地方,它失去了字符串。

如果我更改代码并运行 .fileName = @“ msiexec.exe /i c: test test1.msi” 它可以正常工作,但是我需要能够从文件名列表中进行选择。

有任何想法吗?

有帮助吗?

解决方案

string MSILocation = @"C:\test\"; 
string[] MSIFiles = Directory.GetFiles(MSILocation, "*.*", SearchOption.TopDirectoryOnly).Select(f => Path.GetFileName(f)).ToArray();  

在上面使用 MSIFiles 文件名数组以填充ListView

利用 path.combine 如下

string MSILocation = @"C:\test\";
string MSIname = lboMSIList.SelectedItem.ToString();
Process p = new Process();  
p.StartInfo.FileName = "MSIEXEC.EXE"; 
p.StartInfo.Arguments = string.Format(
"{0} {1}", @"/i",Path.Combine(MSILocation , MSIname );  
p.Start(); 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top