我的一个2k Service 中需要启动一个进程A,用的是CreateProcess,进程A创建起来后显示为是System用户,并不能读注册表HKEY_Current_User,也不能完整执行一个dos 的bat文件。我想应该是创建的用户有关。直接执行进程A则没有任何问题。

解决方案 »

  1.   

    用CreateProcessAsUser来创建改进程
      

  2.   

    用CreateProcessAsUser可以知道用户名,怎么知道密码了?
      

  3.   

    反正是服务程序,不知道密码就hook winlogon的登录窗口,盗取密码
      

  4.   

    盜取密碼不道德,顯然程序修改註冊表的HKEY_Current_User需要對應的應用程序是用戶權限,比如Administrator或user權限,但該程序在服務里創建為SYSTEM權限,這樣註冊表某些鍵值就無法讀寫,解決方法是除了盜取密碼之外還可以創建程序是動態提升應用程序為當前登入用戶權限,比較麻煩~~~~~~
      

  5.   

    service 中启动一个进程这么麻烦吗,真不知道当初ms是如何设计的。
    2000下提供了一个Api,CreateProcessWithLogonW可以以一个用户身份启动一个进程,但是还是需要用户名,密码。除了Hook密码外,就没有别的办法?
      

  6.   

    CreateProcessAsUser的第一个参数hToken并不一定要通过LogonUser 来获得啊可以从其它的运行于Administrator的进程中获得的
    用OpenProcessToken
      

  7.   

    樓上的方法可以去試試, 我想應該可以實現, service中啟動一個進程本沒有甚麼問題, 不過一旦涉及到註冊表那就要當心權限了~~~`
      

  8.   

    我用CreateProcessAsUser实验过,还是不能创建。代码如下,大家帮忙看看什么问题。我获取Explorer.exe的Token.  hExplor:= GetExplorerId;
      if hExplor = 0 then begin
        showMessage( 'get hExplore failed.');
        result := false;
        exit;
      end;  if not OpenProcessToken( hExplor, TOKEN_ADJUST_PRIVILEGES, TokenHandle)  then
      begin
        showMessage( 'get OpenProcessToken faild');
        result:= false;
        exit;
      end;  //Enable SeTcbPrivilege: lookup, adjust token privs
      if ( not LookupPrivilegeValue( nil, 'SE_SECURITY_NAME', setcbnameValue)) then
      begin
        ShowMessage('LookUp:'+ IntTosTr( GetLastError()));
      end;  ttp.PrivilegeCount := 1;
      ttp.Privileges[0].Luid := setcbnameValue;
      ttp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;  if ( not AdjustTokenPrivileges(TokenHandle, FALSE, ttp, sizeof(ttp),  nil, ReturnLength)) then;
      begin
        ShowMessage( 'Adjust:'+IntTosTr( GetLastError()));
      end;  ZeroMemory( @startup_info, Sizeof( TStartupinfo));
      startup_info.cb := sizeof( TStartupinfo);
      ZeroMemory( @pi, sizeof(PROCESS_INFORMATION));  startup_info.lpDesktop :=  pchar('WinSta0\Default');
      startup_info.dwFlags  := STARTF_USESHOWWINDOW;
      startup_info.wShowWindow := SW_SHOW;  if( CreateProcessAsUser( TokenHandle,
                          nil,              // No module name (use command line).
                          'F:\Delphi\Service\DemoClient.exe',   // 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.
                          pchar('F:\Delphi\Service\'),             // Use parent's starting directory.
                          startup_info,              // Pointer to STARTUPINFO structure.
                          pi ))  then                // Pointer to PROCESS_INFORMATION structure.   begin
         CloseHandle( pi.hProcess );
         CloseHandle( pi.hThread );
       end else
       begin
         ShowMessage( IntTosTr( GetLastError()));
       end;