1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
Imports System.Net
Imports System.Text.RegularExpressions
Imports System.Runtime.InteropServices
Imports System.Text
Imports MySql.Data.MySqlClient
Imports System.Net.Mime.MediaTypeNames
Module Module1
Dim ServerString As String = "server=xxxxxxxxxxxx;User Id=sistool;Password=xxxxxxxxxx;Database=right"
Dim SQLConnection As MySqlConnection = New MySqlConnection
Public Sub Main1()
Dim SRV_Name As String = System.Net.Dns.GetHostName
Console.WriteLine(SRV_Name)
End Sub
<DllImport("Netapi32.dll", CharSet:=CharSet.Unicode)> _
Private Function NetShareEnum(ByVal ServerName As [String], ByVal level As Integer, ByRef bufPtr As IntPtr, ByVal prefmaxlen As UInteger, ByRef entriesread As Integer, ByRef totalentries As Integer, _
ByRef resume_handle As Integer) As Integer
End Function
<DllImport("Netapi32.dll", SetLastError:=True)> _
Function NetApiBufferFree(ByVal Buffer As IntPtr) As Integer
End Function
Public Structure SHARE_INFO_2
<MarshalAs(UnmanagedType.LPWStr)> _
Public shi2_netname As String
Public shi2_type As UInteger
<MarshalAs(UnmanagedType.LPWStr)> _
Public shi2_remark As String
Public shi2_permissions As Int32
Public shi2_max_uses As Int32
Public shi2_current_uses As Int32
<MarshalAs(UnmanagedType.LPWStr)> _
Public shi2_path As String
<MarshalAs(UnmanagedType.LPWStr)> _
Public shi2_passwd As String
End Structure
Public Sub Main()
SQLConnection.ConnectionString = ServerString
Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
Console.Out.WriteLine("Successfully Connected to Mysql Database")
Else
'SQLConnection.Close()
Console.Out.WriteLine("Connection is closed")
End If
Catch ex As Exception
Console.Out.WriteLine(ex.ToString)
End Try
Dim Servername As [String] = "NOHVFS01"
Dim level As Integer = 2
Dim prefmaxlen As UInteger = 368880
Dim entriesread As Integer = 0
Dim totalentries As Integer = 0
Dim resume_handle As Integer = 0
Dim bufPtr As IntPtr = IntPtr.Zero
Dim ret As Integer = NetShareEnum(Servername, level, bufPtr, prefmaxlen, entriesread, totalentries, _
resume_handle)
Dim currentPtr As IntPtr = bufPtr
Dim nStructSize As Integer = Marshal.SizeOf(GetType(SHARE_INFO_2))
Dim t As Integer = 0
Dim i As Integer = 0
Dim Debut, Fin As DateTime
Dim Duree As TimeSpan
Debut = Now
While i < entriesread
Dim shio As SHARE_INFO_2 = DirectCast(Marshal.PtrToStructure(currentPtr, GetType(SHARE_INFO_2)), SHARE_INFO_2)
Dim tst As String = Replace(shio.shi2_path, "\", "\\")
'Dim SQLStatement As String = "INSERT INTO right_info(hostname,locpath,sharenm) VALUES ('" & t & "','" & tst & "','" & shio.shi2_netname & "')"
'Dim SQLStatement As String = "INSERT INTO right_info(locpath,sharenm) VALUES ('" & t & "','" & t & "')"
Console.Out.WriteLine("Partage: " + shio.shi2_netname + shio.shi2_path) '+ vbLf)
Console.Out.WriteLine(shio.shi2_permissions)
Console.Out.WriteLine(shio.shi2_current_uses)
Console.Out.WriteLine(t)
'SaveNames(SQLStatement)
Pause(0.6)
currentPtr = New IntPtr(currentPtr.ToInt32() + nStructSize)
System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)
t = t + 1
End While
Fin = Now
Duree = Fin - Debut
Console.Out.WriteLine(Duree)
NetApiBufferFree(bufPtr)
End Sub
Public Sub SaveNames(ByRef SQLStatement As String)
Dim cmd As MySqlCommand = New MySqlCommand
With cmd
.CommandText = SQLStatement
.CommandType = CommandType.Text
.Connection = SQLConnection
.BeginExecuteNonQuery()
End With
'SQLConnection.Close()
'Console.Out.WriteLine("Successfully Added!")
'SQLConnection.Dispose()
End Sub
Public Sub Pause(ByVal duration As Long)
Dim Current As Long
Current = Timer
Do Until Timer - Current >= duration
Loop
End Sub
End Module |