VB脚本按enter而不是单击按钮

时间:2015-08-17 20:05:53

标签: vbscript return enter

我有一个脚本,只有一个文本框和一个按钮才能继续。现在你必须单击按钮或按选项卡然后输入。如何从文本框中发送输入以继续?感谢。

此外,一个可能没有答案的附带问题。它保存为.hta并在Windows Sysprep进程之前运行。如果它在笔记本电脑上运行,并且盖子在启动时关闭,则屏幕完全空白。我可以按 tab + 输入继续,就像我看到它一样,然后再次重新启动它。任何想法为什么它的空白以及如何使它显示总是将非常感激。

<html>
<head>
<title>Sysprep Deployment</title>
<HTA:APPLICATION 
     ID="objCompDeploy" 
     APPLICATIONNAME="Sysprep Deployment"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     maximizeButton="no"
     minimizeButton="no"
     sysMenu="yes"
>
</head>
<SCRIPT LANGUAGE="VBScript">

Set WshShell = CreateObject("Wscript.Shell")

Sub Window_onLoad
window.resizeTo 400,200
ComputerNameArea.Focus
  CreateObject("WScript.Shell").SendKeys "^{Home}"

'turn off setup flag in registry so we can query wmi
WshShell.RegWrite "HKLM\SYSTEM\Setup\SystemSetupInProgress", 0, "REG_DWORD"

'query wmi for serial number
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      serialNumber = objItem.SerialNumber
   Next

'turn setup flag back on
WshShell.RegWrite "HKLM\SYSTEM\Setup\SystemSetupInProgress", 1, "REG_DWORD"

'put the serial number that was retrieved in the textbox
ComputerNameArea.Value = serialNumber

End Sub 

Sub modUnattend

run_button.Disabled = True

Set fso = CreateObject("Scripting.FileSystemObject")

base = Wshshell.ExpandEnvironmentStrings("%SystemRoot%")
unattendFile = base & "\Panther\unattend.xml"

   computerName = ComputerNameArea.Value

 Set xmlDoc = CreateObject("Microsoft.XMLDOM")
 xmlDoc.load unattendFile

 'Iterate through Unattend.xml searching for nodes and properties to replace
 Set oNodes = xmlDoc.documentElement.selectNodes("/unattend/settings/component/ComputerName")
 For each n in oNodes
  n.text = computerName
  xmlDoc.save unattendFile
 Next


'launch the continuation of setup in a hidden window and wait for return
'if we dont wait, closing mshta, closes windeploy.exe
WshShell.Run "%WINDIR%\System32\oobe\windeploy.exe", 0, True
idTimer = window.setTimeout("closeHTA", 5000, "VBScript")
End Sub

Sub closeHTA
window.close
End Sub

Sub commandLine
WshShell.Run "%WINDIR%\System32\cmd.exe", 1, True
End Sub

</SCRIPT>
<body>
<table border="0">
<tr>
<td>Computer Name:</td>
<td><input type="text" name="ComputerNameArea" size="30" maxlength="15" value="computer"></td>
</tr>
<tr>
<td>Tab then Enter to Continue</td>
</tr>
</table> 
<p align="right">
<input id=runbutton  class="button" type="button" value="Continue" name="run_button" onClick="modUnattend">
</body>

2 个答案:

答案 0 :(得分:1)

您可以尝试输入提交,而不是按钮

<input id=runbutton  class="button" type="Submit" value="Continue" name="run_button" onClick="modUnattend">

答案 1 :(得分:0)

我不是100%确定这会有效,我在回车键上添加了一个EventListener,并在按下回车键时触发了点击事件

<input id=runbutton  class="button" type="button" value="Continue" name="run_button" onKeyDown="if (event.keyCode == 13){ this.click }" onClick="modUnattend">