Page 1 of 1

[SOLVED] Copy desktop shortcuts for logged-in users

Published: January 15, 2025 - 3:23 PM
by vgrafte
Good morning,

I created a package to paste links onto the desktop; here is the script:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

import os
import glob

def session_setup():
  username=os.getlogin()
def install():
  chemin = (r'C:\Users\{}\Desktop'.format(username))
    filecopyto(lnk, chemin)
I can't understand why it's not working.
The console displays this error message:

Code: Select all

Traceback (most recent call last):
  File "C:\Program Files (x86)\wapt\common.py", line 4235, in install_wapt
    exitstatus = setup.install()
  File "C:\WINDOWS\TEMP\wapt257aezdq\setup.py", line 13, in install
  File "shutil.py", line 435, in copy2
  File "shutil.py", line 264, in copyfile
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Système\\Desktop'

2 : No such file or directory
I can see that the username returns System and not the logged-in user, but the command in Python does return the correct user.

Thank you for your help.

Re: Copying desktop shortcuts for logged-in user

Published: January 15, 2025 - 4:30 PM
by fschelfaut
Good morning,

If you want to execute code within the user's session, for example, adding a shortcut to the user's desktop
So you need to execute all your code within the function session-setup

Note that the code executed in the function install is as a system user

To achieve what you want, you have two options:

Code: Select all

def session_setup():
    # Create a desktop shortcut link for current user
    create_user_desktop_shortcut(label='', target='', arguments='')
    
def install():
    # Create a desktop shortcut link for all users
    create_desktop_shortcut(label='', target='', arguments='')
Flavien,