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
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
Comment