Shut down hệ thống bằng C

2 176 0
Shut down hệ thống bằng C

Đang tải... (xem toàn văn)

Thông tin tài liệu

Shut down hệ thống bằng C# Cập nhật: 27/8/2008 với no comments Xếp trong: Lập trình, C# Đoạn mã sau đây dùng để shut down hệ điều hành sử dụng assembly System.Management. Lưu ý nó sẽ không thực hiện được nếu trước đó đã có phân quyền bảo mật. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; . Đoạn mã sau đây dùng để shut down hệ điều hành sử dụng assembly System.Management. Lưu ý nó sẽ không thực hiện được nếu trước đó đã có phân quyền bảo mật. view plain print ? 1. using System; 2. using System.Collections.Generic; 3. using System.ComponentModel; 4. using System.Data; 5. using System.Drawing; 6. using System.Text; 7. using System.Windows.Forms; 8. // Remember to add a reference to the System.Management assembly 9. using System.Management; 10. namespace ShutDown 11. { 12. public partial class Form1 : Form 13. { 14. public Form1() 15. { 16. InitializeComponent(); 17. } 18. private void btnShutDown_Click(object sender, EventArgs e) 19. { 20. ManagementBaseObject mboShutdown = null; 21. ManagementClass mcWin32 = new ManagementClass("Win32_OperatingS ystem"); 22. mcWin32.Get(); 23. // You can't shutdown without security privileges 24. mcWin32.Scope.Options.EnablePrivileges = true; 25. ManagementBaseObject mboShutdownParams = mcWin32.GetMethodPara meters("Win32Shutdown"); 26. // Flag 1 means we want to shut down the system 27. mboShutdownParams["Flags"] = "1"; 28. mboShutdownParams["Reserved"] = "0"; 29. foreach (ManagementObject manObj in mcWin32.GetInstances()) 30. { 31. mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdo wnParams, null); 32. } 33. } 34. } 35. } . Shut down hệ thống bằng C# C p nhật: 27/8/2008 với no comments Xếp trong: Lập trình, C# Đoạn mã sau đây dùng để shut down hệ điều hành sử. InitializeComponent(); 17. } 18. private void btnShutDown_Click(object sender, EventArgs e) 19. { 20. ManagementBaseObject mboShutdown = null; 21. ManagementClass

Ngày đăng: 06/11/2013, 05:15

Tài liệu cùng người dùng

Tài liệu liên quan