fil.txt ikke fil.exe som jeg skrev til sidst, når der er en > så overskriver den filen man skriver efter > tegnet, hvis der er to >>fil.txt tilføjer den teksten til slutningen af filen
Duer ikke fordi Net.exe ikke kender noget til redirigering af standard-output (større-end tegnet). Det gør din kommandofortolker (også kaldet shell) derimod. Den hedder blot noget forskelligt afhængig af operativsystemet, men heldigvis er der sættes standardmæssigt en environment-variabel til at pege på den aktuelle kommandofortolker.
Brug derfor i stedet:
Shell Environ(\"COMSPEC\") & \" /C Net Use >fil.txt\"
Bortset fra det, så skal du bruge API-kaldene WNetOpenEnum og WNetEnumResource, hvis du ikke ønsker at bruge Net Use.
Her er et lille eksempel, som jeg har lånt fra Microsoft, men som virker??? Men som har en lille krølle: Er der INGEN netværksforbindelser, meldes fejl 259 - men det må du selv pille ved:
Opret et standard EXE projekt, og kopier følgende kode ind i Form1:
Private Declare Function GlobalAlloc Lib \"KERNEL32\" ( _ ByVal wFlags As Long, ByVal dwBytes As Long) As Long Private Declare Function GlobalFree Lib \"KERNEL32\" ( _ ByVal hMem As Long) As Long
Private Declare Sub CopyMemory Lib \"KERNEL32\" Alias \"RtlMoveMemory\" _ (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function CopyPointer2String Lib \"KERNEL32\" _ Alias \"lstrcpyA\" ( _ ByVal NewString As String, ByVal OldString As Long) As Long
Private Sub Form_click() Dim hEnum As Long, lpBuff As Long, nr As NETRESOURCE Dim cbBuff As Long, cCount As Long Dim p As Long, res As Long, i As Long
\'Open a Net enumeration operation handle: hEnum. res = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, _ 0, nr, hEnum) If res = 0 Then \'Create a buffer large enough for the results. \'1000 bytes should be sufficient. lpBuff = GlobalAlloc(GPTR, cbBuff) \'Call the enumeration function. res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff) If res = 0 Then p = lpBuff Cls \'WNetEnumResource fills the buffer with an array of \'NETRESOURCE structures. Walk through the list and print \'each local and remote name. For i = 1 To cCount CopyMemory nr, ByVal p, LenB(nr) p = p + LenB(nr) Print PointerToString(nr.lpLocalName), _ PointerToString(nr.lpRemoteName) Next i Else MsgBox \"Error: \" & Err.LastDllError, vbOKOnly, \"WNetEnumResources\" End If If lpBuff <> 0 Then GlobalFree (lpBuff) WNetCloseEnum (hEnum) \'Close the enumeration Else MsgBox \"Error: \" & Err.LastDllError, vbOKOnly, \"WNetOpenEnum\" End If End Sub
Private Function PointerToString(p As Long) As String \'The values returned in the NETRESOURCE structures are pointers to \'ANSI strings so they need to be converted to Visual Basic Strings. Dim s As String s = String(255, Chr$(0)) CopyPointer2String s, p PointerToString = Left(s, InStr(s, Chr$(0)) - 1) End Function --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut --- cut ---
Tilføj et kode-modul og kopier følgende til dette:
Public Type NETRESOURCE dwScope As Long dwType As Long dwDisplayType As Long dwUsage As Long lpLocalName As Long lpRemoteName As Long lpComment As Long lpProvider As Long End Type
Public Declare Function WNetOpenEnum Lib \"mpr.dll\" Alias _ \"WNetOpenEnumA\" ( _ ByVal dwScope As Long, _ ByVal dwType As Long, _ ByVal dwUsage As Long, _ lpNetResource As Any, _ lphEnum As Long) As Long
Public Declare Function WNetEnumResource Lib \"mpr.dll\" Alias _ \"WNetEnumResourceA\" ( _ ByVal hEnum As Long, _ lpcCount As Long, _ ByVal lpBuffer As Long, _ lpBufferSize As Long) As Long
Public Declare Function WNetCloseEnum Lib \"mpr.dll\" ( _ ByVal hEnum As Long) As Long
\'RESOURCE ENUMERATION. Public Const RESOURCE_CONNECTED = &H1 Public Const RESOURCE_GLOBALNET = &H2 Public Const RESOURCE_REMEMBERED = &H3
Public Const RESOURCETYPE_ANY = &H0 Public Const RESOURCETYPE_DISK = &H1 Public Const RESOURCETYPE_PRINT = &H2 Public Const RESOURCETYPE_UNKNOWN = &HFFFF
Mange tak for jeres svar, et af dem var lige vad jeg skulle bruge.
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.