After restart the exe of a python script is not able to run anymore - "Windows cannot access the specified [..] file [...]"

Viewed 27

I've been trying to improve the installer for my project. At first i had the project in the same folder as the installer, the installer would then move it to the Program Files directory. That all worked like a breeze.

But I thought that it would be better to have the project and it's directory bundled in the installer itself. As the installer was created with the -onefile argument, the contents would be unzipped in the TEMP files folder. Then the installer would move the Exe to the "Program Files" directory. At first that also worked.

But after I restarted the computer, the exe could not be opened at all with the error message: Windows cannot access the specified device, path, or file. You may not have the appropriate permission to access the item.

Here is a snippet of the code from the installer.

from os import environ, system, path
from shutil import move
import sys

def exe_path():
    temppath = sys._MEIPASS
    return path.join(temppath, 'Project')

def install():
    move(exe_path(), path.join(environ["PROGRAMFILES"], 'Project'))

install()

And this is the Pyinstaller command i use

pyinstaller --noconfirm --onefile --console --uac-admin --add-data "C:/Users/PC/Documents/output/Project;Project" 

Although I'm really no pro when it comes to the windows permission system i have some theories why this happens:

Theory 1

Because the project is bundled within the installer, when unpacked and moved, the installer.exe get's the rights the user should have.

Theory 2

Because the project is moved from the TEMP folder it has less rights because it's not intended to br run or something like that...

0 Answers
Related