开发者

C# Verbatim doesn't seem to work with .startinfo.arguments?

I have an app with which i can select from multiple MSI's (same msi, different versions) in a directory, and i will be able to install or uninstall from this app.

I pull in the list of MSI's, complete with full path, with

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

From here i populate a listview, and once one is selected i hit the install button. But when i go through my installing code, the verbatim seems to screw up.

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

Even though the listview shows the file with single / the end result always comes out with double /

Somewhere in there its losing the literal string.

If i change the code up and run .FileName = @"msiexec.exe /i C:\test\test1.msi" it works just f开发者_JS百科ine, but i need to be able to select from a list of filenames.

Any ideas?


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

use above MSIFiles array of file names to populate the listview

Use Path.combine as below

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(); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜