C# 获取msi文件的ProductCode

        private static string GetProductCode()
        {
            System.Type oType = System.Type.GetTypeFromProgID("WindowsInstaller.Installer");
            Installer inst = System.Activator.CreateInstance(oType) as Installer;
            Database DB = inst.OpenDatabase("C:\\Users\\user\\Desktop\\Setup.msi", MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
            string str = "SELECT * FROM Property WHERE Property = 'ProductCode'";

            WindowsInstaller.View thisView = DB.OpenView(str);
            thisView.Execute();
            WindowsInstaller.Record thisRecord = thisView.Fetch();
            string result = thisRecord.get_StringData(2);

            return result;
        }
 

发表评论 / Comment

用心评论~