关于共享问题!!

Bettyh 2003-05-14 01:13:03
调用什么API函数可以使文件夹共享?
...全文
35 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bettyh 2003-05-15
  • 打赏
  • 举报
回复
高手请进!!
道素 2003-05-15
  • 打赏
  • 举报
回复
Option Explicit
Public Platform As Long 'Platform ID of OS. 1 or 2

'Structure for Getversion
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type

Public Const STYPE_DISKTREE As Long = 0
Public Const STYPE_PRINTQ As Long = 1
Public Const STYPE_DEVICE As Long = 2
Public Const STYPE_IPC As Long = 3

'Access types
Public Const ACCESS_READ As Long = &H1
Public Const ACCESS_WRITE As Long = &H2
Public Const ACCESS_CREATE As Long = &H4
Public Const ACCESS_EXEC As Long = &H8
Public Const ACCESS_DELETE As Long = &H10
Public Const ACCESS_ATRIB As Long = &H20
Public Const ACCESS_PERM As Long = &H40
Public Const ACCESS_ALL As Long = &H7F
Public Const WNTYPE_DRIVE As Long = 1
Public Const SHI_USES_UNLIMITED As Long = -1

'Info structures for NetShareAdd
Type SHARE_INFO_2
shi2_netname As String * 14
shi2_type As Long
shi2_remark As String 'Far pointer to string
shi2_permissions As Long
shi2_max_uses As Long
shi2_current_uses As Long
shi2_path As String 'Far pointer to string
shi2_passwd As String * 10
End Type

Type SHARE_INFO_50
shi50_netname As String
shi50_type As String
shi50_flags As Long
shi50_remark As String
shi50_path As String
shi50_rw_password As String
shi50_ro_password As String
End Type

'ACL for Security Descriptor
Public Type ACL
AclRevision As Byte
Sbz1 As Byte
AclSize As Integer
AceCount As Integer
Sbz2 As Integer
End Type

'Security Descriptor for SHARE_INFO_502
Public Type SECURITY_DESCRIPTOR
Revision As Byte
Sbz1 As Byte
Control As Long
Owner As Long
Group As Long
Sacl As ACL
Dacl As ACL
End Type

Type SHARE_INFO_502
shi502_netname As String
shi502_type As Long
shi502_remark As String
shi502_permissions As Long
shi502_max_uses As Long
shi502_current_uses As Long
shi502_path As String
shi502_passwd As String
shi502_reserved As Long
shi502_security_descriptor As SECURITY_DESCRIPTOR
End Type

Public Security As SECURITY_DESCRIPTOR

Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
(lpVersionInformation As OSVERSIONINFO) As Long
Public Declare Function lstrcpy Lib "kernel32" _
(ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
'NT
Public Declare Function NetShareDelNT Lib "netapi32.dll" Alias "NetShareDel" _
(ByVal servername As Any, ByVal netname As String, ByVal reserved As Long) As Long
Public Declare Function NetShareAddNT Lib "netapi32.dll" Alias "NetShareAdd" _
(ByVal servername As Any, ByVal slevel As Long, _
buf As SHARE_INFO_502, ByVal cbbuf As Long) As Long
'9x
Public Declare Function NetShareDel9x Lib "svrapi.dll" Alias "NetShareDel" _
(ByVal servername As Any, ByVal netname As String, ByVal reserved As Long) As Long
Public Declare Function NetShareAdd9x Lib "svrapi.dll" Alias "NetShareAdd" _
(ByVal servername As Any, ByVal slevel As Long, buf As SHARE_INFO_50, ByVal cbbuf As Long) As Long

'====================
'ADD CODE TO FORM:
'====================
Option Explicit
Dim SI2 As SHARE_INFO_2
Dim SI502 As SHARE_INFO_502
Dim SI50 As SHARE_INFO_50
Dim OSVERInfo As OSVERSIONINFO
Dim ShareRemark As String
Dim SharePath As String
Dim nerr As Long
Dim nPath As String
Dim pwd As String
Dim ret As Long
Dim OS As Long
Private Sub Form_Load()
OSVERInfo.dwOSVersionInfoSize = Len(OSVERInfo)
OS = GetVersionEx(OSVERInfo)
Command1.Caption = "Create Share NT"
Command2.Caption = "Create Share Win9x"
Command3.Caption = "Delete Share"
End Sub
Private Sub Command1_Click()
'NT
On Error Resume Next
SetStrings
nerr = NetShareAddNT(0&, 2, SI502, ret)
Print nerr
End Sub
Private Sub Command2_Click()
'9x
On Error Resume Next
SetStrings
nerr = NetShareAdd9x(0&, 50, SI50, ret)
Print nerr
End Sub
Private Sub Command3_Click()
'Delete
On Error Resume Next
If OSVERInfo.dwPlatformId = 1 Then
nerr = NetShareDel9x(0&, nPath, 0&)
Else
nerr = NetShareDelNT(0&, nPath, 0&)
Print nerr
End If
End Sub
Public Sub SetStrings()
If OSVERInfo.dwPlatformId = 1 Then
'9x OS
nPath = "NewShare"
ShareRemark = "Remark for new share"
SharePath = "C:\dos"
pwd = "Share"

SI50.shi50_netname = nPath
SI50.shi50_path = SharePath

SI50.shi50_remark = ShareRemark
SI50.shi50_type = STYPE_DISKTREE
SI50.shi50_ro_password = vbNullChar
SI50.shi50_rw_password = vbNullChar

Else
'NT OS
nPath = StrConv("NewShare", vbUnicode)
ShareRemark = StrConv("Remark for new share", vbUnicode)
SharePath = StrConv("C:\dos", vbUnicode)
pwd = StrConv("Share", vbUnicode)

SI502.shi502_current_uses = 0
SI502.shi502_max_uses = 10
SI502.shi502_netname = nPath
SI502.shi502_passwd = pwd
SI502.shi502_path = SharePath
SI502.shi502_permissions = ACCESS_ALL
SI502.shi502_remark = ShareRemark
SI502.shi502_reserved = 0
SI502.shi502_security_descriptor = Security
SI502.shi502_type = STYPE_DISKTREE

End If
End Sub
nik_Amis 2003-05-15
  • 打赏
  • 举报
回复
搜索一下,我看到过有类似的贴字
Bettyh 2003-05-15
  • 打赏
  • 举报
回复
??
liuchxing 2003-05-14
  • 打赏
  • 举报
回复
有没有具体代码?我也想知道!
Bettyh 2003-05-14
  • 打赏
  • 举报
回复
谢谢楼上!!
新建文件夹,重命名的API函数知道否?
道素 2003-05-14
  • 打赏
  • 举报
回复
NetShareAdd
Windows 95/98/Me 下 NetShareAdd 函数声明在 SVRAPI.DLL 动态连接库中,而在 2000/XP/NT 下声明在 NETAPI32.DLL 动态连接库中

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧