Skip to content

Commit

Permalink
use subprocess.run instead of os.system to avoid cmd window on VNC an…
Browse files Browse the repository at this point in the history
…d RDP, closes #44
  • Loading branch information
schorschii committed Aug 28, 2024
1 parent d7e4552 commit 85ad168
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions client-extension/oco-client-extension-windows.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import unquote
import sys
import os
import subprocess
import ctypes

def main():
Expand All @@ -14,7 +15,7 @@ def main():

if(arg.startswith('ping://')):
try:
os.system('start cmd.exe @cmd /c "ping /t '+shellQuote(getProtocolPayload(arg))+' & pause"')
subprocess.run('cmd.exe /c ping /t '+shellQuote(getProtocolPayload(arg))+' & pause')
sys.exit(0)
except Exception as e:
msgBox(None, 'Unable to start CMD with ping command. Strange.\n\n'+str(e), APP_TITLE, 48)
Expand All @@ -23,7 +24,7 @@ def main():
if(arg.startswith('nmap://')):
try:
os.chdir('C:\\Program Files (x86)\\Nmap')
os.system('start cmd.exe @cmd /c ".\\nmap.exe -Pn '+shellQuote(getProtocolPayload(arg))+' & pause"')
subprocess.run('cmd.exe /c nmap.exe -Pn '+shellQuote(getProtocolPayload(arg))+' & pause')
sys.exit(0)
except Exception as e:
msgBox(None, 'Unable to start Nmap. Please check if it is installed correctly.\n\n'+str(e), APP_TITLE, 48)
Expand All @@ -32,23 +33,23 @@ def main():
if(arg.startswith('vnc://')):
try:
os.chdir('C:\\Program Files\\TightVNC')
os.system('.\\tvnviewer.exe '+shellQuote(getProtocolPayload(arg)))
subprocess.run('tvnviewer.exe '+shellQuote(getProtocolPayload(arg)))
sys.exit(0)
except Exception as e:
msgBox(None, 'Unable to start TightVNC Viewer. Please check if it is installed correctly.\n\n'+str(e), APP_TITLE, 48)
sys.exit(2)

if(arg.startswith('rdp://')):
try:
os.system('mstsc.exe /v:'+shellQuote(getProtocolPayload(arg)))
subprocess.run('mstsc.exe /v:'+shellQuote(getProtocolPayload(arg)))
sys.exit(0)
except Exception as e:
msgBox(None, 'Unable to start Windows RDP Viewer. Please check if mstsc.exe exists in PATH.\n\n'+str(e), APP_TITLE, 48)
sys.exit(2)

if(arg.startswith('ssh://')):
try:
returnCode = os.system('start cmd.exe @cmd /c "ssh '+shellQuote(getProtocolPayload(arg))+' & pause"')
subprocess.run('cmd.exe /c ssh '+shellQuote(getProtocolPayload(arg))+' & pause')
sys.exit(0)
except Exception as e:
msgBox(None, 'Unable to start SSH session. Please check if ssh.exe is in PATH.\n\n'+str(e), APP_TITLE, 48)
Expand Down

0 comments on commit 85ad168

Please sign in to comment.