Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
A-Loot opened this issue Jan 10, 2024 · 7 comments
Labels
needs - additional info Needs more information from the reporter

Comments

@A-Loot
Copy link
Contributor

A-Loot commented Jan 10, 2024

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

@A-Loot A-Loot added the bug label Jan 10, 2024
@A-Loot
Copy link
Contributor Author

A-Loot commented Jan 10, 2024

@yaira2
Copy link
Member

yaira2 commented Jan 10, 2024

I'm pretty sure this is the same as #12950

@A-Loot
Copy link
Contributor Author

A-Loot commented Jan 11, 2024

Maybe, #3713 also seems to be the same Issue, but unlike .py and .jar I can't reproduce it on my machine (I couldn't find any commit that specifically addressed the Issue so maybe it was caused by something different).

@el-ev
Copy link
Contributor

el-ev commented Jan 11, 2024

In the OpenPath() method of Files.App\Helpers\Navigation\NavigationHelpers.cs, the working directory for the file executed through Win32Helpers.InvokeWin32ComponentAsync() is normal, but when executed through Launcher.LaunchFileAsync(), it's the case of this issue. I'm not sure if it is intentional that there are two different execution methods.

You can verify this by setting the file as hidden, as the latter method is the default, and OpenPath() executes all hidden items in the former method.

Win32Helpers.InvokeWin32ComponentAsync() Launcher.LaunchFileAsync()
image image

@Josh65-2201
Copy link
Member

Should this be merge with #12950 ?

@Josh65-2201 Josh65-2201 added the needs - additional info Needs more information from the reporter label Jan 27, 2024
@yaira2
Copy link
Member

yaira2 commented Jan 28, 2024

Should this be merge with #12950 ?

@hishitetsu

@hishitetsu
Copy link
Member

Should this be merge with #12950 ?

I believe so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs - additional info Needs more information from the reporter
Projects
None yet
Development

No branches or pull requests

5 participants