Skip to content

Python Scripts are executed in %windir%\System32 instead of the current working directory #14419

Closed
@A-Loot

Description

@A-Loot

Description

When executing a python script by double clicking it, it is executed in %windir%\System32 instead of the current directory. I checked and the scripts aren't run as admin so that can't be the problem.

A workaround would be to open the current folder in cmd and excecute the script with "python script.py" or to directly type "python script.py" in the address bar

Steps To Reproduce

  1. execute the following python script by double clicking it. it prints out the current working directory and if the script is executed with admin privileges:
import os
import ctypes

def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False

# Print the current working directory
print("Current working directory: ", os.getcwd())

# Check for admin permissions
if is_admin():
    print("The script is run with administrator permissions.")
else:
    print("The script is not run with administrator permissions.")

# Prevent the script from automatically exiting
input("Press Enter to exit...")
  1. in Windows Explorer I get the following output:
Current working directory:  C:\test
The script is not run with administrator permissions.
  1. in Files I get the following output:
Current working directory:  C:\WINDOWS\system32
The script is not run with administrator permissions.

Requirements

  • Fix Python scripts not being executed in the current working directory

Files Version

3.1.1.0

Windows Version

10.0.23612.1000

Log File

debug.log

nothing there

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions