{"id":65,"date":"2012-11-22T03:06:00","date_gmt":"2012-11-22T01:06:00","guid":{"rendered":"http:\/\/workplace.skyworker.de\/?p=65"},"modified":"2023-08-22T10:39:23","modified_gmt":"2023-08-22T08:39:23","slug":"tool-zum-auslesen-von-msi-informationen","status":"publish","type":"post","link":"http:\/\/workplace.skyworker.de\/?p=65","title":{"rendered":"Powershell: Tool zum auslesen von MSI Informationen"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"65\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">0    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"65\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-down\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\">0<\/span>\r\n<\/div><\/div><div>\n<p style=\"text-align: justify;\">Oft schon stand ich vor dem Problem, das ich gerne die MSI-GUID, MSI-InstallerID und die Version einer neuen MSI Datei auslesen wollte, ohne gleich den Empirum Packaging Wizard zur Hand zu nehmen. Zum Beispiel bei Empirum Paketen, die aus mehreren MSI Dateien bestehen, oder nur um eine neuere Versionen einer Applikation, die \u00fcber einen MSI Installer installiert wird einbinden zu wollen.<\/p>\n<p style=\"text-align: justify;\"><!--more--><\/p>\n<\/div>\n<p style=\"text-align: justify;\">Hierf\u00fcr habe ich mir ein PowerShell Skript geschrieben, welches die relevanten Daten f\u00fcr mich direkt aus einer MSI Datei ausliest.<\/p>\n<p style=\"text-align: justify;\"><a href=\"http:\/\/workplace.skyworker.de\/wp-content\/uploads\/2013\/11\/mx42_getmsiinfo1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-79\" src=\"http:\/\/workplace.skyworker.de\/wp-content\/uploads\/2013\/11\/mx42_getmsiinfo1-300x120.jpg\" alt=\"mx42_getmsiinfo\" width=\"300\" height=\"120\" srcset=\"http:\/\/workplace.skyworker.de\/wp-content\/uploads\/2013\/11\/mx42_getmsiinfo1-300x120.jpg 300w, http:\/\/workplace.skyworker.de\/wp-content\/uploads\/2013\/11\/mx42_getmsiinfo1.jpg 600w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Das PowerShell Skript aufrufen, die MSI Datei ausw\u00e4hlen und schon werden die entsprechenden Daten angezeigt.<\/p>\n<p style=\"text-align: justify;\">Powershell Skript:\u00a0\u00a0 [ddownload id=174]<\/p>\n<blockquote><p><strong>Hinweis:<\/strong> Um das PowerShell Skript ausf\u00fchren zu k\u00f6nnen, muss die <strong>PowerShell ExecutionPolicy<\/strong> herabgesetzt werden. Hierzu ein PowerShell Fenster \u00f6ffnen und den Befehl set-executionpolicy remotesigned eingeben und mit J \u2013 Ja, oder Y \u2013 Yes best\u00e4tigen.<br \/>\nDanach kann das Skript \u00fcber die rechte Maustaste &gt; Mit PowerShell ausf\u00fchren gestartet werden.<\/p><\/blockquote>\n<p>[php]function Get-MsiVersion {<br \/>\nparam (<br \/>\n[IO.FileInfo] $FilePath<br \/>\n)<\/p>\n<p>try {<br \/>\n$windowsInstaller = New-Object -com WindowsInstaller.Installer<\/p>\n<p>$database = $windowsInstaller.GetType().InvokeMember(<br \/>\n\u201cOpenDatabase\u201d, \u201cInvokeMethod\u201d, $Null,<br \/>\n$windowsInstaller, @($FilePath.FullName, 0)<br \/>\n)<\/p>\n<p>$q = &quot;SELECT Value FROM Property WHERE Property = &#8218;ProductVersion&#8217;&quot;<br \/>\n$View = $database.GetType().InvokeMember(<br \/>\n\u201cOpenView\u201d, \u201cInvokeMethod\u201d, $Null, $database, ($q)<br \/>\n)<\/p>\n<p>$View.GetType().InvokeMember(\u201cExecute\u201d, \u201cInvokeMethod\u201d, $Null, $View, $Null)<\/p>\n<p>$record = $View.GetType().InvokeMember(<br \/>\n\u201cFetch\u201d, \u201cInvokeMethod\u201d, $Null, $View, $Null<br \/>\n)<\/p>\n<p>$global:productVersion = $record.GetType().InvokeMember(<br \/>\n\u201cStringData\u201d, \u201cGetProperty\u201d, $Null, $record, 1<br \/>\n)<\/p>\n<p>} catch {<br \/>\nthrow &quot;Failed to get MSI file version the error was: {0}.&quot; -f $_<br \/>\n}<br \/>\n}<\/p>\n<p>function Get-MsiProductCode {<br \/>\nparam (<br \/>\n[IO.FileInfo] $FilePath<br \/>\n)<\/p>\n<p>try {<br \/>\n$windowsInstaller = New-Object -com WindowsInstaller.Installer<\/p>\n<p>$database = $windowsInstaller.GetType().InvokeMember(<br \/>\n\u201cOpenDatabase\u201d, \u201cInvokeMethod\u201d, $Null,<br \/>\n$windowsInstaller, @($FilePath.FullName, 0)<br \/>\n)<\/p>\n<p>$q = &quot;SELECT Value FROM Property WHERE Property = &#8218;ProductCode&#8217;&quot;<br \/>\n$View = $database.GetType().InvokeMember(<br \/>\n\u201cOpenView\u201d, \u201cInvokeMethod\u201d, $Null, $database, ($q)<br \/>\n)<\/p>\n<p>$View.GetType().InvokeMember(\u201cExecute\u201d, \u201cInvokeMethod\u201d, $Null, $View, $Null)<\/p>\n<p>$record = $View.GetType().InvokeMember(<br \/>\n\u201cFetch\u201d, \u201cInvokeMethod\u201d, $Null, $View, $Null<br \/>\n)<\/p>\n<p>$global:ProductCode = $record.GetType().InvokeMember(<br \/>\n\u201cStringData\u201d, \u201cGetProperty\u201d, $Null, $record, 1<br \/>\n)<\/p>\n<p>} catch {<br \/>\nthrow &quot;Failed to get MSI file version the error was: {0}.&quot; -f $_<br \/>\n}<br \/>\n}<\/p>\n<p>function convert1 {<br \/>\nparam (<br \/>\n$codeID,<br \/>\n$i)<br \/>\n$global:convert1 = &quot;&quot;<\/p>\n<p>do {<br \/>\n$code = $codeID.Substring($i,1)<br \/>\n$global:convert1 = $global:convert1 + $code<br \/>\n$i = $i &#8211; 1<br \/>\n}<br \/>\nwhile ($i -ne -1)<br \/>\nreturn $global:convert1<br \/>\n}<\/p>\n<p>function convert2 {<br \/>\nparam (<br \/>\n$codeID,<br \/>\n$i)<br \/>\n$c = 0<br \/>\n$global:convert2 = &quot;&quot;<br \/>\ndo {<br \/>\n$code1 = $codeID.Substring($c,1)<br \/>\n$c++<br \/>\n$code2 = $codeID.Substring($c,1)<\/p>\n<p>$global:convert2 = $global:convert2 + $code2 + $code1<br \/>\n$c++<br \/>\n}<br \/>\nwhile ($c -ne $i)<br \/>\nreturn $global:convert2<br \/>\n}<\/p>\n<p>Function Get-FileName($initialDirectory)<br \/>\n{<br \/>\n[System.Reflection.Assembly]::LoadWithPartialName(&quot;System.windows.forms&quot;) |<br \/>\nOut-Null<\/p>\n<p>$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog<br \/>\n$OpenFileDialog.ShowHelp = $True<br \/>\n$OpenFileDialog.initialDirectory = $initialDirectory<br \/>\n$OpenFileDialog.filter = &quot;All files (*.msi)| *.msi&quot;<br \/>\n# $OpenFileDialog.filter = &quot;All files (*.*)| *.*&quot;<br \/>\n$OpenFileDialog.ShowDialog() | Out-Null<br \/>\n$global:msifile = $OpenFileDialog.filename<br \/>\n} #end function Get-FileName<br \/>\n#######################################################################################################################<\/p>\n<p>#&#8212;&#8211;GUI&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n[void] [System.Reflection.Assembly]::LoadWithPartialName(&quot;System.Drawing&quot;)<br \/>\n[void] [System.Reflection.Assembly]::LoadWithPartialName(&quot;System.Windows.Forms&quot;)<\/p>\n<p>$objForm = New-Object System.Windows.Forms.Form<br \/>\n$objForm.Text = &quot;MSI Info Tool&quot;<br \/>\n$objForm.Size = New-Object System.Drawing.Size(600,240)<br \/>\n$objForm.StartPosition = &quot;CenterScreen&quot;<\/p>\n<p>$objForm.KeyPreview = $True<br \/>\n$objForm.Add_KeyDown({if ($_.KeyCode -eq &quot;Enter&quot;)<br \/>\n{$x=$objTextBox.Text;$objForm.Close()}})<br \/>\n$objForm.Add_KeyDown({if ($_.KeyCode -eq &quot;Escape&quot;)<br \/>\n{$objForm.Close()}})<\/p>\n<p>$CancelButton = New-Object System.Windows.Forms.Button<br \/>\n$CancelButton.Location = New-Object System.Drawing.Size(485,170)<br \/>\n$CancelButton.Size = New-Object System.Drawing.Size(80,23)<br \/>\n$CancelButton.Text = &quot;Cancel&quot;<br \/>\n$CancelButton.Add_Click({$objForm.Close()})<br \/>\n$objForm.Controls.Add($CancelButton)<\/p>\n<p>$OpenButton = New-Object System.Windows.Forms.Button<br \/>\n$OpenButton.Location = New-Object System.Drawing.Size(10,20)<br \/>\n$OpenButton.Size = New-Object System.Drawing.Size(120,23)<br \/>\n$OpenButton.Text = &quot;MSI Datei ausw\u00e4hlen&quot;<br \/>\n$OpenButton.Add_Click({<br \/>\nGet-FileName -initialDirectory &quot;c:\\&quot;<\/p>\n<p>If ($global:msifile) {<br \/>\n$objTextBox1.Text = $global:msifile<\/p>\n<p>Get-MsiVersion $global:msifile<br \/>\nGet-MsiProductCode $global:msifile<\/p>\n<p>$global:MSIInstallerID = $global:productCode.replace(&quot;{&quot;,&quot;&quot;)<br \/>\n$global:MSIInstallerID = $global:MSIInstallerID.replace(&quot;}&quot;,&quot;&quot;)<br \/>\n$global:MSIInstallerID_split = $global:MSIInstallerID.split(&quot;-&quot;)<\/p>\n<p>$block0 = convert1 $global:MSIInstallerID_split[0] 7<br \/>\n$block1 = convert1 $global:MSIInstallerID_split[1] 3<br \/>\n$block2 = convert1 $global:MSIInstallerID_split[2] 3<br \/>\n$block3 = convert2 $global:MSIInstallerID_split[3] 4<br \/>\n$block4 = convert2 $global:MSIInstallerID_split[4] 12<\/p>\n<p>$global:MSIInstallerID = $block0 + $block1 + $block2 + $block3 + $block4<\/p>\n<p>$objTextBox3.Text = $global:productVersion<br \/>\n$objTextBox4.Text = $global:productCode<br \/>\n$objTextBox5.Text = $global:MSIInstallerID<\/p>\n<p>$objForm.Update()<br \/>\n}<br \/>\nElse{<br \/>\n[System.Reflection.Assembly]::LoadWithPartialName(\u201cSystem.Windows.Forms\u201d)<br \/>\n[Windows.Forms.MessageBox]::Show(\u201cEs wurde keine Datei ausgew\u00e4hlt!\u201d, \u201cError\u201d, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)<br \/>\n}<br \/>\n})<br \/>\n$objForm.Controls.Add($OpenButton)<\/p>\n<p>$objTextBox1 = New-Object System.Windows.Forms.TextBox<br \/>\n$objTextBox1.Location = New-Object System.Drawing.Size(140,22)<br \/>\n$objTextBox1.Size = New-Object System.Drawing.Size(400,20)<br \/>\n$objTextBox1.Text = &quot;MSI Datei ausw\u00e4hlen&quot;<br \/>\n$objForm.Controls.Add($objTextBox1)<\/p>\n<p>$objForm.Controls.Add($InfoButton)<\/p>\n<p>$objLabel2 = New-Object System.Windows.Forms.Label<br \/>\n$objLabel2.Location = New-Object System.Drawing.Size(10,90)<br \/>\n$objLabel2.Size = New-Object System.Drawing.Size(120,20)<br \/>\n$FontBold = new-object System.Drawing.Font(&quot;Arial&quot;,8,[Drawing.FontStyle]&#8217;Bold&#8216; )<br \/>\n$objLabel2.Font = $fontBold<br \/>\n$objLabel2.Text = &quot;MSI Info&quot;<br \/>\n$objForm.Controls.Add($objLabel2)<\/p>\n<p>$objLabel3 = New-Object System.Windows.Forms.Label<br \/>\n$objLabel3.Location = New-Object System.Drawing.Size(10,110)<br \/>\n$objLabel3.Size = New-Object System.Drawing.Size(160,20)<br \/>\n$objLabel3.Text = &quot;MSI Version: &quot;<br \/>\n$objForm.Controls.Add($objLabel3)<\/p>\n<p>$objTextBox3 = New-Object System.Windows.Forms.TextBox<br \/>\n$objTextBox3.Location = New-Object System.Drawing.Size(170,110)<br \/>\n$objTextBox3.Size = New-Object System.Drawing.Size(250,20)<br \/>\n$objForm.Controls.Add($objTextBox3)<\/p>\n<p>$objLabel4 = New-Object System.Windows.Forms.Label<br \/>\n$objLabel4.Location = New-Object System.Drawing.Size(10,135)<br \/>\n$objLabel4.Size = New-Object System.Drawing.Size(160,20)<br \/>\n$objLabel4.Text = &quot;MSI ProductCode: &quot;<br \/>\n$objForm.Controls.Add($objLabel4)<\/p>\n<p>$objTextBox4 = New-Object System.Windows.Forms.TextBox<br \/>\n$objTextBox4.Location = New-Object System.Drawing.Size(170,135)<br \/>\n$objTextBox4.Size = New-Object System.Drawing.Size(250,20)<br \/>\n$objForm.Controls.Add($objTextBox4)<\/p>\n<p>$objLabel5 = New-Object System.Windows.Forms.Label<br \/>\n$objLabel5.Location = New-Object System.Drawing.Size(10,160)<br \/>\n$objLabel5.Size = New-Object System.Drawing.Size(160,20)<br \/>\n$objLabel5.Text = &quot;MSIInstallerID: &quot;<br \/>\n$objForm.Controls.Add($objLabel5)<\/p>\n<p>$objTextBox5 = New-Object System.Windows.Forms.TextBox<br \/>\n$objTextBox5.Location = New-Object System.Drawing.Size(170,160)<br \/>\n$objTextBox5.Size = New-Object System.Drawing.Size(250,20)<br \/>\n$objForm.Controls.Add($objTextBox5)<\/p>\n<p>$objForm.Topmost = $True<\/p>\n<p>$objForm.Add_Shown({$objForm.Activate()})<br \/>\n[void] $objForm.ShowDialog()<\/p>\n<p>[\/php]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>0 0 Oft schon stand ich vor dem Problem, das ich gerne die MSI-GUID, MSI-InstallerID und die Version einer neuen MSI Datei auslesen wollte, ohne gleich den Empirum Packaging Wizard zur Hand zu nehmen. Zum Beispiel bei Empirum Paketen, die aus mehreren MSI Dateien bestehen, oder nur um eine neuere Versionen einer Applikation, die \u00fcber &hellip; <a href=\"http:\/\/workplace.skyworker.de\/?p=65\" class=\"more-link\"><span class=\"screen-reader-text\">\u201ePowershell: Tool zum auslesen von MSI Informationen\u201c<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":1829,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,3,38],"tags":[5,6,7,8,10,9],"_links":{"self":[{"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/posts\/65"}],"collection":[{"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65"}],"version-history":[{"count":15,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":1836,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/posts\/65\/revisions\/1836"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=\/wp\/v2\/media\/1829"}],"wp:attachment":[{"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/workplace.skyworker.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}