Re: Netzlaufwerk verbinden und trennen



"Jens Gerber" <gerber.jens-nospam-@xxxxxxxx> schrieb:
hier eine Möglichkeit wo gleichzeitig noch geprüft wird ob das Netzlaufwerk schon verbunden
ist (mit Schreibrechten auf diesem):

#Region " Network via API "

Private Const CONNECT_INTERACTIVE As Long = &H8

Private Const RESOURCETYPE_DISK As Long = &H1

.... wohl 'As Int32'.

Friend Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _

"WNetAddConnection2A" (<Runtime.InteropServices.MarshalAs(UnmanagedType.Struct)> ByRef lpNetResource _

As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, _

ByVal dwFlags As Integer) As Integer

Das Attribut kannst Du einsparen, dafür sehe ich keinen Grund, die ANSI-Version der Funktion zu verwenden. Besser: 'Declare Auto Function...' ohne 'Alias'.

Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _

"WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As _

Integer, ByVal fForce As Integer) As Integer

Dito.

Dim w As StreamWriter = File.CreateText(path & "\test.txt")

w.WriteLine("test")

w.Flush()

w.Close()

'Close' bzw. 'Dispose' rufen intern wohl auch 'Flush' auf.

File.Delete(path & "\test.txt")

Besser: 'System.IO.Path.Combine'.

Public Shared Sub NetDisConnect(ByVal path)

'Path As String'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

.



Relevant Pages

  • Re: Copy File progress...
    ... (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal ... Private Const PROGRESS_CONTINUE As Long = 0 ... > progress and one for overall progress. ... I've read some thread about using the SHFileOperation API ...
    (microsoft.public.dotnet.general)
  • Re: Mass delete files and directories
    ... Private Type SHFILEOPSTRUCT ... pFrom As String ... Private Const FOF_SIMPLEPROGRESS As Integer = &H100 ... I've looked several places and am familiar woth API calls, but have found nothing that helps me much. ...
    (microsoft.public.vb.general.discussion)
  • Re: New Desktop Folder
    ... There are API specifically designed for this. ... Private Declare Function SHGetSpecialFolderPathA Lib "shell32" (ByVal hwnd As Long, ByVal path As String, ByVal csidl As Long, fCreate As Long) As Long ... Private Const CSIDL_DESKTOPDIRECTORY = &H10 ... "Alexm" wrote in message ...
    (microsoft.public.vb.general.discussion)
  • Re: how do i close an app that has no forms?
    ... I have lots of API calls. ... Private Declare Function GetDesktopWindow _ ... ByVal lpOperation As String, _ ... ByVal dwFlags As Long, _ ...
    (microsoft.public.vb.general.discussion)
  • Re: Delete a Workbook via code
    ... windows api? ... Private Const ERROR_SUCCESS = 0& ... Private Type SHFILEOPSTRUCT ... pFrom As String ...
    (microsoft.public.excel.programming)