读书人

怎么获取远程磁盘的容量并对远程磁盘

发布时间: 2012-08-08 14:32:45 作者: rapoo

如何获取远程磁盘的容量,并对远程磁盘进行读写操作 c++
我想获取远程映射磁盘的大小,并对它进行读写操作。但是使用了很多方法都只能获取本地的。

[解决办法]
C:\>net help use
此命令的语法是:


NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
[/USER:[domainname\]username]
[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
[/SMARTCARD]
[/SAVECRED]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]


NET USE 用于将计算机与共享的资源相连接,或者切断计算机与共享资
源的连接。当不带选项使用本命令时,它会列出计算机的连接。

devicename 指定一个名字以便与资源相连接,或者指定要切断的设备。
有两种类型的设备名:磁盘驱动器 (D: 至 Z:) 和打印机
(LPT1: 至 LPT3:)。输入 一个星号来代替一个指定的设备
名可以分配下一个可用设备名。
\\computername 指控制共享资源的计算机的名字。如果计算机名中包含有
空字符,就要将双反斜线 (\\) 和计算机名一起用引号
(" ")括起来。计算机名可以有1 到 15 个 字符。
\sharename 指共享资源的网络名字。
\volume 指定一个服务器上的 NetWare 卷。用户必须安装 Netware
的客户服务(Windows 工作站) 或者 Netware 的网关服务
(Windows 服务器) 并使之与 NetWare 服务器相连。
password 指访问共享资源所需要的密码。
* 进行密码提示。当在密码提示符下输入密码时,密码不会显示。
/USER 指定连接时的一个不同的用户名。
domainname 指定另外一个域。如果缺省域,就会使用当前登录的域。
username 指定登录的用户名。
/SMARTCARD 指定连接使用在智能卡上的凭据。
/SAVECRED 指定保留用户名和密码。此开关被忽略,除非命令提示输入用
户名和密码。
/HOME 将用户与他们的主目录相连。
/DELETE 取消一个网络连接,并且从永久连接列表中删除该连接。
/PERSISTENT 控制对永久网络连接的使用。其默认值是最近使用的设置。
YES 在连接产生时保存它们,并在下次登录时恢复它们。
NO 不保存正在产生的连接或后续的连接;现有的连接将在下次登
录时恢复。可以使用 /DELETE 选项开关来删除永久连接。
NET HELP command | MORE 用于逐屏显示帮助。
[解决办法]
GetDiskFreeSpaceEx
The GetDiskFreeSpaceEx function obtains information about the amount of space available on a disk volume: the total amount of space, the total amount of free space, and the total amount of free space available to the user associated with the calling thread.

BOOL GetDiskFreeSpaceEx(
LPCTSTR lpDirectoryName, // pointer to the directory name
PULARGE_INTEGER lpFreeBytesAvailableToCaller, // receives the number of bytes on
// disk available to the caller
PULARGE_INTEGER lpTotalNumberOfBytes, // receives the number of bytes on disk
PULARGE_INTEGER lpTotalNumberOfFreeBytes // receives the free bytes on disk
);

Parameters
lpDirectoryName
Pointer to a null-terminated string that specifies a directory on the disk of interest. This string can be a UNC name. If this parameter is a UNC name, you must follow it with an additional backslash. For example, you would specify \\MyServer\MyShare as \\MyServer\MyShare\.
If lpDirectoryName is NULL, the GetDiskFreeSpaceEx function obtains information about the disk that contains the current directory.

Note that lpDirectoryName does not have to specify the root directory on a disk. The function accepts any directory on the disk.

lpFreeBytesAvailableToCaller
Pointer to a variable to receive the total number of free bytes on the disk that are available to the user associated with the calling thread.
Windows NT 5.0 and later: If per-user quotas are in use, this value may be less than the total number of free bytes on the disk.

lpTotalNumberOfBytes
Pointer to a variable to receive the total number of bytes on the disk that are available to the user associated with the calling thread.
Windows NT 5.0 and later: If per-user quotas are in use, this value may be less than the total number of bytes on the disk.



lpTotalNumberOfFreeBytes
Pointer to a variable to receive the total number of free bytes on the disk.
This parameter can be NULL.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Note that the values obtained by this function are of type ULARGE_INTEGER. Be careful not to truncate these values to 32 bits.

Windows 95 OSR2: The GetDiskFreeSpaceEx function is available on Windows 95 systems beginning with OEM Service Release 2 (OSR2).

To determine whether GetDiskFreeSpaceEx is available, call the LoadLibrary or LoadLibraryEx function to load the KERNEL32.DLL file, then call the GetProcAddress function to obtain an address for GetDiskFreeSpaceEx. If GetProcAddress fails, or if GetDiskFreeSpaceEx fails with the ERROR_CALL_NOT_IMPLEMENTED code, use the GetDiskFreeSpace function instead of GetDiskFreeSpaceEx.

QuickInfo
Windows NT: Requires version 4.0 or later.
Windows: Requires Windows 95 OSR2 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
File I/O Overview, File Functions, GetDiskFreeSpace


读书人网 >C++

热点推荐