title: LogonUser + CreateProcessAsUser at Service = error 1314
body: <p>I have a windows service created with Delphi 7, with StartType = stSystem.</p>
  
  <p>Now I need to launch an application to make some things for me.
  This application has a MainForm and other GDI resources.
  The parameter passed to the application assigns values for some controls (like edits and memos) and then click at a button....</p>
  
  <p>I'm trying this:</p>
  
  <pre><code>var
    token: cardinal;
    si: TStartupInfo;
    pi: TProcessInformation;
  begin
    if not LogonUser('admintest', '', 'secret123', LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token) then
      RaiseLastOSError;
  
    try
      if not ImpersonateLoggedOnUser(token) then
        RaiseLastOSError;
  
      fillchar(si, sizeof(si), 0);
      si.cb := sizeof(si);
      si.lpDesktop := PChar('winsta0\default');
      if not CreateProcessAsUser(token, nil, '"c:\...\myapp.exe" -doCrazyThings', nil, nil, false, NORMAL_PRIORITY_CLASS or CREATE_NEW_CONSOLE, nil, nil, si, pi) then
        RaiseLastOSError;
  
      CloseHandle(pi.hThread);
      waitForSingleObject(pi.hProcess, INFINITE);
      CloseHandle(pi.hProcess);
    finally
      CLoseHandle(token);
    end;
  end;
  </code></pre>
  
  <p><strong>When I run my service executable as a normal application (-noservice), it starts as a Forms.Application and creates a MainForm with a button "Start".</strong>
  *<em>The button runs the same code that service run, but it doesn't works and it's rasing the eror code 1314 at createprocessasuser.</em>*</p>
  
  <p><strong>Why? What is the diference between SYSTEM service and a normal application launched by a administrator?</strong></p>
  
  <p>My environment is a Windows 7 Pro x64</p>
  
  <p>What am I doing wrong?
  How can I solve this?
  Can someone post an example?</p>