Public Declare Function WNetAddConnection2 _ Lib "mpr.dll" Alias "WNetAddConnection2A" _ ( ByRef lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer Public Declare Function WNetCancelConnection2 _ Lib "mpr" Alias "WNetCancelConnection2A" _ ( ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer <structlayout(layoutkind.sequential)> Public Structure NETRESOURCE Public dwScope As Integer Public dwType As Integer Public dwDisplayType As Integer Public dwUsage As Integer Public lpLocalName As String Public lpRemoteName As String Public lpComment As String Public lpProvider As String End Structure ' Public Const ForceDisconnect As Integer = 1 Public Const RESOURCETYPE_DISK As Long = &H1 ''' <summary> ''' Maps a UNC path to a specific drive. ''' </summary> ''' <param name="DriveLetter"></param> ''' <param name="UNCPath"></param> ''' <returns></returns> ''' <remarks></remarks> Public Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String) As Boolean Dim nr As NETRESOURCE Dim Username As String Dim Password As String nr = New NETRESOURCE nr.lpRemoteName = UNCPath nr.lpLocalName = DriveLetter & ":" Username = Nothing '(add parameters to pass this if necessary) Password = Nothing '(add parameters to pass this if necessary) nr.dwType = RESOURCETYPE_DISK Dim result As Integer result = WNetAddConnection2(nr, Password, Username, 0) If result = 0 Then Return True Else Return False End If End Function
Private Sub Command_Click() Dim startInfo As ProcessStartInfo startInfo = New System.Diagnostics.ProcessStartInfo("cmd.exe", """NET USE F: \\xxxxxxxxx\CSC Backup""") End Sub Dim procID As Integer Dim newProc As Diagnostics.Process newProc = Diagnostics.Process.Start("C:\WINDOWS\SYSTEM32\NET.EXE") procID = newProc.SessionId procID = Shell("""net use F: \\xxxxxxx\csc backup")</structlayout(layoutkind.sequential)>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)