Search code examples
c#wpfwindows-installerverbatim

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 fine, but i need to be able to select from a list of filenames.

Any ideas?


Solution

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