We'd like to remind Forumites to please avoid political debate on the Forum... Read More »
We're aware that some users are experiencing technical issues which the team are working to resolve. See the Community Noticeboard for more info. Thank you for your patience.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!
Command for BAT file
Options

lindabea
Posts: 1,530 Forumite


in Techie Stuff
I have a windows batch file which allows me to keyin a P/W using the echo and set commands. What I would prefer is for the BAT file to read the variable from a TXT file instead of prompting for the variable.
If this is possible to do, can someone please tell me commands I need.
Many thanks
If this is possible to do, can someone please tell me commands I need.
Many thanks
Before doing something... do nothing
0
Comments
-
I'm no DOS expert but I found something:
Set /p TEST=<test.txt
echo %TEST%Changing the world, one sarcastic comment at a time.0 -
25 years ago this would have been a doddle. Today it seems hard, but using a macro language or a keystroke recorder could be another way to go
https://www.techsupportalert.com/best-free-hotkey-macro-recorder-utility.htm.
Would have been handy to know what the exact line looked like, and you are logging onto a remote system, or just running a command
The problem with this is that anybody can come along and easily find the user name and password, so why even have a password?0 -
25 years ago this would have been a doddle.
I am assuming that you have a text file (called here lindabea.txt, but obviously you can call it what you like, if you change the BATch file to match) which contains a single word on the only line of the file, and the single word does not contain any of the 'poison' BATch characters like ^ & " and so on...
The BATch file could be something like...for /f %%a in ("lindabea.txt") do set pw=%%a echo Linda's password is %pw% (so she can see what it is!) pause
I've left out some of the frills like "tokens=1", which aren't necessary in this simplistic instance.0 -
Batch files were (and still are) quite powerful. If you learn how to use them properly, they can do all kinds of things
Here's a bunch of stuff you may or may not know that batch files can do:
https://www.makeuseof.com/tag/use-windows-batch-file-commands-automate-repetitive-tasks/
Useful introduction though to Windows Script Hosting and Powershell which is the same principle but a bit more powerful.0 -
You have passwords in plain text files?0
-
Thank you John Gray and Stator for your help.
But I don't think my logic is correct!!! I'm trying to avoid having the P/W hardcoded inside the BAT prog, but even if I read it from an external txt file as a variable, I still need to check it inside the prog for validity. That's where the logic falls down.
So the question is, is there a way I can check for a valid P/W without having the P/W inside the bat file
One solution is to take the bat file off the hard disk after it's been run, but I'm trying to avoid this inconvenience of having to load it back when I need to run it.Before doing something... do nothing0 -
You have stated the basic problem.
If someone has access to the BATch file all they have to do is to put in
echo Password is %password% & pause
after it has been set, and All is Revealed when the BATch file is run!
Short of finding a BATch file compiler which works successfully (good luck!), I haven't found any way of overcoming the password display problem...0 -
You have stated the basic problem.
If someone has access to the BATch file all they have to do is to put in
echo Password is %password% & pause
after it has been set, and All is Revealed when the BATch file is run!
Short of finding a BATch file compiler which works successfully (good luck!), I haven't found any way of overcoming the password display problem...
Or a person can put in 'type batchfile_name.bat" and 'type password_name.txt" and the whole contents of both files are displayed on the screen. They a can even open both files in a text editor or word.
Possibly more secure to run a keystroke/mouse macro recorder that encrypts. Even if it does not encrypt, the account and passsword are often less obvious that batch files. Also you can assign the login to a button0 -
If I understand correctly, you want the user to enter a password, and then you want to validate that password, but you don't want to hard-code the correct password into the .bat file.
One approach is to perform a one-way transformation on the value entered, and then compare that against the hard-coded one-way transform. A sha encoding, or that sort of thing. That's the way unix traditionally checked login passwords : you enter the password, then the system performs a transform, and then compares that against the entry stored in a world-readable file. (These days, the transformed version is stored in an non-readable file to avoid brute-force attacks.)
I suspect windows bat doesn't have a utility to perform a transform. powershell might. I don't know any powershell - does
https://www.example-code.com/powershell/crypt_hash_algorithms.asp
help ?
Note: are you really doing the password check in the bat file ? What stops someone just copying the bat file, editing out the password check entirely, and running their copy instead ?0
This discussion has been closed.
Confirm your email address to Create Threads and Reply

Categories
- All Categories
- 350.8K Banking & Borrowing
- 253K Reduce Debt & Boost Income
- 453.4K Spending & Discounts
- 243.7K Work, Benefits & Business
- 598.5K Mortgages, Homes & Bills
- 176.8K Life & Family
- 256.9K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.1K Discuss & Feedback
- 37.6K Read-Only Boards