怎样在windows service中
执行(或者说打开)一个exe文件
使其在任务管理器中的用户名为当前登录用户
而不是SYSTEM

解决方案 »

  1.   

    using System.Diagnostics;
    Process.Start(@"D:\钓鱼\go2fishing.exe");
      

  2.   

    那样执行的用户名为SYSTEM
    我现在想建立一个普通用户的进程阿
      

  3.   

    Process.Start()方法有一个重载是要传入四个参数的:
    public static Process Start(
    string fileName,
    string userName,
    SecureString password,
    string domain
    )
    参数
    fileName
    类型:System.String要在该进程中运行的应用程序文件的名称。userName
    类型:System.String启动进程时使用的用户名。password
    类型:System.Security.SecureString一个 SecureString,它包含启动进程时要使用的密码。domain
    类型:System.String启动进程时要使用的域。
      

  4.   

    password 
    类型:System.Security.SecureString 一个 SecureString,它包含启动进程时要使用的密码。 domain 
    类型:System.String 
    这两个东西怎们能获得到阿
    总不能提示用户输入密码吧
      

  5.   

    你在C#中获取当前用户的账户密码基本是不可能的貌似在service中打开进程的话,只能以system的名义运行WINDOWS 安全机制限定的
      

  6.   


              [DllImport("advapi32.dll", CharSet = CharSet.Unicode)]
              static extern Boolean CreateProcessAsUser(
              IntPtr hToken,
              String lpApplicationName,
              String lpCommandLine,
              IntPtr lpProcessAttributes,
              IntPtr lpThreadAttributes,
              Boolean bInheritHandles,
              UInt32 dwCreationFlags,
              IntPtr lpEnvironment,
              String lpCurrentDirectory,
              ref STARTUPINFO lpStartupInfo,
              out PROCESS_INFORMATION lpProcessInformation);
      
              [DllImport("advapi32.dll", CharSet = CharSet.Unicode)]
              static extern Boolean LogonUser(
              String lpszUsername,
              String lpszDomain,
              String lpszPassword,
              Int32 dwLogonType,
              Int32 dwLogonProvider,
              ref IntPtr phToken
              );
    advapi32.dll 类内的这两个API 可以实现你要的功能
      

  7.   

    http://www.cnblogs.com/flying_bat/archive/2007/09/26/906435.html
    参考这里,有现成的源码
      

  8.   


    恩,我用上面start那个函数执行
    在windows service下throw exception
    access is denied 
      

  9.   

    service中获得当前explorer.exe的security token,然后调用CreateProcessAsUser来以当前user权限启动process,这样启动以后得到的就是当前用户权限进程。。http://www.cnblogs.com/liefeng123/articles/533743.html