auto input password in batchfile/cmd file

别说谁变了你拦得住时间么 提交于 2019-12-14 03:07:33

问题


I have this code to make and run an access point:

runas /User:Administrator cmd
netsh wlan set hostednetwork mode=allow ssid=private_wifi key=123456789
netsh wlan start hostednetwork
pause

My question is: Can I make auto input of password to only double click on file without other actions?


回答1:


You could use alternative data streams to provide the password.

1) create and save your batch file
2) use the ECHO command to 'place' your password into an ADS attached to your batch file
3) use redirection to read the password from the ADS (Alternative Data Stream) file

The password is safe as it cannot be 'seen' using conventional methods.

Here's how it works:

1) Include the following line in your code:

set /p password=<%~nx0:password

and save your batch file.

2) At the DOS command line, enter the following command:

echo YourPassWord>YourBatchFile.bat:password

NOTE 1: Please look at that line carefully. Notice the ADS after the ':' (colon) symbol. NOTE 2: Notice there are no spaces either side of the > (greater-than) symbol.

As an example, suppose you create the following simple batch file named GETPASS.BAT, and your password is LETMEIN

@echo off
set /p password=<%~nx0:password
echo %password%

Now save the batch file and enter the following command at the DOS prompt:

echo LETMEIN>GETPASS.BAT:password

NOTE: There is no spaces either side of the > (greater-than) symbol.

Now run your batch file - it should just display:

LETMEIN

On the subject of security, none of the following conventional methods will reveal your password:

COPY getpass.bat:password file.txt
TYPE getpass.bat:password
MORE getpass.bat:password
FIND /V "" getpass.bat:password

There are only a limited number of ways to view the contents of the ADS file. I leave it to you as a challenge to see if you can do it. So, that makes it pretty secure from a novice's point of view.

Furthemore, as far as novices are concerned (and some professionals) the following line can be quite misleading, especially in the absence of knowledge concerning ADS.

set /p password=<%~nx0:password

Finally, as you can see, there is no additional external file containing your password. The ADS is attached to your batch file. This means, if you move or rename your batch file, the ADS moves with it. Also, the %~nx0 part of the command ensures the ADS can be located should you rename the batch file.



来源:https://stackoverflow.com/questions/47518465/auto-input-password-in-batchfile-cmd-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!