2011-05-13 216 views
3

GetExceptionMessage返回空消息(它只包含冒号“:”符号)。使用Inno Setup(5.4.2)的最后一个版本。Inno Setup GetExceptionMessage在Inno Setup脚本中返回空消息

try 
    Log('Create IISNamespace'); 
    // Create IIS namespace object 
    if Length(virtualDirectoryName) > 0 then 
    begin 
    IIS := CreateOleObject('IISNamespace'); 
    Log('Get IIsWebService'); 
    WebSite := IIS.GetObject('IIsWebService', IISServerName + '/w3svc'); 
    Log('Get IIsWebServer'); 
    WebServer := WebSite.GetObject('IIsWebServer', IISServerNumber); 
    Log('Get IIsWebVirtualDir'); 
    WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root'); 
    Log('Delete IIsWebVirtualDir'); 
    WebRoot.Delete('IIsWebVirtualDir', virtualDirectoryName); 
    WebRoot.SetInfo(); 
    end; 
except 
    MsgBox(ExpandConstant('{cm:IISException,'+ GetExceptionMessage +'}'), 
    mbInformation, mb_Ok); 
    Log('Uninstall IIS 6 exception: ' + GetExceptionMessage); 
end; 

删除IIsWebVirtualDir时发生异常。 有什么办法获得异常类型或真正的异常消息?

谢谢,丹尼斯。

+0

如果我运行inno附带的CodeAutomation.iss示例,那么'GetExceptionMessage' /'ShowExceptionMessage'返回“:”以便它看起来被破坏;尝试更旧的版本? – 2011-05-13 13:58:31

+0

我也试过5.2.3版本。结果是一样的。异常在安装程序的其他区域中正常工作 - 在其他异常事件期间显示消息。可能该错误与inno setup中的OLE/COM操作有关。 – 2011-05-17 07:26:39

+0

你在运行什么操作系统? – 2011-05-17 09:56:09

回答

0

我刚刚写了下面的例子,看看GetExceptionMessageShowExceptionMessage是否坏了。我使用了Inno setup 5.4.2 Unicode和Ansi版本。

[Setup] 
AppName=Test 
AppVersion=1.5 
DefaultDirName={pf}\test 

[Code] 
function InitializeSetup(): Boolean; 
var 
I: Integer; 
begin 
try 
    I := I div 0; // Raise an exception 
except 
     MsgBox(GetExceptionMessage, 
     mbError, MB_OK); 

     ShowExceptionMessage; 
end; 
result := false; 
end; 

我也运行了CodeAutomation.iss,它的运行和它的预期工作。这与Alex K.提出的意见相反,可能会被打破。

现在我知道这些例程应该可以工作了,我把你的代码做了下面的设置测试脚本并运行它,并且它没有找到ISSNamespace,因为我没有安装它。

[Setup] 
AppName=Test 
AppVersion=1.5 
DefaultDirName={pf}\test 
[CustomMessages] 
IISException =ISS Exception " %1 " occured. 

[Code] 

const 
    IISServerName = 'localhost'; 
    IISServerNumber = '1'; 
    IISURL = 'http://127.0.0.1'; 

function InitializeSetup(): Boolean; 
var 
    IIS, WebSite, WebServer, WebRoot, VDir: Variant; 
    virtualDirectoryName : String; 
begin 
virtualDirectoryName := 'test'; 
try 
    Log('Create IISNamespace'); 
    // Create IIS namespace object 
    if Length(virtualDirectoryName) > 0 then 
    begin 
    IIS := CreateOleObject('IISNamespace'); 
    Log('Get IIsWebService'); 
    WebSite := IIS.GetObject('IIsWebService', IISServerName + '/w3svc'); 
    Log('Get IIsWebServer'); 
    WebServer := WebSite.GetObject('IIsWebServer', IISServerNumber); 
    Log('Get IIsWebVirtualDir'); 
    WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root'); 
    Log('Delete IIsWebVirtualDir'); 
    WebRoot.Delete('IIsWebVirtualDir', virtualDirectoryName); 
    WebRoot.SetInfo(); 
    end; 
except 
MsgBox(ExpandConstant('{cm:IISException,'+ GetExceptionMessage +'}'), 
    mbInformation, mb_Ok); 
    Log('Uninstall IIS 6 exception: ' + GetExceptionMessage); 
end; 
end; 

但是我在制作这个脚本时犯了一个致命的缺陷,可能是你的问题。

检查您的[CustomMesssages]部分,确保您在邮件中包含%1。否则没有任何回报。

+0

是的,我在[CustomMessages]部分使用“IIS异常:%1”消息。真的,空的异常看起来像inno setup中的异常处理错误。 – 2011-05-17 07:22:38

+0

@ Dennis异常消息在日志中也是空白的?你在其上运行什么操作系统和版本的IIS可能是特定的? – 2011-05-17 10:00:15

+0

是的,日志消息看起来像“Uninstall IIS 6 exception ...:”。 OS/IIS版本:Windows Server 2003/IIS 6。 – 2011-05-17 15:40:14