全部源码
```python
#!D:\appsoft\python\python.exe
# -* - coding: UTF-8 -* -
import msvcrt,os,time
# ###############################################################
# ###########下面的是自定义配置区域##############################
# VeraCrypt.exe的位置
Cmdpath="E:\_tmp\VeraCrypt\VeraCrypt.exe"
# 加密文件的目录
Vospath="D:\_tmp\\"
# 分区和加密的文件对应关系
Local_V_DISK={"X":"testA","Y":"testB"}
# ############上面的是自定义配置区域##############################
# ################################################################
# # ##########下面的不要修改######################################
# def begin ######################################################
def getType():
return input("加载或卸载自定义分区(start,stop):")
def pwd_input():
chars = []
while True:
try:
newChar = msvcrt.getch().decode(encoding="utf-8")
except:
return input("你很可能不是在cmd命令行下运行,密码输入将不能隐藏:")
if newChar in '\r\n': # 如果是换行,则输入结束
break
elif newChar == '\b': # 如果是退格,则删除密码末尾一位并且删除一个星号
if chars:
del chars[-1]
msvcrt.putch('\b'.encode(encoding='utf-8')) # 光标回退一格
msvcrt.putch( ' '.encode(encoding='utf-8')) # 输出一个空格覆盖原来的星号
msvcrt.putch('\b'.encode(encoding='utf-8')) # 光标回退一格准备接受新的输入
else:
chars.append(newChar)
msvcrt.putch('*'.encode(encoding='utf-8')) # 显示为星号
return (''.join(chars) )
def startVeraCrypt(pwd):
global Local_V_DISK,Cmdpath,Vospath
for k in Local_V_DISK:
# print(k,'---',Local_V_DISK[k])
time.sleep(1)
os.system("cmd /c "+Cmdpath+" /v "+Vospath+Local_V_DISK[k]+" /a /l "+k+" /e /q /p "+pwd)
print('......加载成功!')
def stopVeraCrypt():
global Local_V_DISK,Cmdpath
for k in Local_V_DISK:
os.system("cmd /c "+Cmdpath+" /q /d "+k)
print('......卸载成功!!')
# def end ##############################################################
_t=getType()
_tpwd=''
print("您输入的类型:",_t,"\n")
if _t=='start':
print("请输入密码:")
_tpwd=pwd_input()
startVeraCrypt(_tpwd)
elif _t=='stop':
stopVeraCrypt()
else:
print('参数错误')
print("\r\n")
print("\r\n")
print("\r\n")
os.system('pause')
# print("\n密码是:{0}".format(pwd))
```