【发布时间】:2022-06-11 10:36:11
【问题描述】:
我有一个播放 mp3 的 vbs 脚本,正常的做法是通过将 mp3 文件拖到 vbs 来调用它或使用命令行指定 mp3。
Set objArgs = Wscript.Arguments
if (objArgs.Count = 0) then
Wscript.echo "Necesito un archivo MP3"
WScript.Quit 123
end if
'Wscript.echo "Playing: " & objArgs(0) & "..."
Set objPlayer = createobject("Wmplayer.OCX.7")
With objPlayer ' saves typing
.settings.autoStart = True
.settings.volume = 100 ' 0 - 100
.settings.balance = 0 ' -100 to 100
.settings.enableErrorDialogs = False
.enableContextMenu = False
.URL = objArgs(0)
WScript.Sleep(10000) ' time to load and start playing
'.Controls.Pause() ' stop
End With
WScript.Quit 0
' MsgBox "if WMP is still playing, clicking OK will end it", _
' vbInformation, "WMP Demo finished"
为了简单起见,我需要在不创建 vbs 文件的情况下调用此代码。 这可以通过 Windows API 完成吗?
例如
callvbsfunction("mycodevbs")
并运行它?
当我提到 windows api 时,我指的是类似于这些的功能
MessageBox( 0, "Test", "Title here", MB_OK )
GetSystemMetrics( SM_CXSCREEN )
ShellExecute( 0, "open", "c:\myfile.txt", 0, 0, 1 )
Beep( 1000, 250 )
还有更多...
【问题讨论】:
-
您可以使用custom COM capable DLL 使用Windows API。不幸的是,无法使用 VBScript 开箱即用地访问 Windows API。
-
@user692942 即使 .NET 很难注册支持 COM 的 DLL,你是否要编写这个支持 COM 的 DLL。
-
@user18521918 如果他们想在 VBScript 中使用 Windows API,那就是过程。