Announcement

Collapse
No announcement yet.

gbak.exe über einen Dienst starten

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • gbak.exe über einen Dienst starten

    Hallo Forum,

    ich bin am verzweifeln. Zur Zeit programmiere ich einen Dienst, der gbak.exe starten soll. Leider tut gbak.exe nicht das, was es sollte. Es werden drei Zeilen ins Backup-Protokoll geschrieben, die da lauten:

    gbak: gbak version WI-V6.0.1.6
    gbak: ERROR: unavailable database
    gbak: Exiting before completion due to errors

    Der AnsiString asMsg enthält die Kommandozeile. Wenn ich die in der Eingabeaufforderung bzw. in einem Batch einsetze, funktioniert sie einwandfrei.

    Ich poste mal die Methode, über die gbak.exe gestartet werden soll. Diese Methode funktioniert in einem GUI-Programm, 1:1 übernommen, tadelos.

    Vielleicht kann mir einer von Euch sagen, was da falsch ist?

    <PRE>
    int __fastcall TSparkyThread::StarteProgramm(AnsiString asProgramm, AnsiString asParameter,
    bool bEnvironment, int iCmdShow)
    {
    AnsiString asMsg = "";
    bool bOrdner = false;
    DWORD ExitCode = 1; //für den ExitCode
    int iUser = 0; //Rückgabewert für Umgebungs-Variable isc_user
    int iPassword = 0; //Rückgabewert für Umgebungs-Variable isc_password
    TStartupInfo stgStartupInfo; //für CreateProcess()
    TProcessInformation stgProcessInfo; //für CreateProcess()

    asProgramm = LowerCase(asProgramm);
    asParameter = LowerCase(asParameter);

    //iCmdShow steuert die Sichtbarbeit des Programms
    //iCmdShow = SW_HIDE : verbirgt das Programm (isql, gbak)
    //iCmdShow = SW_SHOW : zeigt das Programm (Comparer.exe, blob.exe, prjVorlagen.exe)
    setmem(&stgStartupInfo, sizeof(TStartupInfo), 0);
    stgStartupInfo.cb = sizeof(TStartupInfo); //.cb : Specifies the size, in bytes, of the structure.
    stgStartupInfo.dwFlags = STARTF_USESHOWWINDOW; //.dwFlags : This is a bit field that determines whether certain STARTUPINFO members are used when the process creates a window. Any combination of the following values can be specified:
    stgStartupInfo.wShowWindow = iCmdShow; //.wShowWindow : Ignored unless dwFlags specifies STARTF_USESHOWWINDOW. The wshowWindow member can be any of the SW_ constants defined in WINUSER.H. For GUI processes, wShowWindow specifies the default value the first time ShowWindow is called. The nCmdShow parameter of ShowWindow is ignored. In subsequent calls to ShowWindow, the wShowWindow member is used if the nCmdShow parameter of ShowWindow is set to SW_SHOWDEFAULT.

    //Auszuführendes Programm (Prozeß)
    asMsg = asProgramm;
    //Wenn Kommandozeilen-Parameter vorhanden sind, dann anhängen
    if(asParameter != "")
    {
    asMsg += " " + asParameter;
    }

    //Pfad einstellen, falls das Programm noch zusätzliche Dateien braucht
    bOrdner = SetCurrentDir(ExtractFilePath(asProgramm));

    CreateProcess(NULL, //LPCTSTR lpApplicationName //pointer to name of executable module
    asMsg.c_str(), //LPTSTR lpCommandLine //pointer to command line string
    NULL, //LPSECURITY_ATTRIBUTES lpProcessAttributes //pointer to process security attributes
    NULL, //LPSECURITY_ATTRIBUTES lpThreadAttributes //pointer to thread security attributes
    false, //BOOL bInheritHandles //handle inheritance flag
    CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, //DWORD dwCreationFlags //creation flags
    NULL, //LPVOID lpEnvironment //pointer to new environment block
    NULL, //LPCTSTR lpCurrentDirectory //pointer to current directory name
    &stgStartupInfo, //LPSTARTUPINFO lpStartupInfo //pointer to STARTUPINFO
    &stgProcessInfo); //LPPROCESS_INFORMATION lpProcessInformation //pointer to

  • #2
    Und hier kommt der Rest :-)

    <PRE>
    CreateProcess(NULL, //LPCTSTR lpApplicationName //pointer to name of executable module
    asMsg.c_str(), //LPTSTR lpCommandLine //pointer to command line string
    NULL, //LPSECURITY_ATTRIBUTES lpProcessAttributes //pointer to process security attributes
    NULL, //LPSECURITY_ATTRIBUTES lpThreadAttributes //pointer to thread security attributes
    false, //BOOL bInheritHandles //handle inheritance flag
    CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, //DWORD dwCreationFlags //creation flags
    NULL, //LPVOID lpEnvironment //pointer to new environment block
    NULL, //LPCTSTR lpCurrentDirectory //pointer to current directory name
    &stgStartupInfo, //LPSTARTUPINFO lpStartupInfo //pointer to STARTUPINFO
    &stgProcessInfo); //LPPROCESS_INFORMATION lpProcessInformation //pointer to PROCESS_INFORMATION

    //Auf das Programmende warten
    WaitForSingleObject(stgProcessInfo.hProcess, INFINITE);
    //Das Programm wurde beendet...

    //If the function succeeds, the return value is nonzero.
    //If the function fails, the return value is zero.
    //Rückgabewert auslesen
    GetExitCodeProcess(stgProcessInfo.hProcess, &ExitCode);

    //Ressourcen freigeben
    CloseHandle(stgProcessInfo.hProcess);

    //ExitCode == 0 entspricht "Fehlerfrei"
    if(ExitCode == 0)
    {
    //Fehlerfreier Programmstart
    Protokoll("Befehl ausgeführt:\t" + asMsg);
    }
    else
    {
    //Programmstart fehlgeschlagen
    Protokoll("Befehl fehlgeschlagen:\t" + asMsg);
    Protokoll("Befehl fehlgeschlagen:\tExitCode: " + FormatFloat("#,##0", ExitCode));
    } // else if(ExitCode == 0)
    }
    //---------------------------------------------------------------------------
    </PRE&gt

    Comment


    • #3
      Hallo Jürgen,
      <br><br>
      verwendest eine TCP/IP-Verbindung, auch wenn es sich um eine lokale Datenbank handelt (z.B. mit localhost:c:\...)? Wenn das alleine nicht hilft, dann könntest Du auch noch versuchen, dass Dein Dienst eine Interaktion mit dem Desktop erlaubt.
      <br><br>
      Thoma
      Thomas Steinmaurer

      Firebird Foundation Committee Member
      Upscene Productions - Database Tools for Developers
      Mein Blog

      Comment


      • #4
        Hallo Thomas,

        das wars! Interaktion mit dem Desktop stand auf false. Auf true gesetzt und nun gehts ab wie Schmitz Katze.

        Herzlichen Dank!

        PS. Ich verwende immer eine TCP/IP-Verbindung, so in der Art:

        d:\programme\borland\interbase\bin\gbak.exe -backup -ignore -v -z e:\30001\huesing\audamupsii_basis.gdb e:\backup\huesing\audamupsii_basis.gbk -y e:\backup\huesing\audamupsii_basis_backuplog.txt

        Also nochmal. Vielen vielen Dank für die Hilfe, die ich bisher hier erhalten habe.

        Schönes Wochenende..

        Comment


        • #5
          Hallo Jürgen,
          <br><br>
          schön, dass es jetzt funktioniert, aber in Deinem Beispiel sehe ich nicht wirklich eine TCP/IP-Verbindung. ;-)
          <br><br>
          Thoma
          Thomas Steinmaurer

          Firebird Foundation Committee Member
          Upscene Productions - Database Tools for Developers
          Mein Blog

          Comment


          • #6
            Ups, das sollte so aussehen...

            d:\programme\borland\interbase\bin\gbak.exe -backup -ignore -v -z Rechner:e:\30001\huesing\audamupsii_basis.gdb e:\backup\huesing\audamupsii_basis.gbk -y e:\backup\huesing\audamupsii_basis_backuplog.tx

            Comment

            Working...
            X