Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If <code>C:\temp.txt</code> isn't being created, then the first problem is not with the batch file.</p> <p>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 <code>Password.vbs</code> is not in the same path where your batch file is. You would get an error message if that were the case, though.</p> <p>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, <code>%TEMP%\temp.txt</code>).</p> <p>Having said that, there are a couple more problems you'll run into. For one, your <code>OpenTextFile</code> call uses the <code>ForAppending</code> 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 <code>findstr</code>, if anyone has <strong>ever</strong> put in the proper password, the check will succeed. It would be better to use <code>ForWriting</code> so it is newly generated each time. See <a href="http://msdn.microsoft.com/en-us/library/czxefwt8%28v=vs.84%29.aspx" rel="nofollow">this MSDN article</a> for more information.</p> <p>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:</p> <pre><code>@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. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload