0

我有下面的 vbscript,它需要发送一个 GET 请求,然后注销当前用户。这个想法是用这个脚本替换默认的“注销”开始菜单项。

当我使用 cscript 运行它时,它会在第 9 行引发错误,

HTTPGet = IE.document.documentelement.outerhtml

我不明白出了什么问题。也许我应该在注销用户之前等待收到响应,但是由于上面的行似乎不起作用,我立即注销。

TOKEN = "xxxxx"
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "https://something.com/?action=create&token=" & TOKEN
Do While IE.Busy
   WScript.Sleep 200  ' see the above notice of change
   Exit Do                  ' prevents script host from going crazy waiting for IE
loop
HTTPGet = IE.document.documentelement.outerhtml
IE.quit
Set IE = Nothing

'WScript.Echo HTTPGet   'good for debugging. shows what you got back.

Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\WINDOWS\system32\shutdown.exe -l"

如果重要的话,这仅适用于带有 IE 8 的 Windows XP。

4

1 回答 1

1

试试这个代码:

Set IE = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "https://host/?a=" & TOKEN
i = 1
Do While (IE.readyState <> 4)
   WScript.Sleep 1000  ' see the above notice of change
   i = i + 1
   If (i > 10) Then
      Exit Do
   End If
loop
HTTPGet = IE.document.documentElement.outerHTML
IE.Quit()
Set IE = Nothing
于 2013-03-25T12:13:22.227 回答