小弟想在服务中调用启动一个应用程序,用WinExec,ShellApi启动不了,不知为什么?大侠请指点。 用CreateProcess 不知行不行?

解决方案 »

  1.   

    var
      FileName: array [0..80] of char;
      si      : TStartupInfo;
      pi      : TProcessInformation;
      Len :Integer;
      hReg:HKEY;
      Ret :integer;
    begin
      Ret := RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'Software\xxx有限公司\Sample',
              0, KEY_READ, hReg);
      if Ret = ERROR_SUCCESS then
      begin
        Len := 80;
        RegQueryValueEx(hReg, 'Path', nil, nil, @FileName, @Len);
        RegCloseKey(hReg);
      end;  StrCat(FileName, 'Sample.exe');
      ZeroMemory(@si, sizeof(TStartupInfo));
      si.cb := sizeof(TStartupInfo);
      si.dwFlags := si.dwFlags OR STARTF_USESHOWWINDOW;
      si.wShowWindow := SW_SHOW;
      ZeroMemory(@pi, sizeof(TProcessInformation));
      CreateProcess(nil, // No module name (use command line).
        FileName,        // Command line.
        nil,             // Process handle not inheritable.
        nil,             // Thread handle not inheritable.
        FALSE,            // Set handle inheritance to FALSE.
        0,                // No creation flags.
        nil,             // Use parent's environment block.
        nil,             // Use parent's starting directory.
        si,              // Pointer to STARTUPINFO structure.
        pi);             // Pointer to PROCESS_INFORMATION structure.  CloseHandle(pi.hProcess);
      CloseHandle(pi.hThread);
      Suspend;
    end;win2000服务程序调试成功