[C#] C#检测光驱里的光盘是否已经加载 →→→→→进入此内容的聊天室

来自 , 2020-03-03, 写在 C#, 查看 128 次.
URL http://www.code666.cn/view/4bb948d5
  1. using System;
  2. using System.Management;
  3.  
  4. class App
  5. {
  6.   public static void Main()
  7.   {
  8.     SelectQuery query = new SelectQuery( "select * from win32_logicaldisk where drivetype=5" );
  9.     ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
  10.  
  11.     foreach( ManagementObject mo in searcher.Get() )
  12.     {
  13.       // If both properties are null I suppose there's no CD
  14.       if( ( mo["volumename"] != null ) || ( mo["volumeserialnumber"] != null ) )
  15.       {
  16.         Console.WriteLine( "CD is named: {0}", mo["volumename"] );
  17.         Console.WriteLine( "CD Serial Number: {0}", mo["volumeserialnumber"] );
  18.       }
  19.       else
  20.       {
  21.         Console.WriteLine( "No CD in Unit" );
  22.       }
  23.     }
  24.  
  25.     // Here to stop app from closing
  26.     Console.WriteLine( "\nPress Return to exit." );
  27.     Console.Read();
  28.   }
  29. }
  30. //csharp/4214

回复 "C#检测光驱里的光盘是否已经加载"

这儿你可以回复上面这条便签

captcha