会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
大力
世界多么美好,我却如此暴燥
博客园
首页
新随笔
联系
管理
订阅
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
posted @
2006-08-21 18:17
大力
阅读(
911
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告