0

So, what I would like to accomplish is to make a batch file with a login (username and password) where one would not have to go into the script (where all the commands are) to change the passwords and usernames.

Currently I can make a accounts which store the login information via %info%. However this is not permanent and this info will be lost once i close the batch file, making it so one with my knowledge would either have to manually change the script ( I would like to eliminate this by compressing the batch to an exe file for download later) or to create an account every time the batch file is reopened.

I assume there is some sort of command that allows you to edit the batch file script form the running batch file. If there is so I would be grateful if anyone could show me the command and how to use it (I assume if i change where the password will go to something distinguishable i.e. ZXC001 and so on and such a command exists I can replace this with the password)

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Welcome to StackOverflow. Please note that you can actually format your question using paragraph breaks to make it readable. You can also preview it real-time (as you're typing it) immediately below the multi-line text area you're entering it into, so you know how it will look before posting. It's much better if you do so, so you can make it as readable as possible in order to improve your chances of getting an answer. It might be good if you spent a few minutes reviewing the [FAQ](http://stackoverflow.com/faq) for some additional info. :) – Ken White Mar 22 '12 at 02:43

1 Answers1

1

The easiest thing to do is to save the needed info in a separate batch file using:

echo set info=%info% >loginInfo.bat

and when you want to retrieve the info simply use (from within the main batch file):

call loginInfo

The above code is at risk if %info% has special characters, but there are multiple simple improvements that could be made to get around that problem, all of them using delayed expansion in some way.

There are variations to the theme. For example, you could store just the %info% value only in a text file, and then read the value back in using FOR /F.

If you really want to dynamically modify the main batch script, then have a look at Changing a batch file when its running, especially the solution at the bottom of that answer.

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390