我写了一个简单的脚本在消息框上按ok但它不起作用。请帮我怎么做 这是示例代码
set oWShell = createobject("WScript.Shell")
MsgBox "Hello"
WScript.Sleep 2000
oWShell.Sendkeys "{enter}"
答案 0 :(得分:0)
MsgBox等待点击。如果你没有点击自己,就永远不会“睡觉”或“发送钥匙”。
我认为你只是想学习,因为这段代码毫无意义。如果您想按下另一个程序窗口上的按钮,这可能会起作用。但是在它自己的过程中这不起作用。
如果您确实想要单击自己的MsgBox,则必须使用单独的脚本。一个创建MsgBox,另一个创建按钮。
答案 1 :(得分:0)
如果您只想在一段时间后关闭消息框,请查看Popup()
课程的WshShell
方法。它的第二个参数指定在关闭它之前显示消息框的秒数。
With CreateObject("WScript.Shell")
' Display a message box that disappears after two seconds...
.Popup "Hello", 2
End With
答案 2 :(得分:0)
如何在消息框中单击按钮并在此处控制显示时间,脚本可以做到这一点。
只需复制此行代码并粘贴到文本文件中,然后将其另存为“ ControlMsgBox.vbs”即可。
''' IN THE NAME OF ALLAH
' THIS SCRIPT CONTROL OF MSGBOX DISPLAY TIME
' LET SENKEYS DEAL WITH THE MSGBOX
' SOLVE THE PROBLEM OF APPACTIVATE NOT WORKING EFFECTIVE
On Error Resume Next
Dim Sh : Set Sh=CreateObject("wscript.shell") ' declare and create the wshshell
Dim path : path =Replace(WScript.ScriptFullName,WScript.ScriptName,"") 'declare the variable of the current script path
Dim myMessage : myMessage="This is my message ." 'declare variable of the of the display text of msgbox
Sh.run "cmd.exe /c cd """&path&""" && echo msgbox """&myMessage&""",,""In_The_Name_Of_Allah"" > mymsgbox.vbs",0,false 'create masgbox script in the same path
WScript.Sleep 1000 'wait 1 sec to let process of create msgbox script execute
Sh.run "mymsgbox.vbs" 'run the created msgbox script
WScript.Sleep 3000 ' let the msgbox display for 3 sec before we sendkeys to close
For i=0 To 600 ' loop to retry select correct msgbox window about 1 min
ret = Sh.AppActivate("In_The_Name_Of_Allah") 'select the activate msgbox window (if this loop 300 this mean loop will continue 30 sec if 600 (1 min)
If ret = True Then ' check if the msgbox windows select or not
Sh.SendKeys "%N" 'send key of Alt+N to select first button in msgbox (ok)
End If
ret = Sh.AppActivate("In_The_Name_Of_Allah") 'recheck again to be sure that we will not send key out of target windows (msgbox window)
If ret = True Then
Sh.SendKeys "{enter}" ' send key to click enter
wscript.sleep 500
ret=Sh.AppActivate("In_The_Name_Of_Allah")
If ret=False Then ' using nested IF to sure of selected windows is false because its close
Exit For ' exit for loop directly and execute what after for next
End If
End If
WScript.Sleep 100
Next
With CreateObject("Scripting.FileSystemObject")
If .FileExists(path&"mymsgbox.vbs") Then 'check if the msgbox script we create form this script exist or not
.DeleteFile(path&"mymsgbox.vbs") 'delete the msgbox script we create after message window closed
End If
End With
Set Sh=Nothing 'remove the sh object create
WScript.Quit ' terminate wscript.exe instance who run this script
答案 3 :(得分:0)
检查这个site
您需要这个:
设置objArgs = WScript.Arguments
messageText = objArgs(0)
MsgBox messageText,51,“警告...!”