最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#返回當(dāng)前系統(tǒng)所有可用驅(qū)動(dòng)器符號(hào)的方法

 更新時(shí)間:2015年04月18日 12:24:59   作者:work24  
這篇文章主要介紹了C#返回當(dāng)前系統(tǒng)所有可用驅(qū)動(dòng)器符號(hào)的方法,涉及C#操作系統(tǒng)硬件驅(qū)動(dòng)的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了C#返回當(dāng)前系統(tǒng)所有可用驅(qū)動(dòng)器符號(hào)的方法。分享給大家供大家參考。具體如下:

// The initial C# code for the "plain" WMI query was generated by
// WMI Code Generator, Version 5.00, //http://www.robvanderwoude.com/wmigen.php
using System;
using System.Management;
using System.Collections.Generic;
namespace RobvanderWoude
{
 public class ListDrives
 {
  public static int Main( string[] args )
  {
   try
   {
    string computer = string.Empty;
    #region Command line parsing
    // Only 1 optional argument allowed: a remote computer name
    if ( args.Length > 1 )
    {
     throw new Exception( "Invalid command line arguments" );
    }
    if ( args.Length == 1 )
    {
     // We'll display a 'friendly' message if help was requested
     if ( args[0].StartsWith( "/" ) || args[0].StartsWith( "-" ) )
     {
      switch ( args[0].ToUpper( ) )
      {
       case "/?":
       case "-?":
       case "/H":
       case "-H":
       case "--H":
       case "/HELP":
       case "-HELP":
       case "--HELP":
        return WriteError( string.Empty );
       default:
        return WriteError( "Invalid command line argument" );
      }
     }
     else
     {
      computer = "\\\\" + args[0] + "\\";
     }
    }
    #endregion
    string wmins = computer + "root\\CIMV2";
    ManagementObjectSearcher searcher = new ManagementObjectSearcher( wmins, "SELECT * FROM Win32_LogicalDisk" );
    List<string> drives = new List<string>( );
    foreach ( ManagementObject queryObj in searcher.Get( ) )
    {
     drives.Add( queryObj["DeviceID"].ToString( ) );
    }
    drives.Sort( );
    string drivelist = "";
    foreach ( string drive in drives )
    {
     drivelist += ( drive + " " );
    }
    Console.WriteLine( drivelist.Trim( ) );
    return 0;
   }
   catch ( Exception e )
   {
    return WriteError( e );
   }
  }
  public static int WriteError( Exception e )
  {
   return WriteError( e == null ? null : e.Message );
  }
  public static int WriteError( string errorMessage )
  { 
   string fullpath = Environment.GetCommandLineArgs( ).GetValue( 0 ).ToString( );
   string[] program = fullpath.Split( '\\' );
   string exename = program[program.GetUpperBound( 0 )];
   exename = exename.Substring( 0, exename.IndexOf( '.' ) );
   if ( string.IsNullOrEmpty( errorMessage ) == false )
   {
    Console.Error.WriteLine( );
    Console.ForegroundColor = ConsoleColor.Red;
    Console.Error.Write( "ERROR: " );
    Console.ForegroundColor = ConsoleColor.White;
    Console.Error.WriteLine( errorMessage );
    Console.ResetColor( );
   }
   Console.Error.WriteLine( );
   Console.Error.WriteLine( exename + ", Version 1.10" );
   Console.Error.WriteLine( "List all drive letters in use on the specified computer" );
   Console.Error.WriteLine( );
   Console.Error.Write( "Usage: " );
   Console.ForegroundColor = ConsoleColor.White;
   Console.Error.Write( exename.ToUpper( ) );
   Console.Error.WriteLine( " [ computername ]" );
   Console.ResetColor( );
   Console.Error.WriteLine( );
   Console.Error.WriteLine( "Where: 'computername' is the (optional) name of a remote computer" );
   Console.Error.WriteLine( " (default if not specified: local computer)" );
   Console.Error.WriteLine( );
   Console.Error.WriteLine( "Written by Rob van der Woude" );
   return 1;
  }
 }
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

东丽区| 绍兴县| 天祝| 江口县| 嘉定区| 崇阳县| 丽江市| 双柏县| 石楼县| 宝清县| 建湖县| 孙吴县| 辽阳市| 泰来县| 阿拉善右旗| 鞍山市| 九台市| 阳原县| 嘉定区| 灵石县| 吉木萨尔县| 临城县| 友谊县| 金塔县| 沁水县| 赤水市| 新乡市| 孝义市| 林芝县| 祥云县| 龙海市| 鄂尔多斯市| 盐山县| 永顺县| 五台县| 凯里市| 太原市| 汉寿县| 静海县| 长汀县| 思茅市|