如何读写没有盘符的硬盘?已知硬盘格式。

如何读写没有盘符的硬盘?已知硬盘格式。

在windows下挂了一个硬盘,但这个硬盘里的分区(如我们平时说C盘D盘等)没有给它分配盘符,
但已知其格式(ntfs或fat),如何用perl去读写里面的文件?
谢谢。

PS:我在cpan里搜Drive但没找到想要的。


QUOTE:
原帖由 freeand 于 2007-11-1 13:13 发表
在windows下挂了一个硬盘,但这个硬盘里的分区(如我们平时说C盘D盘等)没有给它分配盘符,
但已知其格式(ntfs或fat),如何用perl去读写里面的文件?
谢谢。

PS:我在cpan里搜Drive但没找到想要的。

Hi,

If you are familiar with Windows VBS. WMI, you can use CPAN module Win32::OLE,
with Win32::OLE to wrap to Win32's Object.

-- ulmer
use Win32::OLE qw(in);
use constant vbTab => "\x09";

$strComputer = '.';
# ------ END CONFIGURATION ---------

print "Physical Disks:\n";
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colDisks = $objWMI->ExecQuery('select * from Win32_DiskDrive');
foreach my $objDisk (in $colDisks) {
    print ' Caption: ' . vbTab . $objDisk->Caption, "\n";
    print ' Device ID: ' . vbTab . $objDisk->DeviceID, "\n";
    print ' Manufacturer: ' . vbTab . $objDisk->Manufacturer, "\n";
    print ' Media Type: ' . vbTab . $objDisk->MediaType, "\n";
    print ' Model: ' . vbTab . $objDisk->Model, "\n";
    print ' Name: ' . vbTab . $objDisk->Name, "\n";
    print ' Partitions: ' . vbTab . $objDisk->Partitions, "\n";
    print ' Size: ' . vbTab . $objDisk->Size, "\n";
    print ' Status: ' . vbTab . $objDisk->Status, "\n";
    print "\n";
}

print "\n";
print "Logical Disks:\n";
$colDisks = $objWMI->ExecQuery('select * from Win32_LogicalDisk');
foreach my $objDisk (in $colDisks) {
    print ' DeviceID: ' . $objDisk->DeviceID, "\n";
    print ' Description: ' . $objDisk->Description, "\n";
    print ' VolumeName: ' . $objDisk->VolumeName, "\n";
    print ' DriveType: ' . $objDisk->DriveType, "\n";
    print ' FileSystem: ' . $objDisk->FileSystem, "\n";
    print ' FreeSpace: ' . $objDisk->FreeSpace, "\n";
    print ' MediaType: ' . $objDisk->MediaType, "\n";
    print ' Name: ' . $objDisk->Name, "\n";
    print ' Size: ' . $objDisk->Size, "\n";
    print "\n";
}


可以读出所有硬盘和显示分区。
但是没有分配盘符的分区(隐藏)还是没法显示啊。。。
Disk Devices
Windows NT: You can use the CreateFile function to open a disk drive or a partition on a disk drive. The function returns a handle to the disk device; that handle can be used with the DeviceIOControl function. The following requirements must be met in order for such a call to succeed:

The caller must have administrative privileges for the operation to succeed on a hard disk drive.

The lpFileName string should be of the form \\.\PHYSICALDRIVEx to open the hard disk x. Hard disk numbers start at zero.For example:

String Meaning
\\.\PHYSICALDRIVE2 Obtains a handle to the third physical drive on the user's computer.

The lpFileName string should be \\.\x: to open a floppy drive x or a partition x on a hard disk.For example:

String Meaning
\\.\A: Obtains a handle to drive A on the user's computer.
\\.\C: Obtains a handle to drive C on the user's computer.


大家看看,是不是要求写盘符(A OR C OR D ...)才能操作啊?
XP下面么? mountvol分配盘符先. Perl对应的API就不清楚了.
是的,xp下。但用xp自带的磁盘管理工具也看不到隐藏的分区的,用PM等软件就可以看到和直接浏览里面的文件。
现在就是想不分配盘符给它。。。
$wmi=Win32::OLE->GetObject("winmgmts://./root/cimv2:Win32_DiskDrive.DeviceID=\'\\\\.\\PHYSICALDRIVE0\'");

这种方式可以用 winmgmts 操作(读写)硬盘,但似乎要求 Partition table (盘符)才可以。。。