0

在第 59 行,字符 1 上出现错误......“接口未知”

目的是弹出一个简单的用户输入框并将结果捕获到一个变量中,然后到一个文本文件中,以便第 3 方应用程序可以读取它。我不太擅长编写 VBS,但我在 Windows 7 中完美地完成了这项工作。

我也想让这个(VBscript)在 Windows 8 中工作。但我不想学习如何用另一种语言编写脚本或编码。我不想用 Javascript 或 .NET 或其他方式重写整个内容。

请让我知道 Windows 8 与 Windows 7 sp1 的不同之处。谢谢。

'=======================[ ASK Password ]========================================'
Option Explicit
Dim strUserID, strPassword

AskPassword

Sub AskPassword()
Dim htmlPwdCode, objCodeFile, objFileSysObj, objBrowser, strButton
Const FOR_WRITING = 2

Set objFileSysObj = CreateObject("Scripting.FileSystemObject")

htmlPwdCode = "<SCRIPT LANGUAGE=" & Chr(34) & "VBScript" & Chr(34) & ">" & Chr(13) & _
"Sub RunScript" & Chr(13) & _
"    OKClicked.Value = " & Chr(34) & "OK"& Chr(34) & Chr(13) & _
"End Sub" & Chr(13) & _
"Sub CancelScript" & Chr(13) & _
"    OKClicked.Value = " & Chr(34) & "Cancelled" & Chr(34) & Chr(13) & _
"End Sub" & Chr(13) & _
"Sub Default_Buttons" & Chr(13) & _
"   If Window.Event.KeyCode = 13 Then" & Chr(13) & _
"       btnOK.Click" & Chr(13) & _
"   End If" & Chr(13) & _
"End Sub" & Chr(13) & _
"</SCRIPT>" & Chr(13) & _
"<BODY onkeypress='vbs:Default_Buttons'><center><font size=" & Chr(34) & "2" & Chr(34) & " face=" & Chr(34) & "Arial" & Chr(34) & ">" & Chr(13) & _
"User name:&nbsp;&nbsp;&nbsp;" & Chr(13) & _
"<input type=" & Chr(34) & "text" & Chr(34) & " name=" & Chr(34) & "UserName" & Chr(34) & " size=" & Chr(34) & "30" & Chr(34) & "><br>" & Chr(13) & _
"Password :&nbsp;&nbsp;&nbsp; </font><font face=" & Chr(34) & "Arial" & Chr(34) & ">" & Chr(13) & _
"<input type=" & Chr(34) & "password" & Chr(34) & " name=" & Chr(34) & "UserPassword" & Chr(34) & _
" size=" & Chr(34) & "30" & Chr(34) & "></font></p>" & Chr(13) & _
"<input type=" & Chr(34) & "hidden" & Chr(34) & " name=" & Chr(34) & "OKClicked" & Chr(34) & " size = " & Chr(34) & "20" & Chr(34) & ">" & Chr(13) & _
"<input id=" & Chr(34) & "btnOK" & Chr(34) & " class=" & Chr(34) & "button" & Chr(34) & _
" type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & " OK " & Chr(34) & _
" name=" & Chr(34) & "ok_button" & Chr(34) & " onClick=" & Chr(34) & "RunScript" & Chr(34) & ">" & Chr(13) & _
"<input id=" & Chr(34) & "btnCancel" & Chr(34) & " class=" & Chr(34) & "button" & Chr(34) & _
" type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & "Cancel" & Chr(34) & _
" name=" & Chr(34) & "cancel_button" & Chr(34) & " onClick=" & Chr(34) & "CancelScript" & Chr(34) & "></center></BODY>"

Set objCodeFile = objFileSysObj.CreateTextFile("LoginPrompt.html", True)
objCodeFile.Write htmlPwdCode
objCodeFile.Close
Set objCodeFile = Nothing

Set objBrowser = CreateObject("InternetExplorer.Application")

With objBrowser
    .Height = 200
    .Width = 400
    .Top = 200
    .Left = 300
    .StatusBar = True
    .Toolbar = False
    .Resizable = False
    .Navigate CreateObject("Scripting.FileSystemObject").GetParentFolderName(Wscript.ScriptFullName) & "\LoginPrompt.html"
    .Visible = True
End With

Do Until objBrowser.ReadyState = 4
'wait till page loads'
Loop

Do While objBrowser.Document.Body.All.OKClicked.Value = ""
    Wscript.Sleep 50                 
Loop 

strUserID = objBrowser.Document.Body.All.UserName.Value
strPassword = objBrowser.Document.Body.All.UserPassword.Value
strButton = objBrowser.Document.Body.All.OKClicked.Value


'''''''''''''''''''''''
Dim objFSO, strFile, objFile

Const ForWriting = 2
Const OpenAsASCII = 0
Const CreateIfNotExist = True

' Specify output file.
strFile = "C:\TEMP\MEX\UN.txt"

' Open the file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFile, _
ForWriting, CreateIfNotExist, OpenAsASCII)

' write to file.
objFile.WriteLine strUserID

' Clean up.
objFile.Close
'''''''''''''''''''''''''''

Dim objFSO2, strFile2, objFile2

Const ForWriting2 = 2
Const OpenAsASCII2 = 0
Const CreateIfNotExist2 = True

' Specify output file.
strFile2 = "C:\TEMP\MEX\PW.txt"

' Open the file.
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set objFile2 = objFSO2.OpenTextFile(strFile2, _
ForWriting2, CreateIfNotExist2, OpenAsASCII2)

' write to file.
objFile2.WriteLine strPassword

' Clean up.
objFile2.Close
'''''''''''''''''''''''''''


objBrowser.Quit

If strButton = "Cancelled" Then
    MsgBox "Operation cancelled, script will now exit!"
    Wscript.Quit
Else
    'Credentials accepted for further processing
End If
objFileSysObj.DeleteFile "LoginPrompt.html", True

Set objBrowser = Nothing
Set objFileSysObj = Nothing
End Sub




'=======================[ GOT Password ]========================================'
4

1 回答 1

1

第 59 行: Do Until objBrowser.ReadyState = 4

根据 MSDN:ReadyState Property Example (VBScript),问题在于“ReadyState”功能已被删除。

于 2013-01-09T13:24:19.630 回答