DriveInfo 类的属性 C#USBDriveType 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 手机相机一般也识别为Removable 1打印机根本不会被视作"driver",也不会有盘符,哪里来的类型 你根本用GetDrivers都取不到,你得用wmi去取。 using System;using System.IO;using System.Management;using System.Windows.Forms;namespace 界面{ public partial class Form4 : Form { public Form4() { InitializeComponent(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void Form4_Load(object sender, EventArgs e) { SelectQuery selectQuery = new SelectQuery("select * from win32_logicaldisk"); ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery); foreach(ManagementObject disk in search.Get()) { comboBox1.Items.Add(disk["Name"].ToString()); } } private void btnCheck_Click(object sender, EventArgs e) { string DriveType; DriveInfo dinfo = new DriveInfo(comboBox1.Text); try { DriveType = dinfo.DriveType.ToString(); switch (DriveType) { case "Unknown": label2.Text = "未知设备"; break; case "NoRootDirectory": label2.Text = "这是未分区"; break; case "Removable": label2.Text = "这是可移动磁盘"; break; case "Fixed": label2.Text = "这是硬盘"; break; case "Network": label2.Text = "这是网络驱动器"; break; case "CDRom": label2.Text = "这是光驱"; break; } } catch { label2.Text = "未知类型"; } } }} SelectQuery进行WMI查询,是不是Select里面查的是所有驱动器的盘符,应该怎么改才能查到打印机的驱动 http://msdn.microsoft.com/zh-cn/library/system.io.driveinfo.drivetype.aspx 看看MSDN的 driveinfo这个类不行,那哪个类能识别出打印机之类的设备呢 1.windos API2.WMI比如:stringwmiSQL ="SELECT * FROM Win32_Printer";ManagementObjectCollectionprinters =newManagementObjectSearcher(wmiSQL).Get();driveinfo和printer不同 VS2008用C#开发Winform如何导出“带双层表头和大标题的列头”的datagridview到EXCEL中 c#中DataTable.DefaultView后数据丢失 网页数据抓取 想实现这样的效果,请前辈们指点一二 打开指定EXCEL文件 求一段c#如何操作oracle数据库的代码示例,包括连接,修改更新删除数据。 公司诚购买PDA源码,价格可以商量 请教高手: 用C#如何实现多人聊天程序?并且有声音提示.在线等待中.......... 有谁能帮我解释一下这段代码吗!!谢谢 散分 System.Data.SQLite错误 C#执行存储过程超时 但直接调用不用1秒
打印机根本不会被视作"driver",也不会有盘符,哪里来的类型
using System.IO;
using System.Management;
using System.Windows.Forms;
namespace 界面
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{ } private void Form4_Load(object sender, EventArgs e)
{
SelectQuery selectQuery = new SelectQuery("select * from win32_logicaldisk");
ManagementObjectSearcher search = new ManagementObjectSearcher(selectQuery);
foreach(ManagementObject disk in search.Get())
{
comboBox1.Items.Add(disk["Name"].ToString()); } } private void btnCheck_Click(object sender, EventArgs e)
{
string DriveType;
DriveInfo dinfo = new DriveInfo(comboBox1.Text);
try
{
DriveType = dinfo.DriveType.ToString();
switch (DriveType)
{
case "Unknown":
label2.Text = "未知设备";
break;
case "NoRootDirectory":
label2.Text = "这是未分区";
break;
case "Removable":
label2.Text = "这是可移动磁盘";
break;
case "Fixed":
label2.Text = "这是硬盘";
break;
case "Network":
label2.Text = "这是网络驱动器";
break;
case "CDRom":
label2.Text = "这是光驱";
break; } }
catch {
label2.Text = "未知类型";
} }
}
}
2.WMI
比如:
stringwmiSQL ="SELECT * FROM Win32_Printer";
ManagementObjectCollectionprinters =newManagementObjectSearcher(wmiSQL).Get();driveinfo和
printer不同