Python版本

import os
import sys
import subprocess
import ctypes

# 设置变量
original_drive = "F:"   # 目标分区
generated_drive = "Z:"   # 生成分区
password = "126598"   # 密码

# 设置路径
recycle_path = os.path.join(original_drive, "RECYCLED")
target_path = os.path.join(recycle_path, r"UDrives.{25336920-03F9-11CF-8FD0-00AA00686F13}")

def disable_access(path):
    subprocess.call(f'echo y|cacls {path} /d everyone', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    
def set_hidden_and_system(path):
    subprocess.call(f'attrib +H +S {path}', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

def set_full_control(path):
    subprocess.call(f'echo y|cacls {path} /c /g everyone:f', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

def prompt_password():
    # PowerShell to securely read password
    ps_command = "$pword = Read-Host 'Enter Password' -AsSecureString; " \
                 "$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); " \
                 "[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"
    result = subprocess.run(
        ["powershell", "-Command", ps_command],
        capture_output=True,
        text=True
    )
    return result.stdout.strip()

def subst_drive(drive, target):
    subprocess.call(f'SUBST {drive} {target}', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

def subst_remove(drive):
    subprocess.call(f'SUBST /D {drive}', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

def main():
    if not os.path.exists(target_path):
        os.makedirs(target_path)

    if os.path.exists(f'{generated_drive}\\'):
        disable_access(recycle_path)
        subst_remove(generated_drive)
        sys.exit()

    if os.path.exists(target_path):
        entered_password = prompt_password()
        if entered_password == password:
            set_full_control(recycle_path)
            subst_drive(generated_drive, target_path)
            subprocess.call(['explorer', f'{generated_drive}\\'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
        else:
            sys.exit()
    else:
        os.makedirs(target_path, exist_ok=True)
        set_hidden_and_system(recycle_path)
        disable_access(recycle_path)
        main()

if __name__ == "__main__":
    main()
@echo on&@endlocal&@cls
@ECHO OFF
title 传送门   By:Kenvie
mode con cols=55 lines=20
IF EXIST X:\NUL GOTO DELETE
IF EXIST E:\RECYCLED GOTO PS
MD E:\RECYCLED\UDrives.{25336920-03F9-11CF-8FD0-00AA00686F13}>NUL
ATTRIB E:\RECYCLED +H +S >NUL
ECHO y|cacls E:\RECYCLED /d everyone >nul
:PS
set ps="密码"
set "psCommand=powershell -Command "$pword = read-host 'Enter Password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set ps=%%p
if /i "%ps%"=="密码" (goto START) else goto END
:START
echo y|cacls E:\RECYCLED  /c /g everyone:f >nul
SUBST X: E:\RECYCLED\UDrives.{25336920-03F9-11CF-8FD0-00AA00686F13} >NUL
START X:\
GOTO END
:delete
ECHO y|cacls E:\RECYCLED /d everyone >nul
SUBST /D X:
:END
EXIT
最后修改:2024 年 07 月 18 日
如果觉得我的文章对你有用,请随意赞赏