Winform 判断打印机是否可用

ManagementScope 类在System.Management(在 system.management.dll 中)

public class CheckPrinterState
    {

        public static bool CheckPrinter(string printerName1)
        {

            ManagementScope scope = new ManagementScope(@"\root\cimv2");
            scope.Connect();

            // Select Printers from WMI Object Collections
            ManagementObjectSearcher searcher = new
             ManagementObjectSearcher("SELECT * FROM Win32_Printer");

            string printerName = "";
            foreach (ManagementObject printer in searcher.Get())
            {
                printerName = printer["Name"].ToString().ToLower();
                if (printerName.IndexOf(printerName1.ToLower()) > -1)
                {

                    if (printer["WorkOffline"].ToString().ToLower().Equals("true"))
                    {
                        return false;
                        // printer is offline by user

                    }
                    else
                    {
                        // printer is not offline

                        return true;
                    }
                }
            }
            return false;
        }
    }
  

  

Winform 判断打印机是否可用

时间: 2024-08-14 19:43:16

Winform 判断打印机是否可用的相关文章

Winform 判断打印机是否可用,实现设置默认打印机功能

Winform 判断打印机是否可用,实现设置默认打印机功能 http://www.cnblogs.com/zfanlong1314/p/3878563.html

Winform判断EventHandler是否已经添加

斜体部分替换成自己需要的 private bool HasValueChangedEventHandler(DateTimePicker b) { FieldInfo f1 = typeof(DateTimePicker).GetField("onValueChanged", BindingFlags.Instance | BindingFlags.NonPublic); var handler = (EventHandler)f1.GetValue(b); return handle

[WinForm]使关闭按钮不可用或隐藏

关键代码: /// <summary> /// 代码源自:http://www.codeproject.com/Articles/20379/Disabling-Close-Button-on-Forms /// </summary> private const int CP_NOCLOSE_BUTTON = 0x200; protected override CreateParams CreateParams { get { CreateParams _createParams

android 中判断WiFi是否可用的可靠方法 ,android 是否联网

http://alex-yang-xiansoftware-com.iteye.com/blog/619841 在一些程序中,需要从网上下载数据,或者通过其他方式对网络产生流量,当wifi不可用时应该提示用户wifi已经不可用了,是否继续,因为如果wifi掉了,那么程序可能采用3G卡或其他的收费的渠道使用网络,会导在不知情时产生大量的上网费用.通过查看android的api可使用下列方法进行判断: public static boolean isWiFiActive(Context inCont

Reachability用于在任何地方判断网络是否可用

#import <UIKit/UIKit.h> #import "Reachability.h" @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) Reachability *reach; @end #import "AppDe

Winform判断是否已启动

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Net; namespace Client { static class Program { /// <summary> /// 应用程序的主入口点. /// </summary>

iOS 兼容性 判断新版本函数可用

在关于ios兼容性问题的时候,可能应用是4.0那么5.0新的函数就不能调用 : 我们可以判断该函数是否能调用来判断: if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) { //如果版本支持这个函数则调用 这个函数是5.0之后的用来设置navigationBar的背景图片 5.0之前不支持 [self.navigationCont

Windows下bat脚本判断端口是否可用

环境: 一台服务器上用了portmap做了端口转发,但是这个程序经常会跪,需要人工去重启 解决思路: 通过bat来监控程序端口,不通时候自动重启,如果端口可用,则会出来telnet进程,若端口不可用,则不会出现telnet进程.根据进程是否存在来判断端口是否可用,因为telnet通的话,会直接跳转窗口,无回显,所以需要telnet时候启用新窗口. 方法二 @echo off title PortMap存活监控!!! :again set ip=127.0.0.1 set port=8080 st

C#Winform判断文件和路径是否存在

//选择文件夹 FolderBrowserDialog dia = new FolderBrowserDialog(); if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filePath = dia.SelectedPath; Directory.Exists(filePath);//判断文件夹是否存在 } //选择文件 OpenFileDialog dia = new OpenFileDialog()