Form1.frm
资源名称:Share_win.rar [点击查看]
上传用户:wxknfb
上传日期:2022-08-10
资源大小:4k
文件大小:8k
源码类别:
网络编程
开发平台:
Visual Basic
- VERSION 5.00
- Begin VB.Form Form1
- BorderStyle = 1 'Fixed Single
- Caption = "添加一个共享"
- ClientHeight = 3000
- ClientLeft = 45
- ClientTop = 435
- ClientWidth = 3600
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 3000
- ScaleWidth = 3600
- StartUpPosition = 3 '窗口缺省
- Begin VB.TextBox Text5
- Height = 285
- Left = 2520
- TabIndex = 11
- Text = "12345678"
- Top = 1920
- Width = 975
- End
- Begin VB.TextBox Text4
- Height = 285
- Left = 720
- TabIndex = 9
- Text = "共享文件夹"
- Top = 720
- Width = 2775
- End
- Begin VB.TextBox Text3
- Height = 285
- Left = 720
- TabIndex = 7
- Text = "documentos"
- Top = 360
- Width = 2775
- End
- Begin VB.TextBox Text2
- Height = 285
- Left = 120
- TabIndex = 5
- Text = "C:winNT"
- Top = 1560
- Width = 3375
- End
- Begin VB.TextBox Text1
- Alignment = 2 'Center
- Height = 285
- Left = 720
- TabIndex = 3
- Text = "127.0.0.1"
- Top = 0
- Width = 2775
- End
- Begin VB.CommandButton Command2
- Caption = "删除共享"
- Height = 495
- Left = 1320
- TabIndex = 1
- Top = 2400
- Width = 1215
- End
- Begin VB.CommandButton Command1
- Caption = "添加共享"
- Height = 495
- Left = 120
- TabIndex = 0
- Top = 2400
- Width = 1215
- End
- Begin VB.Label Label5
- AutoSize = -1 'True
- Caption = "密码保护(最大 8 位长度):"
- Height = 180
- Left = 120
- TabIndex = 10
- Top = 1920
- Width = 2160
- End
- Begin VB.Label Label4
- AutoSize = -1 'True
- Caption = "注释:"
- Height = 180
- Left = 60
- TabIndex = 8
- Top = 780
- Width = 540
- End
- Begin VB.Label Label3
- AutoSize = -1 'True
- Caption = "网络名:"
- Height = 180
- Left = 60
- TabIndex = 6
- Top = 420
- Width = 720
- End
- Begin VB.Label Label2
- AutoSize = -1 'True
- Caption = "要共享的远程路径:"
- Height = 180
- Left = 120
- TabIndex = 4
- Top = 1320
- Width = 1620
- End
- Begin VB.Label Label1
- AutoSize = -1 'True
- Caption = "连接:"
- Height = 180
- Left = 60
- TabIndex = 2
- Top = 60
- Width = 540
- End
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '****************************************************************************
- '人人为我,我为人人
- '枕善居汉化收藏整理
- '发布日期:05/03/29
- '描述:一个共享远程文件夹源码示例
- '网站:http://www.mndsoft.com
- 'e-mail:mnd@mndsoft.com
- '****************************************************************************
- Option Explicit
- 'NET_API_STATUS NetShareAdd(
- ' LPTSTR servername,
- ' DWORD level,
- ' LPBYTE buf,
- ' LPDWORD parm_err
- ' );
- 'NET_API_STATUS NetShareDel(
- ' LPTSTR servername,
- ' LPTSTR netname,
- ' dword reserved
- ' );
- 'typedef struct _SHARE_INFO_502 {
- ' LPTSTR shi502_netname;
- ' DWORD shi502_type;
- ' LPTSTR shi502_remark;
- ' DWORD shi502_permissions;
- ' DWORD shi502_max_uses;
- ' DWORD shi502_current_uses;
- ' LPTSTR shi502_path;
- ' LPTSTR shi502_passwd;
- ' DWORD shi502_reserved;
- ' PSECURITY_DESCRIPTOR shi502_security_descriptor;
- '} SHARE_INFO_502, *PSHARE_INFO_502, *LPSHARE_INFO_502;
- Private Type ACL
- AclRevision As Byte
- Sbz1 As Byte
- AclSize As Integer
- AceCount As Integer
- Sbz2 As Integer
- End Type
- Private 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
- Private Type SHARE_INFO_502
- shi502_netname As String 'UNICODE
- shi502_type As Long
- shi502_remark As String 'UNICODE
- shi502_permissions As Long
- shi502_max_uses As Long
- shi502_current_uses As Long
- shi502_path As String 'UNICODE
- shi502_passwd As String 'UNICODE
- shi502_reserved As Long
- shi502_security_descriptor As SECURITY_DESCRIPTOR
- End Type
- Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
- Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
- Private Declare Function NetShareDel Lib "netapi32.dll" (ByVal servername As String, ByVal netname As String, ByVal reserved As Long) As Long
- Private Declare Function NetShareAdd Lib "netapi32.dll" (ByVal servername As String, ByVal level As Long, buf As SHARE_INFO_502, parm_err As Long) As Long
- Private Const STYPE_DISKTREE As Long = 0
- Private Const ACCESS_ATRIB As Long = &H20
- Private Const ACCESS_CREATE As Long = &H2
- Private Const ACCESS_DELETE As Long = &H10
- Private Const ACCESS_EXEC As Long = &H8
- Private Const ACCESS_WRITE As Long = &H2
- Private Const ACCESS_READ As Long = &H1
- Private Const ACCESS_PERM As Long = &H40
- Private Const ACCESS_ALL As Long = (ACCESS_READ Or ACCESS_WRITE Or ACCESS_CREATE Or ACCESS_EXEC Or ACCESS_DELETE Or ACCESS_ATRIB Or ACCESS_PERM)
- Private Const SHPWLEN As Long = 8
- Dim i As Long
- '添加共享
- Private Sub Command1_Click()
- Dim res As Long
- Dim par_err As Long
- Dim password As String
- Dim share As SHARE_INFO_502
- Dim ruta As String
- password = "manuel" & vbNullChar
- If Len(password) > SHPWLEN + 1 Then: Exit Sub
- If Text1 = "" Or Text1 = "127.0.0.1" Then
- ruta = SetFolder(Me.hwnd, "ShareFolderADD")
- Else
- ruta = Text2
- End If
- share.shi502_netname = StrConv(Text3, vbUnicode)
- share.shi502_type = STYPE_DISKTREE
- share.shi502_remark = StrConv(Text4, vbUnicode)
- share.shi502_permissions = ACCESS_ALL
- share.shi502_max_uses = &HFFFFFFFF ' = -1
- share.shi502_current_uses = 1
- share.shi502_path = StrConv(ruta, vbUnicode)
- share.shi502_passwd = StrConv(password, vbUnicode)
- share.shi502_reserved = 0&
- share.shi502_security_descriptor.Owner = &H50
- share.shi502_security_descriptor.Group = 0&
- share.shi502_security_descriptor.Control = 0&
- res = NetShareAdd(StrConv("\" & Text1, vbUnicode), 502, share, par_err)
- If res = 0 Then
- MsgBox LastErrorApi(res), vbInformation, "添加共享"
- Else
- MsgBox LastErrorApi(res), vbCritical, "添加共享"
- End If
- End Sub
- Public Function LastErrorApi(errordll As Long) As String
- Dim res As Long
- Dim s As String
- s = String(255, vbNullChar)
- res = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, errordll, 0, s, Len(s), 255)
- If res <> 0 Then LastErrorApi = Left(s, res)
- End Function
- '删除共享
- Private Sub Command2_Click()
- Dim res As Long
- res = NetShareDel(StrConv("\" & Text1, vbUnicode), StrConv("documentos", vbUnicode), 0&)
- If res = 0 Then
- MsgBox LastErrorApi(res), vbInformation, "删除共享"
- Else
- MsgBox LastErrorApi(res), vbCritical, "删除共享"
- End If
- End Sub