爱玩科技网
您的当前位置:首页如何解决vista和win7在windows服务中无法与桌面程序交互的问题?

如何解决vista和win7在windows服务中无法与桌面程序交互的问题?

来源:爱玩科技网

问题描述

解决方案

using Cjwdev; 
using Cjwdev.WindowsApi;

try 
       {
           appStartPath= ‚C:\\ruhoo.exe; 
           IntPtr userTokenHandle = IntPtr.Zero; 
           ApiDefinitions.WTSQueryUserToken(ApiDefinitions.WTSGetActiveConsoleSessionId(), ref userTokenHandle);
           ApiDefinitions.PROCESS_INFORMATION procInfo = new ApiDefinitions.PROCESS_INFORMATION(); 
           ApiDefinitions.STARTUPINFO startInfo = new ApiDefinitions.STARTUPINFO(); 
           startInfo.cb = (uint)Marshal.SizeOf(startInfo);
           ApiDefinitions.CreateProcessAsUser( 
               userTokenHandle, 
               appStartPath, 
             ‚„, 
               IntPtr.Zero, 
               IntPtr.Zero, 
               false, 
               0, 
               IntPtr.Zero, 
               null, 
               ref startInfo, 
               out procInfo);
           if (userTokenHandle != IntPtr.Zero) 
               ApiDefinitions.CloseHandle(userTokenHandle);
           _currentAquariusProcessId = (int)procInfo.dwProcessId; 
       } 
       catch (Exception ex) 
       { 
        MessageBox.Show(string.Format("Start Application failed, its path is {0} ,exception: {1}", appStartPath, ex.Message)); 
       }

因篇幅问题不能全部显示,请点此查看更多更全内容