HELP~~~~~~半年了,还是没找到答案,很压抑呀!!!UP者有分

viperstorm 2003-01-07 08:37:15
这个问题困扰我很久了。
我想知道电脑上(A)有多少个物理的硬盘(B)每个物理硬盘上有多少个分区(C)每个分区的逻辑盘符是什么。

也就是我想知道一系列的盘符究竟哪些属于第一个硬盘,那个属于第二个硬盘。

怎样实现呢?WMI方法也行,最好是能在win98下也可以的,或者有相关的资料吗?
这几个月我每过几天就寻找答案,但是还是没找到,搞到我睡觉都不舒服,有人能帮我解脱吗?

我在VC区也贴了个帖子,现在还是没人能够回答。
http://expert.csdn.net/Expert/TopicView1.asp?id=1332891
...全文
23 点赞 收藏 49
写回复
49 条回复
切换为时间正序
请发表友善的回复…
发表回复
野男孩 2003-02-27
唉,我也困绕已久了,98下该怎么办啊!!
回复
sgx 2003-01-09
up
回复
viperstorm 2003-01-09
我寄给你的邮件被退了回来,主页又上不了,5555555555~~~~~~~~~~
我的邮箱是varptr@hotmail.com,3tx 3tx 3tx very much!!
回复
rosement 2003-01-09
没有收到你的EMAIL,不过我已经将我程序的原代码放在了我的主页上,有兴趣可以去下载看看。
ROSEMENT.DIY.163.COM
回复
wocan 2003-01-09
up
回复
viperstorm 2003-01-09
刚才贴错帖了,呵呵。

我用WMI来实现了这个问题:

Private Sub Command1_Click()

Dim ComputerName As String
Dim wmiServices As Object
Dim wmiDiskDrives As Object
Dim wmiDiskDrive As Object

Dim wmiDiskPartitions As Object
Dim wmiDiskPartition As Object
Dim strEscapedDeviceID As String


ComputerName = "."
Set wmiServices = GetObject("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery("SELECT Caption, DeviceID FROM Win32_DiskDrive")

For Each wmiDiskDrive In wmiDiskDrives

'//
Debug.Print "1|" & wmiDiskDrive.Caption & " (" & wmiDiskDrive.DeviceID & ")"

strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition")

For Each wmiDiskPartition In wmiDiskPartitions

'//
Debug.Print "2|" & vbTab & wmiDiskPartition.DeviceID
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
'//
Debug.Print "3|" & vbTab & vbTab & wmiLogicalDisk.DeviceID
Next
Next
Next

End Sub
回复
viperstorm 2003-01-09
楼主用的是VB.NET吧,我试过,可以呀!

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Integer

Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)

Private Const MOUSEEVENTF_LEFTDOWN As Short = &H2S
Private Const MOUSEEVENTF_LEFTUP As Short = &H4S
Private Const MOUSEEVENTF_RIGHTDOWN As Short = &H8S
Private Const MOUSEEVENTF_RIGHTUP As Short = &H10S

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click

SetCursorPos(50, 100)
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
Sleep (10)
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)

End Sub

他是模拟在桌面上(50,100)点击鼠标右键。
回复
ccbl 2003-01-08
up
回复
viperstorm 2003-01-08
怎么就我一个人在贴答案,其他人呢???555~~~~
回复
chao778899 2003-01-08
高手
回复
viperstorm 2003-01-08
我再研究,得出下面的代码:
把它保存为.vbs文件就可以运行了。

ComputerName = "."
Set wmiServices = GetObject ("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery ("SELECT Caption, DeviceID FROM Win32_DiskDrive")

For Each wmiDiskDrive In wmiDiskDrives
WScript.Echo wmiDiskDrive.Caption & " (" & wmiDiskDrive.DeviceID & ")"
strEscapedDeviceID = Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
Set wmiDiskPartitions = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
strEscapedDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition")

For Each wmiDiskPartition In wmiDiskPartitions
WScript.Echo vbTab & wmiDiskPartition.DeviceID
Set wmiLogicalDisks = wmiServices.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
wmiDiskPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition")
For Each wmiLogicalDisk In wmiLogicalDisks
WScript.Echo vbTab & vbTab & wmiLogicalDisk.DeviceID
Next
Next
Next
回复
jnhjone 2003-01-08
楼主,VC转VB在有些时候是肯定有问题的,特别是针对于这类问题

我不是来混分的
只是来看看
以前我总是希望自己发的贴子能有更多的人光顾
虽然我不能帮你
但已经把你的贴子加入了我的收藏夹
学习
回复
progame 2003-01-08
回复人: acptvb(微软全球技术中心 VB技术支持) ( ) 信誉:100 2002-7-18 17:54:07 得分:0



感谢您使用微软产品。

你可以使用WMI的Win32_LogicalDisk对象获得逻辑盘的各项信息,如下例:

Private Sub Command1_Click()

WQL = "Select * From Win32_LogicalDisk"
Set LDisks = GetObject("winmgmts:").ExecQuery(WQL)

For Each disk In LDisks
Debug.Print disk.Name
Debug.Print disk.VolumeName
Next

End Sub

你可以使用WMI的Win32_DiskPartition对象获得硬盘分区的各项信息,其中DiskIndex属性可用于区分属于哪一个硬盘,如下例:

Private Sub Command2_Click()
WQL = "Select * From Win32_DiskPartition"

Set PDisks = GetObject("winmgmts:").ExecQuery(WQL)
For Each disk In PDisks
Debug.Print disk.Name
Debug.Print disk.Index
Debug.Print disk.DiskIndex
Next
End Sub

从逻辑盘符获得该逻辑盘所在分区,从而获得所在硬盘的Index,就能判断两个逻辑盘是否属于同一个物理盘。您可以用WQL的Associators OF关键字关联win32_LogicalDisk和Win32_DiskPartition,实现上述查询,如下例:

Private Sub Command3_Click()

WQL = "Associators of {win32_LogicalDisk='C:'} where resultClass = Win32_DiskPartition"

Set Pattions = GetObject("winmgmts:").ExecQuery(WQL)

For Each Pat In Pattions
Debug.Print Pat.Name
Debug.Print Pat.DiskIndex
Next

End Sub

详细信息请参考:
Win32_LogicalDisk
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_logicaldisk.asp
Win32_DiskPartition
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_diskpartition.asp
ASSOCIATORS OF Statement
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/associators_of_statement.asp


- 微软全球技术中心 VB技术支持

本帖子仅供SINA的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,23094245))。
======================





不知这个对你有用么?
回复
succed 2003-01-08
up
回复
viperstorm 2003-01-08
多谢多谢!!我现在发了一封信给你哦。
回复
rosement 2003-01-08
我已经完成了你需要的功能,可以EMAIL:ROSEMENT@SINA.COM
提供原代码,实现方法:ATL+VISUAL BASIC
DEVICEIOCONTROL API调用
回复
viperstorm 2003-01-08
不会吧,又要我孤独地苦苦找答案??!!有人是同道的吗?
playyuer、foolishtiger、songyangk、zyl910、TechnoFantasy 呢??
回复
viperstorm 2003-01-08
再顶!
回复
starbaby 2003-01-07
希望你尽快解决哦,我也觉得API里能找到答案,小妹也没做过,帮不了你了,抱歉~
回复
suntt 2003-01-07
up
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告