您的位置:首页 > 其它

如何获取共享文件的路径

2008-01-15 14:47 393 查看
using System;
using System.Management;

namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from win32_share");
foreach (ManagementObject share in searcher.Get())
{
Console.WriteLine(share["Name"].ToString()); //名称
Console.WriteLine(share["Path"].ToString()); //路径
}
}
}
}

注册表中有:
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/lanmanserver/Shares

不知从select * from win32_share还可以得到其它什么属性

应该是包括下面这些信息,在msdn中有

uint32 AccessMask;
boolean AllowMaximum;
string Caption;
string Description;
datetime InstallDate;
uint32 MaximumAllowed;
string Name;
string Path;
string Status;
uint32 Type;

Properties
The Win32_Share class defines the following properties.

AccessMask
Data type: uint32
Access type: Read-only

List of access rights to the given file or directory held by the user or group on whose behalf the instance is returned. This property is only supported under Windows NT and Windows 2000. On Windows 98 and on Windows NT/Windows 2000 FAT volumes, the FULL_ACCESS value is returned instead, indicating no security has been set on the object.

Windows 2000, Windows XP: This property is no longer used due to the expense of calling GetEffectiveRightsFromAcl. You should use the Win32_Share.GetAccessMask method instead. The value of the AccessMask property is set to NULL.

AllowMaximum
Data type: boolean
Access type: Read-only

Number of concurrent users for this resource has been limited. If TRUE, the value in the MaximumAllowed property is ignored.

Caption
Data type: string
Access type: Read-only

Short description (one-line string) of the object.

Description
Data type: string
Access type: Read-only

Description of the object.

InstallDate
Data type: datetime
Access type: Read-only

Object was installed. This property does not need a value to indicate that the object is installed.

MaximumAllowed
Data type: uint32
Access type: Read-only

Limit on the maximum number of users allowed to use this resource concurrently. The value is only valid if the AllowMaximum property is set to FALSE

Name
Data type: string
Access type: Read-only
Qualifiers: Key

Alias given to a path set up as a share on a Windows system.

Example: "public"

Path
Data type: string
Access type: Read-only

Local path of the Windows share.

Example: "C:/Program Files"

Status
Data type: string
Access type: Read-only

Current status of the object. Various operational and non-operational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard drive, may be functioning properly but predicting a failure in the near future). Non-operational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is on-line, yet the managed element is neither "OK" nor in one of the other states.

Values are:

"OK"
"Error"
"Degraded"
"Unknown"
"Pred Fail"
"Starting"
"Stopping"
"Service"
"Stressed"
"Nonrecover"
"Nocontact"
"LostComm"

Type
Data type: uint32
Access type: Read-only

Type of resource being shared. Types include disk drives, print queues, interprocess communications (IPC), and general devices.

Value Meaning
0 Disk Drive
1 Print Queue
2 Device
3 IPC
2147483648 Disk Drive Admin
2147483649 Print Queue Admin
2147483650 Device Admin
2147483651 IPC Admin
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: