A voir également:
- [VB]socket:chat
- Vb - Télécharger - Langages
- Vb cable - Télécharger - Audio & Musique
- Vb editor - Télécharger - Langages
- Error 2002 (hy000): can't connect to local server through socket '/run/mysqld/mysqld.sock' (2) - Forum Bases de données
- Socket error soulseek - Forum Logiciels
3 réponses
1. Imports System
2. Imports System.Diagnostics
3. Imports System.Collections
4. Imports System.Runtime.InteropServices
5. Imports ActiveDs
6.
7. Namespace ADSI_Net
8. Class NetApi32
9. Public Enum NetError
10. NERR_Success = 0
11. NERR_BASE = 2100
12. NERR_UnknownDevDir = (NERR_BASE + 16)
13. NERR_DuplicateShare = (NERR_BASE + 18)
14. NERR_BufTooSmall = (NERR_BASE + 23)
15. End Enum
16.
17. Public Enum SHARE_TYPE As ULong
18. STYPE_DISKTREE = 0
19. STYPE_PRINTQ = 1
20. STYPE_DEVICE = 2
21. STYPE_IPC = 3
22. STYPE_SPECIAL = &H80000000
23. End Enum
24.
25. <StructLayout(LayoutKind.Sequential)> _
26. Public Structure SHARE_INFO_502
27. <MarshalAs(UnmanagedType.LPWStr)> _
28. Public shi502_netname As String
29. Public shi502_type As UInteger
30. <MarshalAs(UnmanagedType.LPWStr)> _
31. Public shi502_remark As String
32. Public shi502_permissions As Int32
33. Public shi502_max_uses As Int32
34. Public shi502_current_uses As Int32
35. <MarshalAs(UnmanagedType.LPWStr)> _
36. Public shi502_path As String
37. Public shi502_passwd As IntPtr
38. Public shi502_reserved As Int32
39. Public shi502_security_descriptor As IntPtr
40. End Structure
41.
42. <DllImport("Netapi32.dll")> _
43. Public Shared Function NetShareAdd(<MarshalAs(UnmanagedType.LPWStr)> ByVal strServer As String, ByVal dwLevel As Int32, ByVal buf As IntPtr, ByVal parm_err As IntPtr) As Integer
44. End Function
45.
46.
47. End Class
48.
49. Class AD_ShareUtil
50. <STAThread()> _
51. Private Shared Sub Main(ByVal args As String())
52. Dim strServer As String = "HellRaiser"
53. Dim strShareFolder As String = "G:\Mp3folder"
54. Dim strShareName As String = "MyMP3Share"
55. Dim strShareDesc As String = "Share to store MP3 files"
56. Dim nRetVal As NetApi32.NetError = 0
57. Dim shUtil As New AD_ShareUtil()
58. nRetVal = shUtil.CreateShare(strServer, strShareFolder, strShareName, strShareDesc, False)
59. If nRetVal = NetApi32.NetError.NERR_Success Then
60. Console.WriteLine("Share {0} created", strShareName)
61. ElseIf nRetVal = NetApi32.NetError.NERR_DuplicateShare Then
62. Console.WriteLine("Share {0} already exists", strShareName)
63. End If
64. End Sub
65.
66. Private Function CreateShare(ByVal strServer As String, ByVal strPath As String, ByVal strShareName As String, ByVal strShareDesc As String, ByVal bAdmin As Boolean) As NetApi32.NetError
67. Dim shInfo As NetApi32.SHARE_INFO_502 = New ADSI_Net.NetApi32.SHARE_INFO_502()
68. shInfo.shi502_netname = strShareName
69. shInfo.shi502_type = CUInt(NetApi32.SHARE_TYPE.STYPE_DISKTREE)
70. If bAdmin Then
71. shInfo.shi502_type = CUInt(NetApi32.SHARE_TYPE.STYPE_SPECIAL)
72. shInfo.shi502_netname += "$"
73. End If
74. shInfo.shi502_permissions = 0
75. shInfo.shi502_path = strPath
76. shInfo.shi502_passwd = IntPtr.Zero
77. shInfo.shi502_remark = strShareDesc
78. shInfo.shi502_max_uses = -1
79. shInfo.shi502_security_descriptor = IntPtr.Zero
80.
81. Dim strTargetServer As String = strServer
82. If strServer.Length <> 0 Then
83. strTargetServer = strServer
84. If strServer(0) <> "\"c Then
85. strTargetServer = "\\" & strServer
86. End If
87. End If
88. Dim nRetValue As Integer = 0
89. ' Call Net API to add the share..
90. Dim nStSize As Integer = Marshal.SizeOf(shInfo)
91. Dim buffer As IntPtr = Marshal.AllocCoTaskMem(nStSize)
92. Marshal.StructureToPtr(shInfo, buffer, False)
93. nRetValue = NetApi32.NetShareAdd(strTargetServer, 502, buffer, IntPtr.Zero)
94. Marshal.FreeCoTaskMem(buffer)
95.
96. Return DirectCast(nRetValue, NetApi32.NetError)
97. End Function
98. End Class
99. End Namespace
2. Imports System.Diagnostics
3. Imports System.Collections
4. Imports System.Runtime.InteropServices
5. Imports ActiveDs
6.
7. Namespace ADSI_Net
8. Class NetApi32
9. Public Enum NetError
10. NERR_Success = 0
11. NERR_BASE = 2100
12. NERR_UnknownDevDir = (NERR_BASE + 16)
13. NERR_DuplicateShare = (NERR_BASE + 18)
14. NERR_BufTooSmall = (NERR_BASE + 23)
15. End Enum
16.
17. Public Enum SHARE_TYPE As ULong
18. STYPE_DISKTREE = 0
19. STYPE_PRINTQ = 1
20. STYPE_DEVICE = 2
21. STYPE_IPC = 3
22. STYPE_SPECIAL = &H80000000
23. End Enum
24.
25. <StructLayout(LayoutKind.Sequential)> _
26. Public Structure SHARE_INFO_502
27. <MarshalAs(UnmanagedType.LPWStr)> _
28. Public shi502_netname As String
29. Public shi502_type As UInteger
30. <MarshalAs(UnmanagedType.LPWStr)> _
31. Public shi502_remark As String
32. Public shi502_permissions As Int32
33. Public shi502_max_uses As Int32
34. Public shi502_current_uses As Int32
35. <MarshalAs(UnmanagedType.LPWStr)> _
36. Public shi502_path As String
37. Public shi502_passwd As IntPtr
38. Public shi502_reserved As Int32
39. Public shi502_security_descriptor As IntPtr
40. End Structure
41.
42. <DllImport("Netapi32.dll")> _
43. Public Shared Function NetShareAdd(<MarshalAs(UnmanagedType.LPWStr)> ByVal strServer As String, ByVal dwLevel As Int32, ByVal buf As IntPtr, ByVal parm_err As IntPtr) As Integer
44. End Function
45.
46.
47. End Class
48.
49. Class AD_ShareUtil
50. <STAThread()> _
51. Private Shared Sub Main(ByVal args As String())
52. Dim strServer As String = "HellRaiser"
53. Dim strShareFolder As String = "G:\Mp3folder"
54. Dim strShareName As String = "MyMP3Share"
55. Dim strShareDesc As String = "Share to store MP3 files"
56. Dim nRetVal As NetApi32.NetError = 0
57. Dim shUtil As New AD_ShareUtil()
58. nRetVal = shUtil.CreateShare(strServer, strShareFolder, strShareName, strShareDesc, False)
59. If nRetVal = NetApi32.NetError.NERR_Success Then
60. Console.WriteLine("Share {0} created", strShareName)
61. ElseIf nRetVal = NetApi32.NetError.NERR_DuplicateShare Then
62. Console.WriteLine("Share {0} already exists", strShareName)
63. End If
64. End Sub
65.
66. Private Function CreateShare(ByVal strServer As String, ByVal strPath As String, ByVal strShareName As String, ByVal strShareDesc As String, ByVal bAdmin As Boolean) As NetApi32.NetError
67. Dim shInfo As NetApi32.SHARE_INFO_502 = New ADSI_Net.NetApi32.SHARE_INFO_502()
68. shInfo.shi502_netname = strShareName
69. shInfo.shi502_type = CUInt(NetApi32.SHARE_TYPE.STYPE_DISKTREE)
70. If bAdmin Then
71. shInfo.shi502_type = CUInt(NetApi32.SHARE_TYPE.STYPE_SPECIAL)
72. shInfo.shi502_netname += "$"
73. End If
74. shInfo.shi502_permissions = 0
75. shInfo.shi502_path = strPath
76. shInfo.shi502_passwd = IntPtr.Zero
77. shInfo.shi502_remark = strShareDesc
78. shInfo.shi502_max_uses = -1
79. shInfo.shi502_security_descriptor = IntPtr.Zero
80.
81. Dim strTargetServer As String = strServer
82. If strServer.Length <> 0 Then
83. strTargetServer = strServer
84. If strServer(0) <> "\"c Then
85. strTargetServer = "\\" & strServer
86. End If
87. End If
88. Dim nRetValue As Integer = 0
89. ' Call Net API to add the share..
90. Dim nStSize As Integer = Marshal.SizeOf(shInfo)
91. Dim buffer As IntPtr = Marshal.AllocCoTaskMem(nStSize)
92. Marshal.StructureToPtr(shInfo, buffer, False)
93. nRetValue = NetApi32.NetShareAdd(strTargetServer, 502, buffer, IntPtr.Zero)
94. Marshal.FreeCoTaskMem(buffer)
95.
96. Return DirectCast(nRetValue, NetApi32.NetError)
97. End Function
98. End Class
99. End Namespace