Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

519 lines
19 KiB

  1. namespace WindowsApplication1
  2. {
  3. using System;
  4. using System.Drawing;
  5. using System.Collections;
  6. using System.ComponentModel;
  7. using System.Windows.Forms;
  8. using System.Data;
  9. /// <summary>
  10. /// Summary description for MainForm.
  11. /// </summary>
  12. public class MainForm : System.Windows.Forms.Form
  13. {
  14. /// <summary>
  15. /// Required designer variable.
  16. /// </summary>
  17. private System.ComponentModel.Container components=null;
  18. //The "Start a Process" button
  19. private System.Windows.Forms.Button btnProcess;
  20. //used to select and start a process
  21. private System.Windows.Forms.OpenFileDialog openFile;
  22. private System.Windows.Forms.Label label9;
  23. private System.Windows.Forms.Label label8;
  24. //Processes info listBox
  25. private System.Windows.Forms.ListBox lstPcs;
  26. //Running processes listBox
  27. private System.Windows.Forms.ListBox lstPcsRun;
  28. //Paused drivers listBox
  29. private System.Windows.Forms.ListBox lstDrvPaused;
  30. private System.Windows.Forms.Label label7;
  31. private System.Windows.Forms.Label label6;
  32. private System.Windows.Forms.Label label5;
  33. //Stopped drivers list
  34. private System.Windows.Forms.ListBox lstDrvStopped;
  35. //Running drivers list
  36. private System.Windows.Forms.ListBox lstDrvRun;
  37. //Close app. button
  38. private System.Windows.Forms.Button cmdClose;
  39. //Load data button
  40. private System.Windows.Forms.Button cmdLoadData;
  41. private System.Windows.Forms.TextBox txtMachineName;
  42. private System.Windows.Forms.Label label4;
  43. private System.Windows.Forms.Label label3;
  44. //Stopped services button
  45. private System.Windows.Forms.ListBox lstSrvStopped;
  46. private System.Windows.Forms.Label label2;
  47. //Paused services List
  48. private System.Windows.Forms.ListBox lstSrvPaused;
  49. private System.Windows.Forms.Label label1;
  50. //Running services list
  51. private System.Windows.Forms.ListBox lstSrvRun;
  52. private System.Windows.Forms.TabPage tabProcess;
  53. private System.Windows.Forms.TabPage tabDrivers;
  54. private System.Windows.Forms.TabPage tabServices;
  55. private System.Windows.Forms.TabControl tabControl1;
  56. //User classes :
  57. // ServiceControllerManager is in charge of the System Services management using the ServiceController component
  58. private ServiceControllerManager objSrvCtrlMgr=new ServiceControllerManager();
  59. //DriverControllerManager manage the System drivers via the ServiceController component
  60. private DriverControllerManager objDrvCtrlMgr = new DriverControllerManager();
  61. //ProcessControllerManager is destined to the control of the system Processes via the Process component
  62. private ProcessControllerManager objPcsCrtlMgr = new ProcessControllerManager();
  63. public MainForm()
  64. {
  65. InitializeComponent();
  66. }
  67. /// <summary>
  68. /// Clean up any resources being used.
  69. /// </summary>
  70. protected override void Dispose( bool disposing )
  71. {
  72. if( disposing )
  73. {
  74. if (components != null)
  75. {
  76. components.Dispose();
  77. }
  78. }
  79. base.Dispose( disposing );
  80. }
  81. #region Windows Form Designer generated code
  82. /// <summary>
  83. /// Required method for Designer support - do not modify
  84. /// the contents of this method with the code editor.
  85. /// </summary>
  86. private void InitializeComponent()
  87. {
  88. this.label8 = new System.Windows.Forms.Label();
  89. this.label9 = new System.Windows.Forms.Label();
  90. this.label4 = new System.Windows.Forms.Label();
  91. this.label5 = new System.Windows.Forms.Label();
  92. this.label6 = new System.Windows.Forms.Label();
  93. this.label7 = new System.Windows.Forms.Label();
  94. this.label1 = new System.Windows.Forms.Label();
  95. this.label2 = new System.Windows.Forms.Label();
  96. this.label3 = new System.Windows.Forms.Label();
  97. this.tabDrivers = new System.Windows.Forms.TabPage();
  98. this.lstDrvPaused = new System.Windows.Forms.ListBox();
  99. this.lstDrvStopped = new System.Windows.Forms.ListBox();
  100. this.lstDrvRun = new System.Windows.Forms.ListBox();
  101. this.lstSrvStopped = new System.Windows.Forms.ListBox();
  102. this.lstSrvPaused = new System.Windows.Forms.ListBox();
  103. this.tabControl1 = new System.Windows.Forms.TabControl();
  104. this.tabServices = new System.Windows.Forms.TabPage();
  105. this.lstSrvRun = new System.Windows.Forms.ListBox();
  106. this.tabProcess = new System.Windows.Forms.TabPage();
  107. this.lstPcs = new System.Windows.Forms.ListBox();
  108. this.lstPcsRun = new System.Windows.Forms.ListBox();
  109. this.cmdLoadData = new System.Windows.Forms.Button();
  110. this.openFile = new System.Windows.Forms.OpenFileDialog();
  111. this.cmdClose = new System.Windows.Forms.Button();
  112. this.btnProcess = new System.Windows.Forms.Button();
  113. this.txtMachineName = new System.Windows.Forms.TextBox();
  114. this.tabDrivers.SuspendLayout();
  115. this.tabControl1.SuspendLayout();
  116. this.tabServices.SuspendLayout();
  117. this.tabProcess.SuspendLayout();
  118. this.SuspendLayout();
  119. //
  120. // label8
  121. //
  122. this.label8.Location = new System.Drawing.Point(24, 8);
  123. this.label8.Name = "label8";
  124. this.label8.Size = new System.Drawing.Size(128, 16);
  125. this.label8.TabIndex = 2;
  126. this.label8.Text = "Running Process";
  127. //
  128. // label9
  129. //
  130. this.label9.Location = new System.Drawing.Point(264, 8);
  131. this.label9.Name = "label9";
  132. this.label9.Size = new System.Drawing.Size(128, 16);
  133. this.label9.TabIndex = 3;
  134. this.label9.Text = "Process Properties";
  135. //
  136. // label4
  137. //
  138. this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  139. this.label4.Location = new System.Drawing.Point(8, 416);
  140. this.label4.Name = "label4";
  141. this.label4.Size = new System.Drawing.Size(136, 16);
  142. this.label4.TabIndex = 1;
  143. this.label4.Text = "Machine Name";
  144. //
  145. // label5
  146. //
  147. this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  148. this.label5.Location = new System.Drawing.Point(16, 128);
  149. this.label5.Name = "label5";
  150. this.label5.Size = new System.Drawing.Size(152, 16);
  151. this.label5.TabIndex = 2;
  152. this.label5.Text = "Stopped Drivers";
  153. //
  154. // label6
  155. //
  156. this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  157. this.label6.Location = new System.Drawing.Point(16, 6);
  158. this.label6.Name = "label6";
  159. this.label6.Size = new System.Drawing.Size(144, 16);
  160. this.label6.TabIndex = 3;
  161. this.label6.Text = "Running Drivers";
  162. //
  163. // label7
  164. //
  165. this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  166. this.label7.Location = new System.Drawing.Point(16, 256);
  167. this.label7.Name = "label7";
  168. this.label7.Size = new System.Drawing.Size(152, 16);
  169. this.label7.TabIndex = 4;
  170. this.label7.Text = "Paused Drivers";
  171. //
  172. // label1
  173. //
  174. this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  175. this.label1.Location = new System.Drawing.Point(24, 16);
  176. this.label1.Name = "label1";
  177. this.label1.Size = new System.Drawing.Size(224, 16);
  178. this.label1.TabIndex = 1;
  179. this.label1.Text = "Running Services";
  180. //
  181. // label2
  182. //
  183. this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  184. this.label2.Location = new System.Drawing.Point(20, 241);
  185. this.label2.Name = "label2";
  186. this.label2.Size = new System.Drawing.Size(232, 16);
  187. this.label2.TabIndex = 3;
  188. this.label2.Text = "Paused Services";
  189. //
  190. // label3
  191. //
  192. this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  193. this.label3.Location = new System.Drawing.Point(21, 128);
  194. this.label3.Name = "label3";
  195. this.label3.Size = new System.Drawing.Size(177, 16);
  196. this.label3.TabIndex = 5;
  197. this.label3.Text = "Stopped Services";
  198. //
  199. // tabDrivers
  200. //
  201. this.tabDrivers.Controls.AddRange(new System.Windows.Forms.Control[] {
  202. this.lstDrvPaused,
  203. this.label7,
  204. this.label6,
  205. this.label5,
  206. this.lstDrvStopped,
  207. this.lstDrvRun});
  208. this.tabDrivers.Location = new System.Drawing.Point(4, 22);
  209. this.tabDrivers.Name = "tabDrivers";
  210. this.tabDrivers.Size = new System.Drawing.Size(453, 373);
  211. this.tabDrivers.TabIndex = 1;
  212. this.tabDrivers.Text = "Drivers";
  213. //
  214. // lstDrvPaused
  215. //
  216. this.lstDrvPaused.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  217. | System.Windows.Forms.AnchorStyles.Right);
  218. this.lstDrvPaused.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  219. this.lstDrvPaused.Location = new System.Drawing.Point(16, 280);
  220. this.lstDrvPaused.Name = "lstDrvPaused";
  221. this.lstDrvPaused.Size = new System.Drawing.Size(424, 82);
  222. this.lstDrvPaused.TabIndex = 5;
  223. //
  224. // lstDrvStopped
  225. //
  226. this.lstDrvStopped.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  227. | System.Windows.Forms.AnchorStyles.Right);
  228. this.lstDrvStopped.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  229. this.lstDrvStopped.Location = new System.Drawing.Point(16, 152);
  230. this.lstDrvStopped.Name = "lstDrvStopped";
  231. this.lstDrvStopped.Size = new System.Drawing.Size(424, 95);
  232. this.lstDrvStopped.TabIndex = 1;
  233. //
  234. // lstDrvRun
  235. //
  236. this.lstDrvRun.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  237. | System.Windows.Forms.AnchorStyles.Right);
  238. this.lstDrvRun.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  239. this.lstDrvRun.Location = new System.Drawing.Point(16, 26);
  240. this.lstDrvRun.Name = "lstDrvRun";
  241. this.lstDrvRun.Size = new System.Drawing.Size(424, 95);
  242. this.lstDrvRun.TabIndex = 0;
  243. //
  244. // lstSrvStopped
  245. //
  246. this.lstSrvStopped.Anchor = System.Windows.Forms.AnchorStyles.None;
  247. this.lstSrvStopped.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  248. this.lstSrvStopped.Location = new System.Drawing.Point(18, 152);
  249. this.lstSrvStopped.Name = "lstSrvStopped";
  250. this.lstSrvStopped.Size = new System.Drawing.Size(416, 82);
  251. this.lstSrvStopped.TabIndex = 4;
  252. //
  253. // lstSrvPaused
  254. //
  255. this.lstSrvPaused.Anchor = System.Windows.Forms.AnchorStyles.None;
  256. this.lstSrvPaused.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  257. this.lstSrvPaused.Location = new System.Drawing.Point(16, 272);
  258. this.lstSrvPaused.Name = "lstSrvPaused";
  259. this.lstSrvPaused.Size = new System.Drawing.Size(416, 95);
  260. this.lstSrvPaused.TabIndex = 2;
  261. //
  262. // tabControl1
  263. //
  264. this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  265. | System.Windows.Forms.AnchorStyles.Right);
  266. this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
  267. this.tabServices,
  268. this.tabDrivers,
  269. this.tabProcess});
  270. this.tabControl1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  271. this.tabControl1.Location = new System.Drawing.Point(0, 9);
  272. this.tabControl1.Name = "tabControl1";
  273. this.tabControl1.SelectedIndex = 0;
  274. this.tabControl1.Size = new System.Drawing.Size(461, 399);
  275. this.tabControl1.TabIndex = 0;
  276. this.tabControl1.Text = "tabControl1";
  277. //
  278. // tabServices
  279. //
  280. this.tabServices.Controls.AddRange(new System.Windows.Forms.Control[] {
  281. this.label3,
  282. this.lstSrvStopped,
  283. this.label2,
  284. this.lstSrvPaused,
  285. this.label1,
  286. this.lstSrvRun});
  287. this.tabServices.Location = new System.Drawing.Point(4, 22);
  288. this.tabServices.Name = "tabServices";
  289. this.tabServices.Size = new System.Drawing.Size(453, 373);
  290. this.tabServices.TabIndex = 0;
  291. this.tabServices.Text = "Services";
  292. //
  293. // lstSrvRun
  294. //
  295. this.lstSrvRun.Anchor = System.Windows.Forms.AnchorStyles.None;
  296. this.lstSrvRun.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  297. this.lstSrvRun.Location = new System.Drawing.Point(24, 40);
  298. this.lstSrvRun.Name = "lstSrvRun";
  299. this.lstSrvRun.Size = new System.Drawing.Size(416, 82);
  300. this.lstSrvRun.TabIndex = 0;
  301. //
  302. // tabProcess
  303. //
  304. this.tabProcess.Controls.AddRange(new System.Windows.Forms.Control[] {
  305. this.label9,
  306. this.label8,
  307. this.lstPcs,
  308. this.lstPcsRun});
  309. this.tabProcess.Location = new System.Drawing.Point(4, 22);
  310. this.tabProcess.Name = "tabProcess";
  311. this.tabProcess.Size = new System.Drawing.Size(453, 373);
  312. this.tabProcess.TabIndex = 2;
  313. this.tabProcess.Text = "Process";
  314. //
  315. // lstPcs
  316. //
  317. this.lstPcs.Anchor = System.Windows.Forms.AnchorStyles.None;
  318. this.lstPcs.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  319. this.lstPcs.Location = new System.Drawing.Point(224, 36);
  320. this.lstPcs.MultiColumn = true;
  321. this.lstPcs.Name = "lstPcs";
  322. this.lstPcs.ScrollAlwaysVisible = true;
  323. this.lstPcs.Size = new System.Drawing.Size(224, 329);
  324. this.lstPcs.TabIndex = 1;
  325. //
  326. // lstPcsRun
  327. //
  328. this.lstPcsRun.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  329. this.lstPcsRun.Location = new System.Drawing.Point(8, 36);
  330. this.lstPcsRun.Name = "lstPcsRun";
  331. this.lstPcsRun.Size = new System.Drawing.Size(200, 329);
  332. this.lstPcsRun.Sorted = true;
  333. this.lstPcsRun.TabIndex = 0;
  334. //
  335. // cmdLoadData
  336. //
  337. this.cmdLoadData.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  338. this.cmdLoadData.Location = new System.Drawing.Point(16, 448);
  339. this.cmdLoadData.Name = "cmdLoadData";
  340. this.cmdLoadData.Size = new System.Drawing.Size(120, 24);
  341. this.cmdLoadData.TabIndex = 3;
  342. this.cmdLoadData.Text = "&Load Data";
  343. this.cmdLoadData.Click += new System.EventHandler(this.cmdLoadData_Click);
  344. //
  345. // openFile
  346. //
  347. this.openFile.FileOk += new System.ComponentModel.CancelEventHandler(this.openFile_FileOk);
  348. //
  349. // cmdClose
  350. //
  351. this.cmdClose.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  352. this.cmdClose.Location = new System.Drawing.Point(296, 448);
  353. this.cmdClose.Name = "cmdClose";
  354. this.cmdClose.Size = new System.Drawing.Size(136, 24);
  355. this.cmdClose.TabIndex = 4;
  356. this.cmdClose.Text = "&Close Application";
  357. this.cmdClose.Click += new System.EventHandler(this.cmdClose_Click);
  358. //
  359. // btnProcess
  360. //
  361. this.btnProcess.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  362. this.btnProcess.Location = new System.Drawing.Point(152, 448);
  363. this.btnProcess.Name = "btnProcess";
  364. this.btnProcess.Size = new System.Drawing.Size(128, 24);
  365. this.btnProcess.TabIndex = 5;
  366. this.btnProcess.Text = "&Start a Process";
  367. this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click);
  368. //
  369. // txtMachineName
  370. //
  371. this.txtMachineName.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
  372. this.txtMachineName.Location = new System.Drawing.Point(152, 416);
  373. this.txtMachineName.Name = "txtMachineName";
  374. this.txtMachineName.Size = new System.Drawing.Size(280, 20);
  375. this.txtMachineName.TabIndex = 2;
  376. this.txtMachineName.Text = "";
  377. //
  378. // MainForm
  379. //
  380. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  381. this.ClientSize = new System.Drawing.Size(464, 485);
  382. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  383. this.btnProcess,
  384. this.cmdClose,
  385. this.cmdLoadData,
  386. this.txtMachineName,
  387. this.label4,
  388. this.tabControl1});
  389. this.Name = "MainForm";
  390. this.Text = "Process Controller";
  391. this.tabDrivers.ResumeLayout(false);
  392. this.tabControl1.ResumeLayout(false);
  393. this.tabServices.ResumeLayout(false);
  394. this.tabProcess.ResumeLayout(false);
  395. this.ResumeLayout(false);
  396. }
  397. #endregion
  398. // The event assigned to the openFile control.
  399. protected void openFile_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
  400. {
  401. if(objPcsCrtlMgr!=null)
  402. {
  403. try
  404. {
  405. //try to start a new process using the Process component
  406. objPcsCrtlMgr.StartProcess(openFile.FileName);
  407. }
  408. catch
  409. {
  410. //Its possible since one might not have the permission to start a process on a certain machine
  411. MessageBox.Show("The process: " + openFile.FileName + " cannot be started !");
  412. }
  413. }
  414. }
  415. // launches the OpenFile dialog
  416. protected void btnProcess_Click(object sender, System.EventArgs e)
  417. {
  418. openFile.ShowDialog();
  419. }
  420. // Exit the App
  421. protected void cmdClose_Click(object sender, System.EventArgs e)
  422. {
  423. //Make the Window "Fade away"
  424. for(double d=1.0d; d> 0d; d-=0.2d)
  425. {
  426. System.Threading.Thread.Sleep(50);
  427. Application.DoEvents();
  428. this.Opacity=d;
  429. this.Refresh();
  430. }
  431. Environment.Exit(0);
  432. }
  433. // Call the method that fills up the services, drivers and processes
  434. protected void cmdLoadData_Click(object sender, System.EventArgs e)
  435. {
  436. btnProcess.Enabled=true;
  437. LoadData();
  438. }
  439. // Loading all services, Drivers and Processes running on the selected machine
  440. public void LoadData()
  441. {
  442. string tmpMachineName= GetMachineName();
  443. //clear up the serviceManager
  444. if(objSrvCtrlMgr!=null)
  445. objSrvCtrlMgr.Clear();
  446. objSrvCtrlMgr=null;
  447. objSrvCtrlMgr=new ServiceControllerManager(lstSrvRun,lstSrvStopped,lstSrvPaused,tmpMachineName);
  448. //Clear up the driver manager
  449. if(objDrvCtrlMgr!=null)
  450. objDrvCtrlMgr.Clear();
  451. objDrvCtrlMgr=null;
  452. objDrvCtrlMgr=new DriverControllerManager(lstDrvRun,lstDrvStopped,lstDrvPaused,tmpMachineName);
  453. //Clear the process manager
  454. if(objPcsCrtlMgr!=null)
  455. objPcsCrtlMgr.Clear();
  456. objPcsCrtlMgr=null;
  457. objPcsCrtlMgr=new ProcessControllerManager(lstPcsRun,lstPcs,tmpMachineName);
  458. }
  459. // returns the name of the local machine
  460. public string GetLocalMachine()
  461. {
  462. return System.Environment.MachineName;
  463. }
  464. // check wheter the selected machine exists in the Domain
  465. // you might want to change this to more complex code for machine name check
  466. public string GetMachineName()
  467. {
  468. if(txtMachineName.Text.Equals(""))
  469. //machineName field is empty, take the local machine
  470. {
  471. txtMachineName.Text=GetLocalMachine();
  472. txtMachineName.Focus();
  473. }
  474. return txtMachineName.Text;
  475. }
  476. //Application main entry point
  477. [STAThread]
  478. public static void Main(string[] args)
  479. {
  480. Application.Run(new MainForm());
  481. }
  482. }
  483. }