Nothing 2007-8-7 10:14
Windows 2000 下用 API 实现目录共享和删除
[color=#000000][color=#0000cc]'[/color]共享类型
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] STYPE_ALL As Long [color=#0000cc]=[/color] [color=#0000cc]-[/color]1
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] STYPE_DISKTREE As Long [color=#0000cc]=[/color] 0
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] STYPE_PRINTQ As Long [color=#0000cc]=[/color] 1
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] STYPE_DEVICE As Long [color=#0000cc]=[/color] 2
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] STYPE_IPC As Long [color=#0000cc]=[/color] 3
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] STYPE_SPECIAL As Long [color=#0000cc]=[/color] [color=#0000cc]&[/color]H80000000
[color=#0000cc]'[/color]共享权限
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] ACCESS_READ As Long [color=#0000cc]=[/color] [color=#0000cc]&[/color]H1
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] ACCESS_WRITE As Long [color=#0000cc]=[/color] [color=#0000cc]&[/color]H2
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] ACCESS_CREATE As Long [color=#0000cc]=[/color] [color=#0000cc]&[/color]H4
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] ACCESS_EXEC As Long [color=#0000cc]=[/color] [color=#0000cc]&[/color]H8
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] ACCESS_DELETE As Long [color=#0000cc]=[/color] [color=#0000cc]&[/color]H10
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] ACCESS_ATRIB As Long [color=#0000cc]=[/color] [color=#0000cc]&[/color]H20
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] ACCESS_PERM As Long [color=#0000cc]=[/color] [color=#0000cc]&[/color]H40
[color=#0000ff]Private[/color] [color=#0000ff]Const[/color] ACCESS_ALL As Long [color=#0000cc]=[/color] ACCESS_READ [color=#0000ff]Or[/color] _
ACCESS_WRITE [color=#0000ff]Or[/color] _
ACCESS_CREATE [color=#0000ff]Or[/color] _
ACCESS_EXEC [color=#0000ff]Or[/color] _
ACCESS_DELETE [color=#0000ff]Or[/color] _
ACCESS_ATRIB [color=#0000ff]Or[/color] _
ACCESS_PERM
[color=#0000cc]'[/color]共享信息
[color=#0000ff]Private[/color] Type SHARE_INFO_2
shi2_netname As Long [color=#0000cc]'[/color]共享名
shi2_type As Long [color=#0000cc]'[/color]类型
shi2_remark As Long [color=#0000cc]'[/color]备注
shi2_permissions As Long [color=#0000cc]'[/color]权限
shi2_max_uses As Long [color=#0000cc]'[/color]最大用户
shi2_current_uses As Long [color=#0000cc]'[/color]
shi2_path As Long [color=#0000cc]'[/color]路径
shi2_passwd As Long [color=#0000cc]'[/color]密码
[color=#0000ff]End[/color] Type
[color=#0000cc]'[/color]设置共享
[color=#0000ff]Private[/color] Declare [color=#0000ff]Function[/color] NetShareAdd Lib “netapi32“ _
[color=#0000cc]([/color][color=#0000ff]ByVal[/color] ServerName As Long[color=#0000cc],[/color] _
[color=#0000ff]ByVal[/color] level As Long[color=#0000cc],[/color] _
buf As Any[color=#0000cc],[/color] _
parmerr As Long[color=#0000cc])[/color] As Long
[color=#0000cc]'[/color]删除共享
[color=#0000ff]Private[/color] Declare [color=#0000ff]Function[/color] NetShareDel Lib “netapi32[color=#0000cc].[/color]dll“ _
[color=#0000cc]([/color][color=#0000ff]ByVal[/color] ServerName As Long[color=#0000cc],[/color] _
[color=#0000ff]ByVal[/color] ShareName As Long[color=#0000cc],[/color] _
[color=#0000ff]ByVal[/color] dword As Long[color=#0000cc])[/color] As Long
[color=#0000cc]'[/color]设置共享
[color=#0000ff]Private[/color] [color=#0000ff]Sub[/color] Command1_Click[color=#0000cc]([/color][color=#0000cc])[/color]
[color=#0000ff]Dim[/color] success As Long
success [color=#0000cc]=[/color] ShareAdd[color=#0000cc]([/color]“[color=#0000cc]\[/color][color=#0000cc]\[/color]XP“[color=#0000cc],[/color]“C[color=#0000cc]:[/color][color=#0000cc]\[/color]“[color=#0000cc],[/color]“DOWNLOAD“[color=#0000cc],[/color]“资源目录“[color=#0000cc],[/color]““[color=#0000cc])[/color]
[color=#0000ff]End[/color] [color=#0000ff]Sub[/color]
[color=#0000cc]'[/color]删除共享
[color=#0000ff]Private[/color] [color=#0000ff]Sub[/color] Command2_Click[color=#0000cc]([/color][color=#0000cc])[/color]
[color=#0000ff]Dim[/color] success As Long
success [color=#0000cc]=[/color] DelShare[color=#0000cc]([/color]“[color=#0000cc]\[/color][color=#0000cc]\[/color]XP“[color=#0000cc],[/color]“DOWNLOAD“[color=#0000cc])[/color]
[color=#0000ff]End[/color] [color=#0000ff]Sub[/color]
[color=#0000cc]'[/color]设置共享[color=#0000cc]([/color]返回0 为成功[color=#0000cc])[/color]
[color=#0000cc]'[/color]参数[color=#0000cc]:[/color]
[color=#0000cc]'[/color]sServer 计算机名
[color=#0000cc]'[/color]sSharePath 要共享路径
[color=#0000cc]'[/color]sShareName 显示的共享名
[color=#0000cc]'[/color]sShareRemark 备注
[color=#0000cc]'[/color]sSharePw 密码
[color=#0000ff]Private[/color] [color=#0000ff]Function[/color] ShareAdd[color=#0000cc]([/color]sServer As [color=#ff0000]String[/color][color=#0000cc],[/color] _
sSharePath As [color=#ff0000]String[/color][color=#0000cc],[/color] _
sShareName As [color=#ff0000]String[/color][color=#0000cc],[/color] _
sShareRemark As [color=#ff0000]String[/color][color=#0000cc],[/color] _
sSharePw As [color=#ff0000]String[/color][color=#0000cc])[/color] As Long
[color=#0000ff]Dim[/color] lngServer As Long
[color=#0000ff]Dim[/color] lngNetname As Long
[color=#0000ff]Dim[/color] lngPath As Long
[color=#0000ff]Dim[/color] lngRemark As Long
[color=#0000ff]Dim[/color] lngPw As Long
[color=#0000ff]Dim[/color] parmerr As Long
[color=#0000ff]Dim[/color] si2 As SHARE_INFO_2
lngServer [color=#0000cc]=[/color] StrPtr[color=#0000cc]([/color]sServer[color=#0000cc])[/color] [color=#0000cc]'[/color]转成地址
lngNetname [color=#0000cc]=[/color] StrPtr[color=#0000cc]([/color]sShareName[color=#0000cc])[/color]
lngPath [color=#0000cc]=[/color] StrPtr[color=#0000cc]([/color]sSharePath[color=#0000cc])[/color]
[color=#0000cc]'[/color]如果有备注信息
[color=#0000ff]If[/color] [color=#ff0000]Len[/color][color=#0000cc]([/color]sShareRemark[color=#0000cc])[/color] [color=#0000cc]>[/color] 0 [color=#0000ff]Then[/color]
lngRemark [color=#0000cc]=[/color] StrPtr[color=#0000cc]([/color]sShareRemark[color=#0000cc])[/color]
[color=#0000ff]End[/color] [color=#0000ff]If[/color]
[color=#0000cc]'[/color]如果有密码
[color=#0000ff]If[/color] [color=#ff0000]Len[/color][color=#0000cc]([/color]sSharePw[color=#0000cc])[/color] [color=#0000cc]>[/color] 0 [color=#0000ff]Then[/color]
lngPw [color=#0000cc]=[/color] StrPtr[color=#0000cc]([/color]sSharePw[color=#0000cc])[/color]
[color=#0000ff]End[/color] [color=#0000ff]If[/color]
[color=#0000cc]'[/color]初始化共享信息
With si2
[color=#0000cc].[/color]shi2_netname [color=#0000cc]=[/color] lngNetname
[color=#0000cc].[/color]shi2_path [color=#0000cc]=[/color] lngPath
[color=#0000cc].[/color]shi2_remark [color=#0000cc]=[/color] lngRemark
[color=#0000cc].[/color]shi2_type [color=#0000cc]=[/color] STYPE_DISKTREE
[color=#0000cc].[/color]shi2_permissions [color=#0000cc]=[/color] ACCESS_ALL
[color=#0000cc].[/color]shi2_max_uses [color=#0000cc]=[/color] [color=#0000cc]-[/color]1
[color=#0000cc].[/color]shi2_passwd [color=#0000cc]=[/color] lngPw
[color=#0000ff]End[/color] With
[color=#0000cc]'[/color]设置共享[color=#0000cc]([/color]用户名[color=#0000cc],[/color]共享类型[color=#0000cc],[/color]共享信息[color=#0000cc],[/color][color=#0000cc])[/color]
ShareAdd [color=#0000cc]=[/color] NetShareAdd[color=#0000cc]([/color]lngServer[color=#0000cc],[/color] _
2[color=#0000cc],[/color] _
si2[color=#0000cc],[/color] _
parmerr[color=#0000cc])[/color]
[color=#0000ff]End[/color] [color=#0000ff]Function[/color]
[color=#0000cc]'[/color]删除共享[color=#0000cc]([/color]返回0 表示成功[color=#0000cc])[/color]
[color=#0000cc]'[/color]参数[color=#0000cc]:[/color]
[color=#0000cc]'[/color]sServer 计算机名
[color=#0000cc]'[/color]sShareName 共享名
[color=#0000ff]Private[/color] [color=#0000ff]Function[/color] DelShare[color=#0000cc]([/color]sServer As [color=#ff0000]String[/color][color=#0000cc],[/color] _
sShareName As [color=#ff0000]String[/color][color=#0000cc])[/color] As Long
[color=#0000ff]Dim[/color] lngServer As Long [color=#0000cc]'[/color]计算机名
[color=#0000ff]Dim[/color] lngNetname As Long [color=#0000cc]'[/color]共享名
lngServer [color=#0000cc]=[/color] StrPtr[color=#0000cc]([/color]sServer[color=#0000cc])[/color] [color=#0000cc]'[/color]转成地址
lngNetname [color=#0000cc]=[/color] StrPtr[color=#0000cc]([/color]sShareName[color=#0000cc])[/color]
[color=#0000cc]'[/color]删除共享
DelShare [color=#0000cc]=[/color] NetShareDel[color=#0000cc]([/color]lngServer[color=#0000cc],[/color] lngNetname[color=#0000cc],[/color] 0[color=#0000cc])[/color]
[color=#0000ff]End[/color] [color=#0000ff]Function[/color] [/color]