0

我是 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
4

1 回答 1

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")
于 2013-06-29T08:35:14.710 回答