在VC++
中使用Windows Management Instrumentation( WMI ),我们可以找到SystemInfo,如系统名称和其他属性。
GetComputerName 的示例:
BOOL WINAPI GetComputerName(
_Out_ LPTSTR lpBuffer,
_Inout_ LPDWORD lpnSize
);
我的系统1热敏打印机和2个共享打印机连接了3台打印机,
如何获取有关离线打印机的信息? 如何根据打印机的状态对打印机进行分类/列表?
由于
答案 0 :(得分:1)
DWORD flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS;
DWORD bufsize, printerCount;
DWORD level = 2; //2 is for PRINTER_INFO_2
::EnumPrinters(flags, NULL, level, NULL, 0, &bufsize, &printerCount);
if (bufsize)
{
BYTE* buffer = new BYTE[bufsize];
::EnumPrinters(flags, NULL, level, buffer, bufsize, &bufsize, &printerCount);
if (bufsize && printerCount)
{
const PRINTER_INFO_2* info = (PRINTER_INFO_2*)buffer;
for (DWORD i = 0; i < printerCount; i++)
{
if (info->pServerName) cout << "pServerName: " << info->pServerName << endl;
if (info->pPrinterName) cout << "pPrinterName: " << info->pPrinterName << endl;
if (info->pShareName) cout << "pShareName: " << info->pShareName << endl;
if (info->pPortName) cout << "pPortName: " << info->pPortName << endl;
if (info->Attributes & PRINTER_ATTRIBUTE_LOCAL) cout << "[local]\n";
if (info->Attributes & PRINTER_ATTRIBUTE_NETWORK) cout << "[network]\n";
wcout << "status: " << info->Status << endl;
if (info->Status & PRINTER_STATUS_ERROR) cout << "status: error\n";
wcout << endl;
info++;
}
}
delete[] buffer;
}