using System.Text.RegularExpressions;
public static void Main()
string commandLine = @"msiexec /i 'Igor Pavlov_7-Zip_24.06.msi' /qn /L*V %temp%\7-Zip\24.06\7-Zip_24.06_Install.log";
string msiPattern = @"msiexec(?:\s+[^\s]*)*\s+/i\s+['""]?([^'""]+\.msi)['""]?";
Match msiMatch = Regex.Match(commandLine, msiPattern, RegexOptions.IgnoreCase);
Console.WriteLine("Pass");
Console.WriteLine("Fail");
string logPattern = @"(?:/l[\*+!iwearucmopvx]*|/log)\s+[""']?([^\s""'<>:|?*]+\.\w{2,6})[""']?";
Match logMatch = Regex.Match(commandLine, logPattern, RegexOptions.IgnoreCase);
string logFilePath = logMatch.Groups[1].Value;
logFilePath = SanitizeLogPath(logFilePath);
Console.WriteLine(logFilePath);
private static string SanitizeLogPath(string path)
if (string.IsNullOrWhiteSpace(path))
char[] invalidChars = Path.GetInvalidFileNameChars();
string sanitizedPath = new string(path
.Where(c => !invalidChars.Contains(c))