ich möchte eine Netzwerkverbindung (Laufwerk S) trennen, das klappt ohne Probleme mit
Code: Alles auswählen
def button_A32():
myprocess = subprocess.Popen('net use S: /delete')
Code: Alles auswählen
def button_A32():
myprocess = subprocess.Popen('net use S: /delete')
Code: Alles auswählen
subprocess.run(["net", "use", "S:", "/delete"], check=True)
Code: Alles auswählen
import subprocess
def umount_share(drive_letter: str) -> bool:
"""
Umount drive_letter and return True if success.
The windows of invoked net command is hidden.
"""
cmd = ["net", "use", f"{drive_letter.upper()}:", "/delete"]
startup_info = subprocess.STARTUPINFO()
startup_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, startupinfo=startup_info)
return proc.returncode == 0
print(umount_share("x"))