Windows EXE: Use psutil for startup terminal detection
This commit is contained in:
parent
c818165db4
commit
2fd1422619
@ -8,34 +8,19 @@ import sys
|
|||||||
# copy the required files into repo root
|
# copy the required files into repo root
|
||||||
shutil.copy('docs/favicon.ico', '.')
|
shutil.copy('docs/favicon.ico', '.')
|
||||||
shutil.copy('deploy/windows/instaloader.spec', '.')
|
shutil.copy('deploy/windows/instaloader.spec', '.')
|
||||||
shutil.unpack_archive('deploy/windows/ps', '.', 'xztar')
|
|
||||||
|
|
||||||
code = """
|
code = """
|
||||||
|
import contextlib
|
||||||
import psutil
|
import psutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
def __main():
|
def __main():
|
||||||
grandparentpid = psutil.Process(os.getppid()).ppid()
|
with contextlib.suppress(AttributeError, psutil.Error):
|
||||||
grandparentpidsearchstring = ' ' + str(grandparentpid) + ' '
|
if psutil.Process().parent().parent().name() == "explorer.exe":
|
||||||
if hasattr(sys, "_MEIPASS"):
|
|
||||||
ps = os.path.join(sys._MEIPASS, 'tasklist.exe')
|
|
||||||
else:
|
|
||||||
ps = 'tasklist'
|
|
||||||
popen = subprocess.Popen(ps, stdout=subprocess.PIPE, universal_newlines=True)
|
|
||||||
for examine in iter(popen.stdout.readline, ""):
|
|
||||||
if grandparentpidsearchstring in examine:
|
|
||||||
pname = examine
|
|
||||||
break
|
|
||||||
popen.stdout.close()
|
|
||||||
return_code = popen.wait()
|
|
||||||
if return_code:
|
|
||||||
raise subprocess.CalledProcessError(return_code, ps)
|
|
||||||
if pname[0:12] == 'explorer.exe':
|
|
||||||
subprocess.Popen("cmd /K \\\"{0}\\\"".format(os.path.splitext(os.path.basename(sys.argv[0]))[0]))
|
subprocess.Popen("cmd /K \\\"{0}\\\"".format(os.path.splitext(os.path.basename(sys.argv[0]))[0]))
|
||||||
else:
|
return
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
__main()
|
__main()
|
||||||
"""
|
"""
|
||||||
|
@ -5,7 +5,7 @@ block_cipher = None
|
|||||||
|
|
||||||
a = Analysis(['__main__.py'],
|
a = Analysis(['__main__.py'],
|
||||||
binaries=[],
|
binaries=[],
|
||||||
datas=[('tasklist.exe', '.'), ('framedyn.dll', '.')],
|
datas=[],
|
||||||
hiddenimports=[],
|
hiddenimports=[],
|
||||||
hookspath=[],
|
hookspath=[],
|
||||||
runtime_hooks=[],
|
runtime_hooks=[],
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user