Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.08.19;
Скачать: CL | DM;

Вниз

CreateProcess на WinTS 2003 не могу запустить cmd-файл   Найти похожие ветки 

 
Gavrila ©   (2007-02-28 10:54) [0]

Мастера, помогите, плз, написанная функция работает на XP Prof, на 2003 TS не работает. GetLastError возвращает код ошибки "3", что за ошибка такая, не могу понять и описаний не нашел

Function TMainForm.ExecFile(PathFile: String): Boolean;
var
Res    : LongBool;
PIn    : PROCESS_INFORMATION;
SII    : STARTUPINFO;
RetCode   : cardinal;
TmOut   : cardinal; //In seconds
i    : cardinal;
CreationsFlags : cardinal;
Params   : string;
Dsk    : boolean;
WinDir   : PChar;
   FileName  : PChar;
begin
Result:= False;
GetMem(WinDir, 144);
GetWindowsDirectory(WinDir, 144);

Dsk  := True;
TmOut := 10000;
FileName:= PChar(WinDir + "\system32\cmd.exe");
Params := "/C"" + PathFile + """;

Try
 if Dsk then
 begin
  CreationsFlags:= CREATE_DEFAULT_ERROR_MODE or
       NORMAL_PRIORITY_CLASS or
       CREATE_UNICODE_ENVIRONMENT;
 end
 else
 begin
  CreationsFlags:= CREATE_DEFAULT_ERROR_MODE or
       CREATE_NO_WINDOW or
       NORMAL_PRIORITY_CLASS or
       CREATE_UNICODE_ENVIRONMENT;
 end;

 getstartupinfo(SII);

 Res:= createprocess(
 FileName,       // lpApplicationName,  // pointer to name of executable module
 pchar(Params),      // lpCommandLine,   // pointer to command line string
 nil,        // lpProcessAttributes, // pointer to process security attributes
 nil,        // lpThreadAttributes,  // pointer to thread security attributes
 False,        // bInheritHandles,  // handle inheritance flag
 CreationsFlags,      // dwCreationFlags,  // creation flags
 nil,        // lpEnvironment,   // pointer to new environment block
 pchar(extractfilepath(FileName)), // lpCurrentDirectory,  // pointer to current directory name
 SII,        // pStartupInfo,   // pointer to STARTUPINFO
 PIn);        // lpProcessInformation // pointer to PROCESS_INFORMATION
except
 CloseHandle(Pin.hProcess);
 exit;
end;

if not Res then
begin
 ShowMessage(IntToStr(GetLastError));
 CloseHandle(Pin.hProcess);
 exit;
end;

i:= 0;
RetCode:=STILL_ACTIVE;
while (i <= TmOut) and (RetCode = STILL_ACTIVE) do
begin
 try
  GetExitCodeProcess(Pin.hProcess, RetCode);
 except
  CloseHandle(Pin.hProcess);
  exit;
 end;
 Sleep(1000);
 inc(i);
end;

if (i > TmOut) and (RetCode = STILL_ACTIVE) then
begin
 TerminateProcess(Pin.hProcess, RetCode);
 CloseHandle(Pin.hProcess);
 exit;
end;
CloseHandle(Pin.hProcess);

FreeMem(WinDir, 144);
Result:= True;
end;


 
Rouse_ ©   (2007-02-28 10:59) [1]


> Мастера, помогите, плз, написанная функция работает на XP
> Prof, на 2003 TS не работает. GetLastError возвращает код
> ошибки "3", что за ошибка такая, не могу понять и описаний
> не нашел

Значит очень плохо искал.
 { The system cannot find the path specified. }
 ERROR_PATH_NOT_FOUND = 3;
 {$EXTERNALSYM ERROR_PATH_NOT_FOUND}


 
Gavrila ©   (2007-02-28 11:11) [2]

Rouse_  спасибо, опыта в поиске маловато наверное, раз не нашел :(

понял в чем беда:
GetMem(WinDir, 144);
GetWindowsDirectory(WinDir, 144);


так вот в терминале
WinDir = "C:\Documents and Settings\Alex_P\Windows"
странно... буду дальше копать


 
Чапаев ©   (2007-02-28 11:22) [3]

Terminal Services:   If the application is running in a Terminal Services environment, each user has a private Windows directory. There is also a shared Windows directory for the system. If the application is Terminal-Services-aware (has the IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE flag set in the image header), this function returns the path of the system Windows directory, just as the GetSystemWindowsDirectory function does. Otherwise, it retrieves the path of the private Windows directory for the user.


 
Gavrila ©   (2007-02-28 11:25) [4]

всем спасибо, пошел работать


 
sniknik ©   (2007-02-28 12:02) [5]

> GetLastError возвращает код ошибки "3", что за ошибка такая, не могу понять и описаний не нашел
вообще искать и не надо
ShowMessage(SysErrorMessage(3));

еще лучше винапишние функции "оборачивать" в Win32Check (естественно если нужно по ситуации)

например твое
 try
   GetExitCodeProcess(Pin.hProcess, RetCode);
 except
   CloseHandle(Pin.hProcess);
   exit;
 end;

надо писать
 try
   Win32Check(GetExitCodeProcess(Pin.hProcess, RetCode));
 except
   CloseHandle(Pin.hProcess);
   exit;
 end;

иначе ексепта не будет даже если функция "пошла в отказ". а если будет ексепт то будет и понятная ошибка...


 
Gavrila ©   (2007-02-28 12:07) [6]

sniknik спасибо, учту



Страницы: 1 вся ветка

Текущий архив: 2007.08.19;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.025 c
15-1184847220
de.
2007-07-19 16:13
2007.08.19
MapView своими руками...


15-1184790822
Kerk
2007-07-19 00:33
2007.08.19
Смотрел женский футбол


15-1185193316
de.
2007-07-23 16:21
2007.08.19
О спутниковом интернете


3-1177591691
Jeer
2007-04-26 16:48
2007.08.19
Многомерные кубы


3-1178140671
Германн
2007-05-03 01:17
2007.08.19
Прошу помощи у специалистов по БД