borna
borna

Reputation: 924

Password Encryption inside a batch


I have a windows bat which is called by the Windows task scheduler every 5 mins. In there I am connecting to a network drive, something like this
net use G: \hostname\shared mypassword /user:myuserid /persistent:yes
it works with no issue, but I don't want to put the password in the bat file as a plain txt. is there anyway to protect my password or put a encrypted password or store it somewhere safe in there to make it secure?

Upvotes: 2

Views: 9193

Answers (2)

Pika
Pika

Reputation: 517

You could use a Md5 generator (or hash code generator written by your own) to generate a password from any file in your computer. Whenever you run it, the batch file will generate the password from that specific file by the generator.

Your password is no longer in plain text, but hidden in generator and the corresponding file.

hope it helps.

Upvotes: 0

Remus Rusanu
Remus Rusanu

Reputation: 294187

Use an environment variable.

 Net use .... %password%

Then define the variable in the context which the batch runs. This is better than script source because the script is mobile, it can be copied from this machine to that, it can end up in the source control and so on. It is not more secure against a local host attack, i.e. If one user could see the password in the script it is also likely to find it in the environment.

There are more advanced solutions if you are willing to switch to PowerShell. https://social.technet.microsoft.com/wiki/contents/articles/4546.working-with-passwords-secure-strings-and-credentials-in-windows-powershell.aspx

Upvotes: 1

Related Questions