VB 脚本按回车而不是点击按钮
VB Script press enter instead of click button
我的脚本只有一个文本框和一个继续按钮。现在您必须单击按钮或按 tab,然后按 enter。如何从文本框中发送 enter 以继续?谢谢
另外,一个可能没有答案的问题。这被保存为 .hta
并在 Windows Sysprep 进程之前运行。如果它在笔记本电脑上运行,启动时盖子是合上的,屏幕是完全空白的。我可以按 tab + enter 让它继续,就像我看到它一样,然后当它重新启动时它又好了。任何关于为什么它的空白以及如何让它始终显示的想法将不胜感激。
<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>
我不是 100% 确定这会起作用,我向回车键添加了一个 EventListener 并让它在按下回车键时触发点击事件
<input id=runbutton class="button" type="button" value="Continue" name="run_button" onKeyDown="if (event.keyCode == 13){ this.click }" onClick="modUnattend">
您可以尝试输入 提交 而不是 按钮 !
<input id=runbutton class="button" type="Submit" value="Continue" name="run_button" onClick="modUnattend">
我的脚本只有一个文本框和一个继续按钮。现在您必须单击按钮或按 tab,然后按 enter。如何从文本框中发送 enter 以继续?谢谢
另外,一个可能没有答案的问题。这被保存为 .hta
并在 Windows Sysprep 进程之前运行。如果它在笔记本电脑上运行,启动时盖子是合上的,屏幕是完全空白的。我可以按 tab + enter 让它继续,就像我看到它一样,然后当它重新启动时它又好了。任何关于为什么它的空白以及如何让它始终显示的想法将不胜感激。
<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>
我不是 100% 确定这会起作用,我向回车键添加了一个 EventListener 并让它在按下回车键时触发点击事件
<input id=runbutton class="button" type="button" value="Continue" name="run_button" onKeyDown="if (event.keyCode == 13){ this.click }" onClick="modUnattend">
您可以尝试输入 提交 而不是 按钮 !
<input id=runbutton class="button" type="Submit" value="Continue" name="run_button" onClick="modUnattend">