我想把這個VBScript寫成VB.NET。但它不工作.... 這裏我的VBScript:VB.NET中的VBScript,錯誤信息
'VBScript
Dim strServer
strServer = "LP-BK"
Set objConnection = GetObject("WinNT://" & strServer & "/LanmanServer")
Set colSessions = objConnection.Sessions
on error resume next
For Each objSession in colSessions
Msgbox("objSession Computer is: " & objSession.Computer)
Msgbox("objSession User is: " & objSession.User)
Next
Set objConnection = nothing
Set ColResources = nothing
Set colSessions = nothing
這是我的VB.Net代碼,它不工作。
'Imports ActiveDs
'and add a reference on the com tab to Active DS Type Library
Private Sub bSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bSave.Click
Dim fso As IADsFileServiceOperations
On Error GoTo Cleanup
fso = GetObject("WinNT://LP-BK/LanmanServer") ' There is a error: Option Strict On disallows implicit conversions from 'Object' to 'ActiveDs.IADsFileServiceOperations'.
For Each session In fso.Sessions
MsgBox(session.Computer) ' Error: Option Strict On disallows late binding.
Next
Cleanup:
If (Err.Number <> 0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
fso = Nothing
End Sub
我希望你能幫助MEE .... 很多感謝 問候
編輯:有人什麼想法?
你有沒有試圖明確地轉換你的'GetObject'結果? –
HI喬治,謝謝你的回答。你究竟意味着什麼「鑄造你的getobject結果」? –