首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InnoSetup + MySQL ODBC脚本=错误消息

InnoSetup + MySQL ODBC脚本=错误消息
EN

Stack Overflow用户
提问于 2013-10-07 07:10:48
回答 1查看 4.3K关注 0票数 4

我一直试图使用Inno安装程序为我的vb.net应用程序创建一个安装程序。

此应用程序具有对MySQL ODBC的先决条件依赖关系。因此,我在想,如果存在MySQL,我是否可以检查系统,如果没有,请安装。老实说,我是一个新手程序员,我对debian一点也不了解,debian是InnoSetup的脚本语言。

从一段时间以来,我一直在寻求帮助,通过google和其他工具,但是除了一些例子,什么都找不到,于是我自己编写了脚本。

下面是剧本:

代码语言:javascript
复制
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{ID goes here}
AppName=DCS
AppVersion=1.0
;AppVerName=DCS 1.0
AppPublisher=Syed
DefaultDirName={pf}\DCS
DisableDirPage=yes
DefaultGroupName=DCS
DisableProgramGroupPage=yes
OutputBaseFilename=setup
SetupIconFile=C:\logo.ico
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.vshost.exe.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.vshost.exe.manifest"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.application"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.exe.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.exe.manifest"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.pdb"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.vshost.application"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.vshost.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\DCS.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\VS12\Projects\DCS\bin\Debug\mysql-connector-odbc-5.1.12-win32.msi"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[code]
function IsMySQLOdbcInstalled(): boolean;
begin
    If NOT RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\ODBC\ODBCINST.INI\MySQL ODBC 5.1 Driver') then
    Result := True
    Else
    Result := False;
end;

[Icons]
Name: "{group}\DCS"; Filename: "{app}\DCS.exe"
Name: "{commondesktop}\DCS"; Filename: "{app}\DCS.exe"; Tasks: desktopicon

[Run]
Filename: {src}\mysql-connector-odbc-5.1.12-win32.msi; Check: IsMySQLOdbcInstalled()
Filename: "{app}\DCS.exe"; Description: "{cm:LaunchProgram,DCS}"; Flags: nowait postinstall skipifsilent

现在,编译进行得很好,并生成一个setup.exe可执行文件。运行时,应用程序DCS会被安装,但是MySQL没有安装,并且会产生一个错误,

代码语言:javascript
复制
Unable to execute file:
'Output path'\mysql-connector-odbc-5.1.12-win32.msi
Create Process failed; code2.
The system cannot find the file specified. 

OK

我认为输出文件夹需要mysql-连接器-odbc msi安装文件夹。为了检查,我手动复制了它,重新编译并运行了安装程序,结果得到了相同的结果,但做了一些更改:

代码语言:javascript
复制
Unable to execute file:
'Output path'\mysql-connector-odbc-5.1.12-win32.msi
Create Process failed; code193.
%1 is not a vaild Win32 application. 

OK

而且,我还希望安装程序在安装之前检查MySQL ODBC驱动程序,但是在这里,它会在主应用程序安装之后进行检查。有人能帮我更正一下这个剧本吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-07 07:23:15

问题在于您的[Run]部分。您将从MySQL路径执行该{src} ODBC安装程序。由于您将mysql-connector-odbc-5.1.12-win32.msi安装程序文件复制到{app}文件夹,所以必须从相同的位置运行它。以这种方式修复脚本的[Run]部分:

代码语言:javascript
复制
[Run]
; on the following line, run the executable from the {app} directory instead
; of {src}; the {src} folder is the folder in which the Setup files are located
; since it is not an *.exe file, you must also specify the shellexec flag
Filename: {app}\mysql-connector-odbc-5.1.12-win32.msi; Check: IsMySQLOdbcInstalled(); Flags: shellexec
Filename: "{app}\DCS.exe"; Description: "{cm:LaunchProgram,DCS}"; Flags: nowait postinstall skipifsilent

更新:

为了满足您的额外需求,在主要安装过程之前运行ODBC驱动程序安装程序,我做了以下脚本示例(只保留与ODBC驱动程序设置相关的部分)。

无论如何,如果您在某种默认设置下以静默模式运行ODBC驱动程序安装程序,那么它将不会为用户提供向导(但这是这个问题的更广泛的主题;将有参数来控制ODBC驱动程序安装程序,而那些可以传递到Exec函数的第二个参数的参数可能会告诉显示窗口标志为SW_HIDE而不是SW_SHOWNORMAL,这将使其对用户保持隐藏)。请注意,此代码未经测试:

代码语言:javascript
复制
[Setup]
AppName=DCS
AppVersion=1.0
DefaultDirName={pf}\DCS

[Files]
; keep just the only one flag, "dontcopy"; it will tell the installer to not copy
; this file entry to the target machine, but will be part of the setup binary and
; available for manual extracting by using the ExtractTemporaryFile(s) function
Source: "C:\VS12\Projects\DCS\bin\Debug\mysql-connector-odbc-5.1.12-win32.msi"; Flags: dontcopy

[Run]
; remove the ODBC driver installer entry from [Run] section since the [Run] section
; is executed after the installation is succesfully finished and your requirement is
; to run it before the installation process
; Filename: {app}\mysql-connector-odbc-5.1.12-win32.msi; Check: IsMySQLOdbcInstalled()

[Code]
function IsMySQLODBC51Installed: Boolean;
begin
  // the result was inverted in the original code; the original function returned
  // True if the ODBC driver was not installed, False otherwise, and according to
  // the function name it should be vice-versa
  Result := RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\ODBC\ODBCINST.INI\MySQL ODBC 5.1 Driver');
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  ResultCode: Integer;
begin
  // if we are right before the main installation starts and ODBC driver is not yet
  // installed, then...
  if (CurStep = ssInstall) and not IsMySQLODBC51Installed then
  begin
    // now extract the ODBC installaer to the Inno Setup's temporary folder
    ExtractTemporaryFile('mysql-connector-odbc-5.1.12-win32.msi');
    // and execute the ODBC driver installation (it is necessary to use ShellExec
    // since it is not an *.exe file); if the execution fails, then...
    if not ShellExec('', ExpandConstant('{tmp}\mysql-connector-odbc-5.1.12-win32.msi'), '', '', 
      SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
    begin
      // show the error message with exit code
      MsgBox('MySQL ODBC Driver setup failed!' + #13#10 + 'Exit code: ' + IntToStr(ResultCode) +
        '; ' + SysErrorMessage(ResultCode), mbError, MB_OK);
      // here you can optionally call Abort to abort the upcoming installation process
      // so if you uncomment the following line, the main installation will not run if
      // the ODBC driver installer execution failed
      // Abort;
    end;
  end;
end;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19218918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档