通过命令方式 TCHAR szFetCmd[] = _T("wmic baseboard get serialnumber"); 可以有:

查找主板厂商和型号
wmic BaseBoard get Manufacturer
wmic BaseBoard get Product

先决条件: a. 启动Windows Management Instrumentation服务,开放TCP135端口。 b. 本地安全策略的“网络访问: 本地帐户的共享和安全模式”应设为“经典-本地用户以自己的身份验证”。

  1. wmic /node:"192.168.1.20" /user:"domain\administrator" /password:"123456"

2.【硬件管理】:

获取磁盘资料: wmic DISKDRIVE get deviceid,Caption,size,InterfaceType 获取分区资料: wmic LOGICALDISK get name,Description,filesystem,size,freespace 获取CPU资料: wmic cpu get name,addresswidth,processorid 获取主板资料: wmic BaseBoard get Manufacturer,Product,Version,SerialNumber 获取内存数: wmic memlogical get totalphysicalmemory 获得品牌机的序列号: wmic csproduct get IdentifyingNumber 获取声卡资料: wmic SOUNDDEV get ProductName 获取屏幕分辨率 wmic DESKTOPMONITOR where Status='ok' get ScreenHeight,ScreenWidth

  1. PROCESS【进程管理】:

列出进程 wmic process list brief (Full显示所有、Brief显示摘要、Instance显示实例、Status显示状态)

wmic 获取进程路径: wmic process where name="jqs.exe" get executablepath

wmic 创建新进程 wmic process call create notepad wmic process call create "C:\Program Files\Tencent\QQ\QQ.exe" wmic process call create "shutdown.exe -r -f -t 20"

wmic 删除指定进程: wmic process where name="qq.exe" call terminate wmic process where processid="2345" delete wmic process 2345 call terminate

wmic 删除可疑进程 wmic process where "name='explorer.exe' and executablepath<>'%SystemDrive%\windows\explorer.exe'" delete wmic process where "name='svchost.exe' and ExecutablePath<>'C:\WINDOWS\system32\svchost.exe'" call Terminate

  1. USERACCOUNT【账号管理】:

更改当前用户名 WMIC USERACCOUNT where "name='%UserName%'" call rename newUserName WMIC USERACCOUNT create /?

  1. SHARE【共享管理】:

建立共享 WMIC SHARE CALL Create "","test","3","TestShareName","","c:\test",0 (可使用 WMIC SHARE CALL Create /? 查看create后的参数类型)

删除共享 WMIC SHARE where name="C$" call delete WMIC SHARE where path='c:\test' delete

  1. SERVICE【服务管理】:

更改telnet服务启动类型[Auto|Disabled|Manual] wmic SERVICE where name="tlntsvr" set startmode="Auto"

运行telnet服务 wmic SERVICE where name="tlntsvr" call startservice

停止ICS服务 wmic SERVICE where name="ShardAccess" call stopservice

删除test服务 wmic SERVICE where name="test" call delete

  1. FSDIR【目录管理】

列出c盘下名为test的目录 wmic FSDIR where "drive='c:' and filename='test'" list 删除c:\good文件夹 wmic fsdir "c:\test" call delete 重命名c:\test文件夹为abc wmic fsdir "c:\test" rename "c:\abc" wmic fsdir where (name='c:\test') rename "c:\abc" 复制文件夹 wmic fsdir where name='d:\test' call copy "c:\test"

7.datafile【文件管理】

重命名 wmic datafile "c:\test.txt" call rename c:\abc.txt

8.【任务计划】: wmic job call create "notepad.exe",0,0,true,false,********154800.000000+480 wmic job call create "explorer.exe",0,0,1,0,********154600.000000+480

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <windows.h>

BOOL GetMainBoardInfoByCmd(char* & lpszBaseBoard)
{
	const long COMMAND_SIZE = 1020; // Command line output buffer
	const DWORD WAIT_TIME = 500; // INFINITE

								 // The command to get mainboard serial number
	TCHAR szFetCmd[] = _T("wmic baseboard get serialnumber");

	// Pre- information of mainboard serial number
	const std::string strEnSearch = "SerialNumber";

	BOOL fReturnCode = FALSE;
	HANDLE hReadPipe = NULL;  // Pipeline for READ
	HANDLE hWritePipe = NULL; // Pipeline for WRITE
	PROCESS_INFORMATION pi;   // Process information
	STARTUPINFO			si;   // Control-command window info
	SECURITY_ATTRIBUTES sa;   // Security attributes

	char szBuffer[COMMAND_SIZE + 1] = { 0 }; // Command line output buffer
	std::string strBuffer;
	DWORD count = 0;
	size_t pos = 0;
	size_t i = 0;
	size_t j = 0;

	lpszBaseBoard = (char*)malloc((COMMAND_SIZE + 1) * sizeof(char));
	memset(lpszBaseBoard, 0x00, (COMMAND_SIZE + 1) * sizeof(char));

	memset(&pi, 0, sizeof(pi));
	memset(&si, 0, sizeof(si));
	memset(&sa, 0, sizeof(sa));

	pi.hProcess = NULL;
	pi.hThread = NULL;
	si.cb = sizeof(STARTUPINFO);
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	sa.lpSecurityDescriptor = NULL;
	sa.bInheritHandle = TRUE;

	// Step 1: Create pipeline
	fReturnCode = CreatePipe(&hReadPipe, &hWritePipe, &sa, 0);
	if (!fReturnCode)
	{
		goto EXIT;
	}

	// Step 2: Set command line window to be specific READ / WRITE pipeline
	GetStartupInfo(&si);
	si.hStdError = hWritePipe;
	si.hStdOutput = hWritePipe;
	si.wShowWindow = SW_HIDE; // hide command line window
	si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;

	// Step 3: Create process to get command line handle
	fReturnCode = CreateProcess(NULL, szFetCmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
	if (!fReturnCode)
	{
		goto EXIT;
	}

	// Step 4: Get return back data
	WaitForSingleObject(pi.hProcess, WAIT_TIME);
	fReturnCode = ReadFile(hReadPipe, szBuffer, COMMAND_SIZE, &count, 0);
	if (!fReturnCode)
	{
		goto EXIT;
	}

	// Step 5: Search for mainboard serial number
	fReturnCode = FALSE;
	strBuffer = szBuffer;
	pos = strBuffer.find(strEnSearch);

	if (pos < 0) // NOT FOUND
	{
		goto EXIT;
	}
	else
	{
		strBuffer = strBuffer.substr(pos + strEnSearch.length());
	}

	memset(szBuffer, 0x00, sizeof(szBuffer));
	strcpy_s(szBuffer, strBuffer.c_str());

	// Get ride of <space>, \r, \n
	j = 0;
	for (i = 0; i < strlen(szBuffer); i++)
	{
		if (szBuffer[i] != ' ' && szBuffer[i] != '\n' && szBuffer[i] != '\r')
		{
			lpszBaseBoard[j] = szBuffer[i];
			j++;
		}
	}

	fReturnCode = TRUE;

EXIT:
	CloseHandle(hWritePipe);
	CloseHandle(hReadPipe);
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);

	return(fReturnCode);
}
int main()
{ 
	char* lpszMainBoardSN = NULL;
	GetMainBoardInfoByCmd(lpszMainBoardSN);

	if (lpszMainBoardSN)
	{
		printf("%s\n", lpszMainBoardSN);

		free(lpszMainBoardSN);
		lpszMainBoardSN = NULL;
	}
	else
	{
		printf("N/A\n");
	}
	getchar();
	return 0;
}

cpu有

#include <windows.h>
#include <iostream>
#include <string>
 
using namespace std;
 
 
//用来存储eax,ebx,ecx,edx四个寄存器的信息
DWORD deax;
DWORD debx;
DWORD decx;
DWORD dedx;
 
void ExeCPUID(DWORD veax)  //初始化CPU
{
__asm
{
    mov eax,veax
    cpuid
    mov deax,eax
    mov debx,ebx
    mov decx,ecx
    mov dedx,edx
}
}
 
/*    在Intel Pentium以上级别的CPU中,有一个称为“时间戳(Time Stamp)”的部件,
    它以64位无符号整型数的格式,记录了自CPU上电以来所经过的时钟周期数。
    由于目前的CPU主频都非常高,因此这个部件可以达到纳秒级的计时精度。
    这个精确性是上述两种方法所无法比拟的。
    在Pentium以上的CPU中,提供了一条机器指令RDTSC(Read Time Stamp Counter)
    来读取这个时间戳的数字,并将其保存在EDX:EAX寄存器对中
*/
long GetCPUFreq()       //获取CPU频率,单位: MHZ
{
    int start,over;
    _asm 
    {
        RDTSC
        mov start,eax
    }
    Sleep(50);
    _asm 
    {
        RDTSC
        mov over,eax
    }
    return (over-start)/50000;
}
 
 
 
/*   把eax = 0作为输入参数,可以得到CPU的制造商信息。
     cpuid指令执行以后,会返回一个12字符的制造商信息,
     前四个字符的ASC码按低位到高位放在ebx,中间四个放在edx,最后四个字符放在ecx。
*/
string GetManID()   //获取制造商信息
{
    char ID[25];        
    memset(ID,0,sizeof(ID));
     
    ExeCPUID(0);          //初始化
    memcpy(ID+0,&debx,4); //制造商信息复制到数组
    memcpy(ID+4,&dedx,4);
    memcpy(ID+8,&decx,4);
     
    return string(ID);
}
 
 
/*  在我的电脑上点击右键,选择属性,可以在窗口的下面看到一条CPU的信息,
    这就是CPU的商标字符串。CPU的商标字符串也是通过cpuid得到的。
    由于商标的字符串很长(48个字符),所以不能在一次cpuid指令执行时全部得到,
    所以intel把它分成了3个操作,eax的输入参数分别是0x80000002,0x80000003,0x80000004,
    每次返回的16个字符,按照从低位到高位的顺序依次放在eax, ebx, ecx, edx。
    因此,可以用循环的方式,每次执行完以后保存结果,然后执行下一次cpuid。
*/
string GetCPUType()
{
    const DWORD id = 0x80000002; //从0x80000002开始,到0x80000004结束
    char CPUType[49];//用来存储CPU型号信息
    memset(CPUType,0,sizeof(CPUType));//初始化数组
     
    for(DWORD t = 0 ; t < 3 ; t++ )
    {
        ExeCPUID(id+t);
        //每次循环结束,保存信息到数组
        memcpy(CPUType+16*t+ 0,&deax,4);
        memcpy(CPUType+16*t+ 4,&debx,4);
        memcpy(CPUType+16*t+ 8,&decx,4);
        memcpy(CPUType+16*t+12,&dedx,4);
    }
     
    return string(CPUType);
}
 
void main() 
{ 
    cout<<"本机CPU信息如下:"<<endl;
    cout<<"CPU 主 频: "<<GetCPUFreq()<<" MHZ"<<endl;
    cout<<"CPU 制造商: "<<GetManID()<<endl;
    cout<<"CPU 型 号: "<<GetCPUType()<<endl;
    cin.get();
 
}

Win32_baseboard 主板 参数说明 Caption --简短说明 ConfigOptions --数组,表示位于在底板上跳线和开关的配置。 CreationClassName --表示类的名称(就是Win32_baseboard类) Depth --以英寸为单位的物理封装。 Description --对象的描述(底板) Height --用英寸表示的物理包的高度 HostingBoard --如果为TRUE,该卡是一个主板,或在一个机箱中的基板。 HotSwappable --如果为TRUE,就是支持热插拔(判断是否支持热插拔) InstallDate --日期和时间对象安装。此属性不需要的值以表示已安装的对象。 Manufacturer --表示制造商的名称 Model --物理元素的名称是已知。 Name --对象的名称标签 OtherIdentifyingInfo --捕获附加数据,超出资产标签的信息,可以用来标识物理元件 PartNumber --由负责生产或制造的物理元素的组织分配部件编号。 PoweredOn --如果为真,物理元素处于开机状态。 Product --产品的型号 Removable --判断是否可拆卸的 Replaceable --判断是否可更换的 RequirementsDescription --自由格式字符串描述方式,这张卡是身体不同于其他卡。该属性才有意义时,相对应的布尔值属性特殊要求是集真的 RequiresDaughterBoard --如果是TRUE,至少一个子板或辅助卡才能正常工作。 SerialNumber --制造商分配的用于识别所述物理元件数目。 SKU --库存的物理单元号。 SlotLayout --描述插槽位置 SpecialRequirements --如果为真,此卡是同类型的其他卡物理上唯一的,因此需要一个专门的插槽 Status --对象的当前状态。 Tag --符系统的基板唯一标识 Version --物理元素的版本 Weight --物理元素的重量英镑表示 Width --用英寸表示的物理元素的宽度 参考: https://bbs.pediy.com/thread-225735.htm http://www.cppfans.com/articles/system/bcb_wmi.asp https://blog.csdn.net/darennet/article/details/41149725