1
我想從另一臺計算機(它有一個密碼)讀取共享文件的內容。我搜索在谷歌如何訪問該文件,我在我自己的代碼:閱讀共享文件的內容
Option Explicit On
Public Class Form1
Dim file As New Scripting.FileSystemObject
Dim readfile As Scripting.TextStream
Private Structure NETRESOURCE
Public dwScope As UInteger
Public dwType As UInteger
Public dwDisplayType As UInteger
Public dwUsage As UInteger
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Structure
Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _
"WNetAddConnection2A" (lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, ByVal lpUserName As String, _
ByVal dwFlags As Long) As Long
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _
"WNetCancelConnection2A" (ByVal lpName As String, _
ByVal dwFlags As Long, ByVal fForce As Long) As Long
Private Const NO_ERROR As UInteger = 0
Private Const RESOURCETYPE_DISK As UInteger = 1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'' readfile = file.OpenTextFile(Process.Start("net.exe", "use \\Reznicencu-2025\share /USER:Reznicencu Reznicencu".ToString), Scripting.IOMode.ForReading)
''MsgBox(readfile.ReadAll)
Test()
End Sub
Private Sub Test()
Dim nr As New NETRESOURCE
nr.dwType = RESOURCETYPE_DISK
nr.lpRemoteName = "\\Reznicencu-2025\share"
If WNetAddConnection2(nr, "Reznicencu", "Reznicencu", 0) <> NO_ERROR Then
Throw New Exception("WNetAddConnection2 failed.")
End If
'Code to use connection here.'
If WNetCancelConnection2("\\Reznicencu-2025\share", 0, True) <> NO_ERROR Then
Throw New Exception("WNetCancelConnection2 failed.")
End If
End Sub
End Class
我不知道這是否是正確的,因爲它告訴我,「‘lpNetResource’不能在命名空間暴露型」NETRESOURCE「使者'通過班'Form1'「,你能幫我嗎?