0

如何在 VBScript 中使用别名?我正在尝试以下代码:

AliasesExample
Sub AliasesExample
  Dim AliasObj
  ' Obtains the object that corresponds to the Notepad main window
  Set AliasObj = Aliases.notepad.wndNotepad
  ' Checks whether the specified window exists
  If AliasObj.Exists Then
    ' Enters text in the Notepad editor
    AliasObj.Keys("Hello, world.")
  Else
    Log.Error("Notepad is not running.")
  End If
End Sub

但出现以下错误:

object required: 'Aliases'
4

1 回答 1

1

VBScript 和 Windows Script Host 不支持调用 DLL 和 Windows API 函数,但有一些可能的解决方案:

  • 您可以调用通过 COM 对象公开的 DLL 函数:

    Set obj = CreateObject("Foo.Bar")
    Call obj.Method(Param1, Param2)
    
  • 如果 DLL 和函数满足某些要求,您也许可以调用一些 DLL 函数。 rundll32

    ' Open "Programs and Features" using the Control_RunDLL function from shell32.dll
    Set oShell = CreateObject("WScript.Shell")
    oShell.Run "rundll32.exe shell32.dll Control_RunDLL appwiz.cpl,,0"
    

除此之外,你运气不好。

所以一般来说,您的 DLL 函数需要一个 COM 可调用的包装器,以便能够从 VBScript 中使用它。

于 2014-04-11T11:12:59.663 回答