WindowsAccountModel.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Azylee.Core.ProcessUtils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. namespace Azylee.Core.WindowsUtils.AdminUtils
  8. {
  9. /// <summary>
  10. /// Windows 系统账号信息
  11. /// </summary>
  12. public class WindowsAccountModel
  13. {
  14. /// <summary>
  15. /// 域
  16. /// </summary>
  17. public string Domain { get; set; }
  18. /// <summary>
  19. /// 账号
  20. /// </summary>
  21. public string UserName { get; set; }
  22. /// <summary>
  23. /// 密码
  24. /// </summary>
  25. public string Password { get; set; }
  26. /// <summary>
  27. /// 构造函数
  28. /// </summary>
  29. /// <param name="domain"></param>
  30. /// <param name="username"></param>
  31. /// <param name="password"></param>
  32. public WindowsAccountModel(string domain = "", string username = "", string password = "")
  33. {
  34. Domain = domain;
  35. UserName = username;
  36. Password = password;
  37. }
  38. /// <summary>
  39. /// 验证账号密码正确性
  40. /// </summary>
  41. public bool Check()
  42. {
  43. try
  44. {
  45. Process process = ProcessStarter.NewProcess(
  46. exe: "cmd.exe",
  47. domain: Domain,
  48. username: UserName,
  49. password: Password);
  50. bool flag = process.Start();
  51. process.Kill();
  52. return flag;
  53. }
  54. catch { return false; }
  55. }
  56. /// <summary>
  57. /// 验证账号密码为管理员账号
  58. /// </summary>
  59. /// <returns></returns>
  60. public bool CheckAdmin(string password)
  61. {
  62. return AdminTool.CheckPassword(password);
  63. }
  64. }
  65. }