python win32在使用Windows Installer API时失败,但perl工作正常-我在python中做错了什么?
我正在尝试使用python的win32 COM API编辑Windows安装程序MSI,但它不起作用。 我的perl应用程序运行得很好,但是尽管我的python运行没有错误,但MSI没有更新。我是python新手,所以可能会做一些愚蠢的事情。我的新工作使用的是python而不是perl,因此我非常感谢任何更正(特别是在错误检测和处理方面)。谢谢 下面是perl和pythonpython win32在使用Windows Installer API时失败,但perl工作正常-我在python中做错了什么?,python,com,windows-installer,Python,Com,Windows Installer,我正在尝试使用python的win32 COM API编辑Windows安装程序MSI,但它不起作用。 我的perl应用程序运行得很好,但是尽管我的python运行没有错误,但MSI没有更新。我是python新手,所以可能会做一些愚蠢的事情。我的新工作使用的是python而不是perl,因此我非常感谢任何更正(特别是在错误检测和处理方面)。谢谢 下面是perl和python use Win32::OLE; my $msifile = "ws.msi"; my($Installer, $data
use Win32::OLE;
my $msifile = "ws.msi";
my($Installer, $database, $query, $view);
$Installer = undef;
Win32::OLE::CreateObject("WindowsInstaller.Installer", $Installer) ||
die "CreateObject installer failed: $!";
$database = $Installer->OpenDatabase($msifile, 1) ||
die "cannot open msi file $msifile (OpenDatabase failed): $!";
my $qry = "UPDATE `InstallExecuteSequence` SET `InstallExecuteSequence`.`Condition`='1' WHERE `InstallExecuteSequence`.`Action`='CheckAllUserLegacy'";
$view = $database->OpenView($qry);
check_error();
$view->Execute;
check_error();
$database->Commit();
check_error();
print "\t$msifile updated \n";
$record = undef;
$view = undef;
$database = undef;
$Installer = undef;
exit 0;
sub check_error {
if ( Win32::OLE->LastError() ) {
printf "SQL ERROR, the following query:\n\t'==$query==\ngets\n\t(%-s)\n", Win32::OLE->LastError();
exit(1);
}
}
=========================================================================
import pdb;
import win32com.client
msifile = "e:\ws.msi"
MSIDBOPEN_TRANSACT = 1
MSIDBOPEN_DIRECT = 2
openMode = MSIDBOPEN_TRANSACT
print "about to open DB"
#pdb.set_trace()
try:
wi = win32com.client.DispatchEx ( "WindowsInstaller.Installer" )
db = wi.OpenDatabase( msifile, openMode )
except:
print "Oops"
else:
print ("opened OK")
sql = "UPDATE `InstallExecuteSequence` SET `InstallExecuteSequence`.`Condition`='0' WHERE `InstallExecuteSequence`.`Action`='CheckAllUserLegacy'"
#print(sql)
try:
view = db.OpenView(sql)
except:
error = wi.LastErrorRecord()
for field_num in range(1, error.FieldCount + 1):
print error.StringData(field_num)
else:
print ("after open view, didn't get exception")
try:
view.Execute
except:
error = wi.LastErrorRecord()
for field_num in range(1, error.FieldCount + 1):
print error.StringData(field_num)
else:
print ("view.executed didn't get exception")
try:
db.Commit
except:
error = wi.LastErrorRecord()
for field_num in range(1, error.FieldCount + 1):
print error.StringData(field_num)
else:
print ("after commit, didn't get exception")
print "end"
在运行perl之后,MSI被正确地更改,但是在运行python之后,它没有被更改。我是python新手,但多年来一直在使用perl(这些都是简化的片段,不是很好的编程示例)python需要在函数名后面加括号,否则它只会计算它们的地址,而不会调用它们。在
查看。执行
和db.Commit
之后,您将丢失它们,非常感谢!!很好的答案解决了我愚蠢的问题!