最新国产好看的视频,伊人天堂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;
  }
 }
}

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

相關(guān)文章

最新評(píng)論

宜黄县| 黄平县| 留坝县| 崇阳县| 于田县| 治多县| 泾源县| 石家庄市| 墨玉县| 阿拉善左旗| 响水县| 广德县| 兰坪| 平罗县| 洱源县| 青州市| 西盟| 石嘴山市| 榕江县| 威海市| 通州区| 临夏县| 泗水县| 城固县| 栾城县| 清涧县| 浦东新区| 英山县| 合川市| 平乡县| 青阳县| 凤冈县| 洛浦县| 肃北| 阿图什市| 三明市| 忻州市| 张家港市| 溧阳市| 桦甸市| 青河县|