在batchfile/cmd文件中自动输入密码 [英] auto input password in batchfile/cmd file

查看:320
本文介绍了在batchfile/cmd文件中自动输入密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以创建并运行一个接入点:

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?

推荐答案

您可以使用备用数据流来提供密码.

You could use alternative data streams to provide the password.

1)创建并保存您的批处理文件
2)使用ECHO命令将密码放入"批处理文件中附带的ADS中
3)使用重定向从ADS(备用数据流)文件中读取密码

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.

这是它的工作方式:

1)在代码中包含以下行:

1) Include the following line in your code:

set /p password=<%~nx0:password

并保存您的批处理文件.

and save your batch file.

2)在DOS命令行上,输入以下命令:

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

echo YourPassWord>YourBatchFile.bat:password

注意1:请仔细查看该行.注意:"(冒号)符号后的ADS. 注意2:请注意,>(大于)符号的两边都没有空格.

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.

作为示例,假设您创建了一个名为GETPASS.BAT的简单批处理文件,密码为LETMEIN

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%

现在保存批处理文件,并在DOS提示符下输入以下命令:

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

只有少数几种方法可以查看ADS文件的内容.我将它留给您作为挑战,看看您是否可以做到.因此,从新手的角度来看,这非常安全.

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.

此外,就新手(和某些专业人士)而言,以下内容可能会引起误解,尤其是在缺乏有关ADS的知识的情况下.

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

最后,如您所见,没有包含您的密码的其他外部文件. ADS已附加到您的批处理文件中.这意味着,如果您移动或重命名批处理文件,则ADS将随之移动.另外,该命令的%~nx0部分可确保在重命名批处理文件时可以找到ADS.

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.

这篇关于在batchfile/cmd文件中自动输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆