zoukankan
html css js c++ java
WMI,列出服务器进程信息及系统服务信息及管理帐号等。
VBS代码转成vb.net比较简单,感觉学WIN32 WMI还是比较重要的。
'
*************************************************************************
'
目的:获取本机IP
'
函数:getLocalIP
'
参数:无
'
返回值:本机IP
'
*************************************************************************
Function
getLocalIP
Set
IPConfigSet
=
GetObject
(
"
winmgmts:{impersonationLevel=impersonate}
"
).ExecQuery(
"
select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE
"
)
For
Each
IPConfig IN IPConfigSet
If
Not
IsNull
(IPConfig.IPAddress)
Then
For
i
=
LBound
(IPConfig.IPAddress)
To
UBound
(IPConfig.IPAddress)
strIP
=
strIP
&
IPConfig.IPAddress(i)
&
"
"
Next
End
If
Next
getLocalIP
=
strIP
End Function
'
*************************************************************************
'
功能:列出服务器驱动器可用磁盘空间
'
*************************************************************************
Function
listDiskFreeSpace()
On
Error
Resume
Next
'
XP/2003
Dim
strDiskSpace
'
strComputer = "."
'
Set objWMIService = GetObject("winmgmts:" _
'
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'
'
Set colDiskDrives = objWMIService.ExecQuery _
'
("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk Where " _
'
& "Name <> '_Total'")
'
'
For Each objDiskDrive in colDiskDrives
'
strDiskSpace = strDiskSpace & objDiskDrive.Name & _
'
"可用空间: " & objDiskDrive.FreeMegabytes & "MB" & VbCrLf
'
Next
'
All
Const
HARD_DISK
=
3
strComputer
=
"
.
"
Set
objWMIService
=
GetObject
(
"
winmgmts:
"
_
&
"
{impersonationLevel=impersonate}!\\
"
&
strComputer
&
"
\root\cimv2
"
)
Set
colDisks
=
objWMIService.ExecQuery _
(
"
Select * from Win32_LogicalDisk Where DriveType =
"
&
HARD_DISK
&
""
)
For
Each
objDisk in colDisks
strDiskSpace
=
strDiskSpace
&
objDisk.DeviceID
&
vbTab
&
_
"
空闲磁盘空间:
"
&
vbTab
&
objDisk.FreeSpace
/
1024
/
1024
&
"
MB
"
&
VbCrLf
Next
listDiskFreeSpace
=
strDiskSpace
End Function
'
*************************************************************************
'
目的:列出服务器进程
'
函数:strProcess
'
参数:无
'
返回值:字符串
'
*************************************************************************
Function
strProcess()
strComputer
=
"
.
"
Dim
oWMI, oProcs, oProc, strSQL,strPro
strSQL
=
"
SELECT * FROM Win32_Process
"
Set
oWMI
=
GetObject
(
"
winmgmts:\\
"
&
strComputer
&
"
\root\cimv2
"
)
Set
oProcs
=
oWMI.ExecQuery(strSQL)
For
Each
oProc In oProcs
strPro
=
strPro
&
VbCrLf
&
"
名称:
"
&
oProc.Name
&
VbCrLf
&
_
"
路径:
"
&
oProc.ExecutablePath
&
VbCrLf
&
_
"
===========================================================
"
Next
Set
oProc
=
Nothing
Set
oProcs
=
Nothing
Set
oWMI
=
Nothing
strProcess
=
strPro
End Function
'
*************************************************************************
'
目的:列出系统服务名字及路径和状态
'
函数名:strServicr()
'
参数:无
'
返回值:字符串
'
*************************************************************************
Function
strService()
dim
strTemp
strComputer
=
"
.
"
Set
objWMIService
=
GetObject
(
"
winmgmts:\\
"
&
strComputer
&
"
\root\cimv2
"
)
Set
colItems
=
objWMIService.ExecQuery(
"
Select * from Win32_Service
"
)
For
Each
objItem in colItems
strTemp
=
strTemp
&
VbCrLf
&
"
名称:
"
&
objItem.DisplayName
&
VbCrLf
&
VbCrLf
&
_
"
路径:
"
&
objItem.PathName
&
VbCrLf
&
_
"
状态:
"
&
objItem.State
&
VbCrLf
&
_
"
===========================================================
"
Next
strService
=
strTemp
Set
colItems
=
Nothing
Set
objWMIService
=
Nothing
End Function
'
*************************************************************************
'
目的:列出系统用户名及状态
'
函数名:strWinUser()
'
参数:无
'
返回值:字符串
'
*************************************************************************
Function
strWinUser()
strComputer
=
"
.
"
dim
strTemp
Set
objWMIWinUser
=
GetObject
(
"
winmgmts:\\
"
&
strComputer
&
"
\root\cimv2
"
)
Set
colItems
=
objWMIWinUser.ExecQuery(
"
Select * from Win32_UserAccount
"
)
For
Each
objItem in colItems
strTemp
=
strTemp
&
VbCrLf
&
"
名称:
"
&
objItem.Caption
&
VbCrLf
&
_
"
状态:
"
&
objItem.Status
&
VbCrLf
&
_
"
===========================================================
"
Next
strWinUser
=
strTemp
Set
colItems
=
Nothing
Set
objWMIWinUser
=
Nothing
End Function
查看全文
相关阅读:
Perforce笔记
Lumia 800 无法正常开机
Windows service 中出现Set ServiceLogin 对话框
华为要求七千员工先辞职再竞岗 补偿费超10亿
BLOG新址:http://longware.spaces.live.com
家装(2)
解脱
论持久战
有感于软件项目测试
THE POEM AS A GIFT FOR MY GF'S BIRTHDAY
原文地址:https://www.cnblogs.com/LCX/p/482601.html
最新文章
doxygen lua
Ubuntu太牛了!
VirtualBox 虚拟机命令行启动
宋体 与 粗宋体
doxygen filter
git 提交中的文件变化
Ubuntu 安装 wxlua
软件最终是要换成钱的啊!
算法啊算法
CMake5 调试
热门文章
Asp.net 2.0 Treeview 动态填充,并实现无限级树
编译错误 编译器失败,错误代码为 1073741819
CSS快速让图片变灰,网站快速变灰
Asp.net aspx 页面调用js 中文乱码问题
Cannot open database “XXX” requested by the login. The login failed.
bad module "ManagedPipelineHandler" in its module list
REST风格中什么时候用HTTP PUT
CMD
Bad module "ManagedPipelineHandler" in its module list
VS2010下使用NUnit 无法进行调试的问题
Copyright © 2011-2022 走看看