Page 1 of 1

[SOLVED] Using get_current_user()

Published: March 18, 2022 - 2:17 PM
by kcr
Good morning

I am trying to delete one or more files simultaneously from both the agent profile desktop and the public desktop

For the user: I use os.getlogin() to retrieve the UID
For the public part: path C:\Users\Public\Desktop\

The script I created works correctly locally, but as soon as I build my package and place it in my instance, it no longer works for the user part... The file is only deleted for the "Public" part

I tried with get_current_user(), same result

Problem writing the script? Permissions issue?

Here is the script:

Code: Select all

import glob
import os

def install():
    user = os.getlogin()
    path = "C:\\Users\\" + user + "\\Desktop\\nom_fichier"

    for filename1 in glob.glob(r'C:\Users\Public\Desktop\nom_fichier'):
        remove_file(filename1)

    for filename2 in glob.glob(path):
        remove_file(filename2)

Thank you for your feedback
Sincerely

Re: Using get_current_user()

Published: March 22, 2022 - 1:43 PM
by olaplanche
Hello,

The local script in PyScripter runs with the admin account -> no problem.
The script on the server runs with the LOCAL system account -> problem.

To make changes to user profiles, you need to use the `def session_setup()` function:
https://www.wapt.fr/fr/doc/wapt-create- ... sion-setup

Regards