using System.Runtime.InteropServices; using System; using System.ServiceProcess; using System.Collections.Generic; using SolidWorks.Interop.sldworks; namespace PluginLisener { public partial class PluginLisener : ServiceBase { public PluginLisener() { InitializeComponent(); } private List processIds = new List(); public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero; protected override void OnStart(string[] args) { var SwApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application"); int resp = 0; WTSSendMessage( WTS_CURRENT_SERVER_HANDLE, WTSGetActiveConsoleSessionId(),//获得当前显示的桌面所在的SessionID "title", "title".Length, "message", "message".Length, 0, 0, out resp, false); } public void StartScan() { } protected override void OnStop() { } [DllImport("kernel32.dll", SetLastError = true)] public static extern int WTSGetActiveConsoleSessionId(); [DllImport("wtsapi32.dll", SetLastError = true)] public static extern bool WTSSendMessage( //一个Session中的进程可以用WTSSendMessage,让另一个Session弹出对话框             IntPtr hServer, int SessionId, String pTitle, int TitleLength, String pMessage, int MessageLength, int Style, int Timeout, out int pResponse, bool bWait); } }