
shane.mecham1.552492578107875E12 asked a question.
Simple way to get GUIDs?
I'm looking for a way to export or collect all of the GUIDs Package, Product, Ugrade that are in the MSI's I have. Is there a tool in Admin Studio that can do that? or does anyone know of a command line program that can?
Thank you in advance.
There are some other tools that I have seen, but none that allow me to select the information I want to see. It's an all or nothing, and none of it allows me to export the data simply.
Thanks for the reply.
If you havn't already, check out the MSI SDK and look at WiSQL.vbs for examples on how to query information in an MSI.
:)
Including one that might apply to your question:
SELECT 'Value' FROM 'Property' WHERE 'Property'='ProductCode'
@value = qw(ProductName UninstallCode ProcductCode);
foreach $value(@value){
"SELECT 'Value' FROM 'Property' WHERE 'Property'='$value'
}
that worked for what I needed. I'm at home, so I'll post the full code up on Monday...
Might be helpful to somone else. The VBS takes too much work to get the same results, so I went to Perl...
[CODE]
!perl
use Win32::OLE;
use strict;
use constant msiOpenDatabaseModeReadOnly => 0;
use constant msiOpenDatabaseModeTransact => 1;
my ($param, $argCount, $file);
$argCount = @ARGV;
if (($argCount < 1)) {
print "\n\t
Windows Installer utility to execute SQL queries against an installer database.
This returns the Product Name, Product code, and Upgrade code of all MSI files
given in the path or the file specified on the command line.
The 1st argument specified can be the path to search or the file you want info from.
\n\tExample: MSI_Properties.pl \"\\path\\share\\\" or \"\\path\\share\\msifile.msi\"\n
\t
";
exit (1);
}
my $openMode = msiOpenDatabaseModeReadOnly;
Connect to Windows installer object
my $installer = undef;
$installer = Win32::OLE->new('WindowsInstaller.Installer');
CheckError();
$param = $ARGV[0];
if ($param =~/(\.msi)/ || (-d $param)){
$file = $1;
}else{
die "Need MSI file or directory!\n";
}
my (@msis, $cmd);
Open database
my $databasePath = $ARGV[0]."\\*.msi";
if ($file){
@msis = ($ARGV[0]);
}else{
$cmd = "dir \"$databasePath\" /b /s";
print "$cmd\n";
@msis = qx($cmd);
}
my ($ctr, %msiData);
my $output = "MSI-Value";
&Name;
$output = $output.".xls";
open OUT, ">$output";
print OUT "Product Name\tUpgrade Code\tProduct Code\tFile - Path\n"; header row
for (@msis){
chomp;
$ctr++;
my $database = $installer->OpenDatabase($_, $openMode);
CheckError();
my ($value, $query, $view, $record, $message, $rowData, $columnCount, $delim, $column);
my @query_value = qw(ProductName UpgradeCode ProductCode);
foreach $value(@query_value){
$message;
$query = "SELECT \'Value\' FROM \'Property\' WHERE \'Property\'=\'$value\'";
$view = $database->OpenView($query);
CheckError();
$view->Execute();
CheckError();
if (uc(substr($query, 0, 6)) eq 'SELECT') {
while (1) {
$record = $view->Fetch;
last if !($record->{FieldCount});
$columnCount = $record->FieldCount;
$rowData = "";
$delim = ' ';
for my $column (1 .. $columnCount) {
if ($column eq $columnCount) {
$delim = vbLf;
}
$rowData = $rowData . $record->StringData($column) . $delim;
}
$message = $rowData;
chomp $message;
$msiData{$ctr}{$value} = $message;
}
}
$msiData{$ctr}{'PATH'} = $_;
if (defined($message)) {
print "$msiData{$ctr}{$value}\n";
print OUT "$msiData{$ctr}{$value}\t";
}
}
print OUT "$msiData{$ctr}{'PATH'}";
print "\n";
print OUT "\n";
$database->Close();
}
print "$ctr records added to $output\n";
close OUT;
exit (0);
sub CheckError {
my ($message, $errRec);
return if (0 + Win32::OLE::LastError()) == 0;
$message = ' ' . sprintf("%x", (0 + Win32::OLE::LastError())) . ': ' . ('' . Win32::OLE::LastError());
if (!($installer)) {
$errRec = $installer->LastErrorRecord;
if (!($errRec)) {
$message = $message . $errRec->FormatText;
}
}
Fail($message);
}
sub Fail {
my($message) = @_;
print "$message";
exit (2);
}
sub Name {
if (-e "$output.xls"){
my ($p1, $nctr) = split(/_/, $output);
$nctr++;
$output = join("_", $p1, $nctr);
&Name;
}else{
return;
}
}
[/CODE]
This will take a path or .msi file and return the Product name, Upgrade code, and Product Code from the msi. If it's a path, then it will run on all of them within the folder you specify. It dumps this out to a file called msi-values.xls (tab delimited). This file will increment as if it's already there...
Good luck and thanks for the help.