2013-05-22 32 views
0

我想把這個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 .... 很多感謝 問候

編輯:有人什麼想法?

+0

你有沒有試圖明確地轉換你的'GetObject'結果? –

+0

HI喬治,謝謝你的回答。你究竟意味着什麼「鑄造你的getobject結果」? –

回答

0

爲了讓你去,你可以在你的班級頂部添加Option Strict Off。這樣它會更像VBScript。

從長遠來看,雖然你會想重新寫這樣才符合選項嚴格在

如果你希望有人翻譯VBScript代碼到VB.NET代碼編譯爲你,那麼你已經來到了錯誤的地方。

+0

是的,我不會寫選項嚴格關閉...它沒關係,是嚴格的選項..但問題是更多,如果它的選項嚴格的代碼如何? –

+0

是的,但那不能解決我的問題/問題。否則,不正確地理解你。 –