OfflineCommand.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using DiskAccessLibrary;
  6. using DiskAccessLibrary.LogicalDiskManager;
  7. using Utilities;
  8. namespace ISCSIConsole
  9. {
  10. public partial class Program
  11. {
  12. public static void OfflineCommand(string[] args)
  13. {
  14. if (args.Length > 1)
  15. {
  16. switch (args[1].ToLower())
  17. {
  18. case "disk":
  19. {
  20. if (m_selectedDisk != null)
  21. {
  22. if (m_selectedDisk is PhysicalDisk)
  23. {
  24. if (Environment.OSVersion.Version.Major >= 6)
  25. {
  26. bool isOnline = ((PhysicalDisk)m_selectedDisk).GetOnlineStatus();
  27. if (isOnline)
  28. {
  29. bool success = ((PhysicalDisk)m_selectedDisk).SetOnlineStatus(false, true);
  30. if (success)
  31. {
  32. Console.WriteLine("Disk has been taken offline.");
  33. }
  34. else
  35. {
  36. Console.WriteLine("Failed to take the disk offline.");
  37. }
  38. }
  39. else
  40. {
  41. Console.WriteLine("Disk is already offline.");
  42. }
  43. }
  44. else
  45. {
  46. Console.WriteLine("This command is only supported on Windows Vista and later.");
  47. }
  48. }
  49. }
  50. else
  51. {
  52. Console.WriteLine("No disk has been selected.");
  53. }
  54. break;
  55. }
  56. default:
  57. {
  58. Console.WriteLine("Invalid argument.");
  59. break;
  60. }
  61. }
  62. }
  63. else
  64. {
  65. Console.WriteLine("Invalid argument.");
  66. }
  67. }
  68. public static void OnlineCommand(string[] args)
  69. {
  70. if (args.Length > 1)
  71. {
  72. switch (args[1].ToLower())
  73. {
  74. case "disk":
  75. {
  76. if (m_selectedDisk != null)
  77. {
  78. if (m_selectedDisk is PhysicalDisk)
  79. {
  80. if (Environment.OSVersion.Version.Major >= 6)
  81. {
  82. bool isOnline = ((PhysicalDisk)m_selectedDisk).GetOnlineStatus();
  83. if (!isOnline)
  84. {
  85. bool success = ((PhysicalDisk)m_selectedDisk).SetOnlineStatus(true, true);
  86. if (success)
  87. {
  88. Console.WriteLine("Disk has been taken online.");
  89. }
  90. else
  91. {
  92. Console.WriteLine("Failed to take the disk online.");
  93. }
  94. }
  95. else
  96. {
  97. Console.WriteLine("Disk is already online.");
  98. }
  99. }
  100. else
  101. {
  102. Console.WriteLine("This command is only supported on Windows Vista and later.");
  103. }
  104. }
  105. }
  106. else
  107. {
  108. Console.WriteLine("No disk has been selected.");
  109. }
  110. break;
  111. }
  112. default:
  113. {
  114. Console.WriteLine("Invalid argument.");
  115. break;
  116. }
  117. }
  118. }
  119. else
  120. {
  121. Console.WriteLine("Invalid argument.");
  122. }
  123. }
  124. public static void HelpOffline()
  125. {
  126. Console.WriteLine();
  127. Console.WriteLine("OFFLINE DISK - Takes the selected disk offline.");
  128. }
  129. public static void HelpOnline()
  130. {
  131. Console.WriteLine();
  132. Console.WriteLine("ONLINE DISK - Takes the selected disk online.");
  133. }
  134. }
  135. }