0

我想将此 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

我希望你能帮助我......非常感谢提前问候

编辑:有人知道吗?

4

1 回答 1

0

为了让你继续前进,你可以Option Strict Off在班级的顶部添加。这样它会更像 VBScript。

从长远来看,尽管您将希望重新编写它,以便与 Option Strict On 一起编译

如果您希望有人为您将 VBScript 代码翻译成 VB.NET 代码,那么您来错地方了。

于 2013-05-22T13:05:28.347 回答