wmi一些操作
使用wmic识别安装到系统中的补丁情况
1 | C:\> wmic qfe get description,installedOn |
外部调用获取补丁情况
1 | select * from Win32_QuickFixEngineering |
识别正在运行的服务
1 | C:\>sc query type= service |
识别开机启动的程序,包括路径
1 | C:\>wmic startup list full |
查看系统中网卡的IP地址和MAC地址
1 | D:\>wmic nicconfig get ipaddress,macaddress |
用户列表
1 | D:\>wmic useraccount list brief |
查看当前系统是否有屏保保护,延迟是多少
1 | D:\>wmic desktop get screensaversecure,screensavertimeout |
域控机器
1 | D:\>wmic ntdomain list brief |
登录用户
1 | D:\>wmic logon list brief |
查看系统中开放的共享
1 | D:\>wmic share get name,path |
卸载和重新安装程序
1 | wmic product where "name like '%Office%'" get name |
来源:
查看系统中开启的日志
1 | C:\>wmic nteventlog get path,filename,writeable |
清除相关的日志(这里是全部清除)
1 | wevtutil cl "windows powershell" |
博主注:建议使用tr 或sed 或其他方法替换关键字符
*查看系统中安装的软件以及版本**
1 | C:\>wmic product get name,version |
查看某个进程的详细信息 (路径,命令行参数等)
1 | C:\>wmic process where name="chrome.exe" list full |
终止一个进程
1 | D:\>wmic process where name="xshell.exe" call terminate |
获取存储在注册表中所有包含密码的键值:
1 | REG query HKCU /v "pwd" /s #pwd可替换为password \ HKCU 可替换为HKCR |
显示系统中的曾经连接过的无线密码
1 | D:\>netsh wlan show profiles |
博主首发:
一键获取:
1 | for /f "skip=9 tokens=1,2 delims=:" %i in ('netsh wlan show profiles') do @echo %j | findstr -i -v echo | netsh wlan show profiles %j key=clear |
查看当前系统是否是VMWARE
1 | C:\>wmic bios list full | find /i "vmware" |
获取进程服务名称 PID
1 | tasklist /svc | findstr "TermService" |
杀毒软件
1 | Get-WmiObject -Namespace root\SecurityCenter2 -Class AntiVirusProduct |
虚拟机检测
判断TotalPhysicalMemory和NumberOfLogicalProcessors
1
2
3
4
5
6
7
8
9
10
11
12$VMDetected = $False
$Arguments = @{
Class = 'Win32_ComputerSystem'
Filter = 'NumberOfLogicalProcessors < 2 AND TotalPhysicalMemory < 2147483648'
}
if (Get-WmiObject @Arguments) {
$VMDetected = $True
"In vm"
}
else{
"Not in vm"
}判断虚拟机进程
1
2
3
4
5
6
7
8
9
10
11
12
13$VMwareDetected = $False
$VMAdapter = Get-WmiObject Win32_NetworkAdapter -Filter 'Manufacturer LIKE
"%VMware%" OR Name LIKE "%VMware%"'
$VMBios = Get-WmiObject Win32_BIOS -Filter 'SerialNumber LIKE "%VMware%"'
$VMToolsRunning = Get-WmiObject Win32_Process -Filter 'Name="vmtoolsd.exe"'
if ($VMAdapter -or $VMBios -or $VMToolsRunning)
{ $VMwareDetected = $True
"in vm"
}
else
{
"not in vm"
}
获取电脑产品编号和型号信息
1 | wmic baseboard get Product,SerialNumber |
安装软件
1 | wmic product get name,version |
程序运行时间
1 | wmic process get CreationDate |
检查服务路径中包含空格且没有双引号的服务
*博主首发
1 | wmic service where "((state='running') and (pathname like '% %') and not (pathname like '%\"%') and not (pathname like '%system32%') and not (pathname like '%syswow64%'))" get pathname,name,displayname,startname |