Add stdin fallback for diskpart when script file is virtualized/blocked

- Detect when script file disappears after successful creation
- Fall back to piping diskpart commands via stdin instead of script file
- Bypasses Windows security features that may block/virtualize temp files
- More reliable approach when file system access is restricted
- Addresses issue where file appears created but doesn't actually exist
- Resolves diskpart script access problems on secured Windows systems
parent 4cfe722d
...@@ -360,14 +360,26 @@ exit ...@@ -360,14 +360,26 @@ exit
# Final verification before using the script # Final verification before using the script
if not os.path.exists(script_path): if not os.path.exists(script_path):
raise Exception(f"Diskpart script was created but is no longer accessible at {script_path}") self.status.emit(f"WARNING: Script file vanished after creation - {script_path}")
# Fall back to stdin approach if script file disappears
script_path = None
try: try:
# Run diskpart to format the USB drive # Run diskpart to format the USB drive
self.status.emit("Formatting USB drive...") self.status.emit("Formatting USB drive...")
if script_path and os.path.exists(script_path):
# Use script file approach
self.status.emit(f"Using script file: {script_path}")
result = subprocess.run([ result = subprocess.run([
'diskpart', '/s', script_path 'diskpart', '/s', script_path
], capture_output=True, text=True, timeout=60) ], capture_output=True, text=True, timeout=60)
else:
# Fall back to stdin approach (more reliable)
self.status.emit("Using stdin approach (script file unavailable)")
result = subprocess.run([
'diskpart'
], input=diskpart_script, capture_output=True, text=True, timeout=60)
# Clean up diskpart script # Clean up diskpart script
try: try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment