批量解析为VBScript [英] Batch parsing to VBscript
问题描述
我已经从链接 http://www.robvanderwoude.com/vbstech_ui_password.php
在现有VBSscript我已经加入了code,为Internet Explorer版本:
In the existing VBSscript I have added the code for the "Internet Explorer version" :
WS脚本 - 名为Password.vbs( 看到完整的剧本在上面的链接的)
strPw = GetPassword( "Please, type your password:" )
Sub Submit_OnClick
Const ForWriting = 2
Dim filesys, filetxt, FormContent
Set FormContent = document.getElementById("strPw")
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("c:\temp.txt", ForWriting, True)
filetxt.WriteLine(FormContent.value)
filetxt.Close
End Sub
批处理脚本
@echo off
SET VALIDPASSWORD=1234
wscript Password.vbs
findstr %VALIDPASSWORD% c:\temp.txt
if ERRORLEVEL 1 (
echo Incorrect password.
goto :EOF
) else (
echo Password correct.
)
echo Batch continues from here
pause
:EOF
exit /b
的文件TEMP.TXT应发送到c:与所述信息用户键入的输入框\\。批处理会读这个输入并比较了一组密码,并继续编码...
The file temp.TXT should be sent to the c:\ with the information the user typed on the inputbox. The batch would read this input and compare to a set password and continue the coding...
我怎样才能使这项工作?该TEMP.TXT不产生等等...
How can I make this work?? the temp.TXT is not generated an so forth ...
批量和VBS大师在那里,任何人的帮助解决这些问题真的欢迎!
BATCH and VBS gurus out there, any help to SOLVE these problems is really welcomed !
推荐答案
如果 C:\\ TEMP.TXT
没有被创建,那么第一个问题是不是与该批处理文件。
If C:\temp.txt
isn't being created, then the first problem is not with the batch file.
您链接到这篇文章的作者提到,这code不Win7上工作。我没有一个非Win7的机器方便的测试,但我怀疑,IE浏览器有写权限到C的根:驱动器(他的code没有做到这一点)。另一种可能性是, Password.vbs
是不是在你的批处理文件是相同的路径。你会得到一个错误消息,如果是这样的话,虽然。
The author of the article you linked to mentions that this code does not work on Win7. I don't have a non-Win7 machine handy to test on, but I doubt that IE has permission to write to the root of your C: drive (his code does not do this). Another possibility is that Password.vbs
is not in the same path where your batch file is. You would get an error message if that were the case, though.
由于这从命令行无论如何运行,为什么不尝试修改要简单得多WScript的版本,他张贴?假设这是由一个非管理员身份运行,并根据其操作系统这是上运行,你需要使用用户具有写权限(比如,例如,%TEMP目录%\\ TEMP.TXT
)。
Since this will be run from a command line anyway, why not try modifying the much simpler WScript version that he posted? Assuming this is being run by a non-administrator, and depending on which OS this is running on, you will need to use a directory that the user has permission to write to (say, for example, %TEMP%\temp.txt
).
话虽如此,也有你会碰到夫妇更多的问题。首先,你的的OpenTextFile
调用使用 ForAppending
模式(这是'8'在那里)。这意味着您的TEMP.TXT文件将包含所有用户曾经进入了答案。这也意味着,当你做你的 FINDSTR
,如果任何人有曾经放在正确的密码,校验会成功。这将是更好地使用 ForWriting
所以它每次新生成。请参见这个MSDN文章更多信息
Having said that, there are a couple more problems you'll run into. For one, your OpenTextFile
call uses the ForAppending
mode (that's the '8' in there). This means that your temp.txt file will hold all of the answers users have ever entered. This also means that when you do your findstr
, if anyone has ever put in the proper password, the check will succeed. It would be better to use ForWriting
so it is newly generated each time. See this MSDN article for more information.
此方法不处理密码的安全方式。一方面,用户可以只读取的批处理文件,其中要存储的有效密码,或者更简单的内容,他们可能只是看看有什么是应该,如果他们得到的密码正确的情况发生。但是如果你必须这样做,我会建议改变你的批处理文件是这样的:
This method is not a secure way to handle passwords. For one thing, the user could just read the contents of the batch file where you're storing the valid password, or even easier, they could just see what's supposed to happen if they do get the password correct. But if you must do it this way, I would recommend changing your batch file to something like this:
@echo off
REM This file assumes that you switch to a wscript version
REM and use the recommendations I gave.
SET VALIDPASSWORD=IAmTheRightPassword
wscript Password.vbs
findstr %VALIDPASSWORD% %TEMP%\temp.txt
if ERRORLEVEL 1 (
echo Incorrect password.
goto :EOF
) else (
echo Password correct.
)
REM Here's where you put whatever you were going to do if
REM the password was correctly entered.
这篇关于批量解析为VBScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!