下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
// The initial C# code for the 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; namespace RobvanderWoude{ public class ListPrinters { 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_Printer" ); ArrayList printers = new ArrayList( ); foreach ( ManagementObject queryObj in searcher.Get( ) ) { printers.Add( queryObj["deviceid"] ); } printers.sort( ); foreach ( string printer in printers ) { Console.Writeline( printer ); } 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 ) { /* ListPrinters,Version 1.10 List all local printers on the specifIEd computer Usage: ListPRINTERS [ computername ] Where: 'computername' is the (optional) name of a remote computer (default if not specifIEd: local computer) Written by Rob van der Woude http://www.robvanderwoude.com */ 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 local printers 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" ); Console.Error.Writeline( "http://www.robvanderwoude.com" ); return 1; } }}
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的C#控制台列出当前所有可用的打印机列表全部内容,希望文章能够帮你解决C#控制台列出当前所有可用的打印机列表所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)