我是VBS脚本的新手,我正在尝试掌握我们目前正在使用的脚本来设置工作站的特定设置。
我已根据我们更新的需求修改了脚本,但在尝试运行时遇到错误。
错误:需要对象:'document.getElementById(....)'
非常感谢任何帮助!
'******************IE Interface Starts******************************************
Public skipexit
Dim oIE ' declare variables
Dim path
Dim oBut, oBut2
Dim ready
' *** get script path -> because form (HTML file)
' *** must be in the same folder!!!
path = WScript.ScriptFullName
path = Left(path, InstrRev(path, "\"))
' *** launch Internet Explorer ***
Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
oIE.left = 250 ' window position
oIE.top = 250 ' and other properties
oIE.height = 595
oIE.width = 530
oIE.menubar = 0 ' no menu
oIE.toolbar = 0
oIE.statusbar = 0
' commented out, because it causes a corrupted window
oIE.resizable = 0 ' disable resizing
oIE.navigate path & "options.php" ' Form
oIE.visible = 1 ' keep visible
' Important: wait till MSIE is ready
Do While (oIE.Busy)
WScript.Sleep 100 ' suspend, just to lower CPU load
Loop
' now connect the event handler
Set oBut = oIE.document.getElementById ("Run")
Set oBut.onclick = GetRef ("GetFormValue")
Set oBut2 = oIE.document.getElementById ("Cancel")
Set oBut2.onclick = GetRef ("EndProgram")
'****Values
oIE.Document.ValidForm.DisableNICpowermanagement.checked = True
oIE.Document.ValidForm.BSODrestartDisable.checked = True
oIE.Document.ValidForm.DisplaySettings.checked = True
oIE.Document.ValidForm.SysTrayNoHide.checked = True
oIE.Document.ValidForm.WindowsUpdate.checked = True
oIE.Document.ValidForm.RDPenable.checked = True
oIE.Document.ValidForm.USBPowerManagementDisable.checked = True
oIE.Document.ValidForm.ServicesDisable.checked = True
oIE.Document.ValidForm.SyncOfflineFilesDisable.checked = False
oIE.Document.ValidForm.ShowHiddenFiles.checked = True
oIE.Document.ValidForm.SetVirtualMem.checked = True
oIE.Document.ValidForm.PowerManagment.checked = True
oIE.Document.ValidForm.AddRegistryFavorites.checked = True
oIE.Document.ValidForm.W32TimeServer.checked = True
oIE.Document.ValidForm.ActionCenter.checked = True
oIE.Document.ValidForm.SimpleFileSharingDisable.checked = True
'Wait until the OK button has clicked
ready = false
Do Until ready
WScript.Sleep 100 ' supend, just to lower CPU load
Loop
oIE.Quit ' close Internet Explorer
Set oIE = Nothing ' reset object variable
' ### Event handler ###
Sub GetFormValue
' User has clicked the OK button, get values
skipexit = true
runDisableNICpowermanagement = oIE.Document.ValidForm.DisableNICpowermanagement.checked
runBSODrestartDisable = oIE.Document.ValidForm.BSODrestartDisable.checked
runDisplaySettings = oIE.Document.ValidForm.DisplaySettings.checked
runSysTrayNoHide = oIE.Document.ValidForm.SysTrayNoHide.checked
runWindowsUpdate = oIE.Document.ValidForm.WindowsUpdate.checked
runRDPenable = oIE.Document.ValidForm.RDPenable.checked
runUSBPowerManagementDisable = oIE.Document.ValidForm.USBPowerManagementDisable.checked
runServicesDisable = oIE.Document.ValidForm.ServicesDisable.checked
runSyncOfflineFilesDisable = oIE.Document.ValidForm.SyncOfflineFilesDisable.checked
runShowHiddenFiles = oIE.Document.ValidForm.ShowHiddenFiles.checked
runSetVirtualMem = oIE.Document.ValidForm.SetVirtualMem.checked
runPowerManagment = oIE.Document.ValidForm.PowerManagment.checked
runAddRegistryFavorites = oIE.Document.ValidForm.AddRegistryFavorites.checked
runW32TimeServer = oIE.Document.ValidForm.W32TimeServer.checked
runSimpleFileSharingDisable = oIE.Document.ValidForm.SimpleFileSharingDisable.checked
runActionCenterDisable = oIE.Document.ValidForm.ActionCenter.checked
答案 0 :(得分:0)
替换
Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
与
Set oIE = CreateObject("InternetExplorer.Application")
然后再试一次。此外,您正在从本地路径加载.php
文件。 PHP文件通常包含服务器端代码。这也可能导致问题。
作为旁注,您可以通过使用字符串操作来避免构建路径:
path = WScript.ScriptFullName
path = Left(path, InstrRev(path, "\"))
...
oIE.navigate path & "options.php"
使用相应的FileSystemObject
方法执行此操作更为可靠:
Set fso = CreateObject("Scripting.FileSystemObject")
path = fso.GetParentFolderName(WScript.ScriptFullName)
...
oIE.navigate fso.BuildPath(path, "options.php")