最近把公司用的电脑重装了一下,期间用到了驱动精灵,驱动精灵把电脑的全方面信息都显示出来了,让人有种一目了然的感觉,为什么我不自己也写个呢?虽然显示的数据不一定有驱动精灵全单至少是我自己写的,不是吗?
软件写好后,看着显示出来的电脑信息虽然不是很全但是基本信息都有,普通人就够了。这时我又想起了一件事 ,每天上班第一件事是开电脑,第二件事就是打开VS(我的是vs2012),既然每天都固定要做为什么不让它开机就启动呢?于是我结合每天打开vs2012的命令上网搜了些资料完成了此功能,以下是截图,虽然丑了点:
2 private void btnReboot_Click(object sender, EventArgs e)
3 {
4 OperatingSystemControl("重启", "Reboot", new object[] { ComputerStatus.Reboot });
5 }
6
7 private void btnShutDown_Click(object sender, EventArgs e)
8 {
9 OperatingSystemControl("关机", "ShutDown", new object[] { ComputerStatus.Shutdown });
10 }
11
12
13 public void OperatingSystemControl(string word, string cmd, object[] prams)
14 {
15 DialogResult result = MessageBox.Show("确定要" + word + "吗?", "请确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
16 if (result == DialogResult.Yes)
17 {
18 ManagementClass mo = new ManagementClass("Win32_OperatingSystem");
19 mo.Scope.Options.EnablePrivileges = true;
20 foreach (ManagementObject n in mo.GetInstances())
21 {
22 n.InvokeMethod(cmd, prams);
23 }
24 mo.Dispose();
25 }
26 }
27
28 private void btnLogoff_Click(object sender, EventArgs e)
29 {
30 OperatingSystemControl("注销", "Win32Shutdown", new object[] { ComputerStatus.LogOff });
31 }
32
33 private void btnForcedLogoff_Click(object sender, EventArgs e)
34 {
35 OperatingSystemControl("强制注销", "Win32Shutdown", new object[] { ComputerStatus.ForcedLogOff });
36 }
37
38 private void btnForcedReboot_Click(object sender, EventArgs e)
39 {
40 OperatingSystemControl("强制重启", "Win32Shutdown", new object[] { ComputerStatus.ForcedReboot });
41 }
42
43 private void btnForcedShutDown_Click(object sender, EventArgs e)
44 {
45 OperatingSystemControl("强制关机", "Win32Shutdown", new object[] { ComputerStatus.ForcedShutdown });
46 }
47
48 private void btnPoweroff_Click(object sender, EventArgs e)
49 {
50 OperatingSystemControl("关闭电源", "Win32Shutdown", new object[] { ComputerStatus.PowerOff });
51 }
52
53 private void btnFocedPoweroff_Click(object sender, EventArgs e)
54 {
55 OperatingSystemControl("强制关闭电源", "Win32Shutdown", new object[] { ComputerStatus.ForcedPowerOff });
56 }
57 #endregion
1 #region VS操作
2 private void btnStartiPush_Click(object sender, EventArgs e)
3 {
4 //Process p = new Process();
5 //p.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe";
6 //p.StartInfo.Arguments = string.Format("/command File.OpenFile {0}", @"E:\Work\iPush.sln"); //設定程式執行參數
7 //p.StartInfo.UseShellExecute = false; //關閉Shell的使用
8 //p.StartInfo.RedirectStandardInput = true; //重定向標準輸入
9 //p.StartInfo.RedirectStandardOutput = true; //重定向標準輸出
10 //p.StartInfo.RedirectStandardError = true; //重定向錯誤輸出
11 //p.StartInfo.CreateNoWindow = true; //設置不顯示窗口
12
13 //p.Start(); //啟動
14
15 StartProject(cbProjects.SelectedValue.ToString());
16 }
17 public void StartProject(string projectUrl)
18 {
19 Process p = new Process();
20 p.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe";
21 p.StartInfo.Arguments = string.Format("{0}", projectUrl); //設定程式執行參數
22 p.StartInfo.UseShellExecute = false; //關閉Shell的使用
23 p.StartInfo.RedirectStandardInput = true; //重定向標準輸入
24 p.StartInfo.RedirectStandardOutput = true; //重定向標準輸出
25 p.StartInfo.RedirectStandardError = true; //重定向錯誤輸出
26 p.StartInfo.CreateNoWindow = true; //設置不顯示窗口
27
28 p.Start(); //啟動
29 }
30 private void btnChoiseFile_Click(object sender, EventArgs e)
31 {
32 OpenFileDialog file = new OpenFileDialog();
33 if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
34 {
35 string fileUrl = file.FileName;
36 string type = fileUrl.Substring(fileUrl.LastIndexOf(‘.‘));
37 if (type == ".sln")
38 {
39 MessageBox.Show(file.SafeFileName);
40 //StartProject(fileUrl);
41 XmlDocument doc = new XmlDocument();
42 doc.Load("Project.xml");
43 XmlNode node = doc.SelectSingleNode("projects");
44 XmlElement xe1 = doc.CreateElement("project");
45 xe1.SetAttribute("id", file.SafeFileName.Substring(0, file.SafeFileName.LastIndexOf(‘.‘)));
46 //xe1.SetAttribute("name", file.SafeFileName.Substring(0, file.SafeFileName.LastIndexOf(‘.‘)));
47 //xe1.SetAttribute("path", fileUrl);
48 XmlElement xesub1 = doc.CreateElement("name");
49 xesub1.InnerText = file.SafeFileName.Substring(0, file.SafeFileName.LastIndexOf(‘.‘));
50 xe1.AppendChild(xesub1);
51 XmlElement xesub2 = doc.CreateElement("path");
52 xesub2.InnerText = fileUrl;
53 xe1.AppendChild(xesub2);
54 node.AppendChild(xe1);
55 doc.Save("Project.xml");
56
57 initProjects();
58 }
59 }
60 else
61 {
62 MessageBox.Show("false");
63 }
64 }
65
66 #endregion