I have a simple script:
def get_log_dir():
    time_stmp = datetime.now().strftime('%m%d-%H%M%S')
    dir_ = Path('..') / f'log_{time_stmp}'
    dir_.mkdir(exist_ok=True)
    return dir_
if __name__ == '__main__':
    path = get_log_dir()
I build it to exe with pyinstaller --debug all -n minimal minimal.py.
Then I create a simple installer with NSIS:
  Name "myAppName"
  OutFile ".\myApp.exe"
  SilentInstall silent
  InstallDir "$LOCALAPPDATA\MyApp-0.1.1"
  
  RequestExecutionLevel admin
Section "Main Section" SecMain
  SetOutPath "$INSTDIR"
  
  File /r ".\myApp-app\*"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "myApp" '"$InstDir\minimal.exe"'
  ;Store installation folder
  WriteRegStr HKCU "Software\myApp" "" $INSTDIR
  
  Exec '"$INSTDIR\minimal.exe"'
SectionEnd
After running the installer i get my exe put to AppData folder and there is a registry entry in HKLM. It correctly starts at the end of installation, I can also start it manually at any time. However, if I restart my machine the script starts as it is supposed to but it fails with Access Denied error while trying to create folder. What could be causing this and/or how to debug this? Are there any Windows logs that could be investigated? Maybe pyInstaller logs?
Update:
Interestingly it works if instead of modifying registry I create a shortcut and put it to C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup. The question now is how does it differ and why? Is the walk around a clean solution or should be considered a hack?
 
    