Vbscript 需要VBS脚本的帮助。获取对象所需的错误
我是VBS脚本的新手,我正在尝试掌握我们目前在工作中使用的一个脚本,用于为工作站设置特定设置 我已根据更新的需要修改了脚本,但在尝试运行时出错 错误:需要对象:“document.getElementById(..)” 任何帮助都将不胜感激Vbscript 需要VBS脚本的帮助。获取对象所需的错误,vbscript,wsh,Vbscript,Wsh,我是VBS脚本的新手,我正在尝试掌握我们目前在工作中使用的一个脚本,用于为工作站设置特定设置 我已根据更新的需要修改了脚本,但在尝试运行时出错 错误:需要对象:“document.getElementById(..)” 任何帮助都将不胜感激 '******************IE Interface Starts****************************************** Public skipexit Dim oIE ' declare variables
'******************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
替换
Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
与
然后再试一次。另外,您正在从本地路径加载.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")
你能把你的代码删减到只显示你的问题吗?完成了。很抱歉。基于此,我认为文档没有getElementById方法。你必须通过在@rene上循环来“构建”它。这个对象肯定有一个
getElementById()
方法。我做了你建议的更改,但仍然得到相同的错误。主要问题似乎与Set oBut=oIE.document.getElementById(“Run”)有关。请检查页面的源代码。它是否包含属性为id=“Run”
的元素?哇,我完全忽略了这一点。我使用的是name=“Run”。我将其更改为id=“Run”。这解决了这个问题。现在我遇到了一个错误:对象不支持这个属性或方法:“document.ValidForm”它的意思是它所说的。对象没有名为ValidForm
的属性或方法。如果要引用具有该ID的元素,必须使用document.all.ValidForm
或document.getElementById(“ValidForm”)
。
Set fso = CreateObject("Scripting.FileSystemObject")
path = fso.GetParentFolderName(WScript.ScriptFullName)
...
oIE.navigate fso.BuildPath(path, "options.php")