Saving Files to Desktop That is Synced Via OneDrive

tmyers

Well-known member
Local time
Yesterday, 20:36
Joined
Sep 8, 2020
Messages
1,090
I am trying to save files to users desktop, or even their Documents folder but several people have OneDrive enabled and are syncing either one or both of them which changes their path completely.

Any code I run, whether it is Python or VBA, while it doesn't seem to explicitly fail, doesn't work either. The code runs and a file is supposedly created but never actually appears and becomes "lost". From what I have read it is likely due to OneDrive catching the file during its creation and trying to do something with it but fails.

Would any happen to know a way to bypass OneDrive, or work with it in the event it is enabled? I remember reading somewhere that I likely have to work with its API.

For the record, this is what I was trying to use to check for its use:

Python:
        is_onedrive_in_use = False

        try:
            # Open OneDrive registry key
            with winreg.OpenKeyEx(
                winreg.HKEY_LOCAL_MACHINE,
                r'Software\Microsoft\OneDrive\Settings',
                0,
                winreg.KEY_READ
            ) as key:
                # Get value of the UserFolder key
                user_folder_value = winreg.QueryValueEx(key, 'UserFolder')[0]

                # Check if it being redirected to OneDrive
                if user_folder_value != os.path.expanduser('~\\Desktop'):
                    is_onedrive_in_use = True
        except Exception as e:
            print(e)

        target_desktop_path = os.path.expanduser('~\\Desktop')
        if is_onedrive_in_use:
            target_desktop_path = user_folder_value

        return target_desktop_path
 
Could you create the files in the %TEMP% folder, then copy them?
 
Could you create the files in the %TEMP% folder, then copy them?
I have tried creating files elsewhere then tried pushing them to the desktop but that also results in the file becoming lost as OneDrive tries to redirect it. Admittedly I have not tried using the temp folder specifically.
 
Hi. I just tried to create a file on my desktop using VBA, and it worked, as long as I use the OneDrive address. Is your question how to determine the name of the OneDrive folder?
 
The overarching question I guess would be how to detect if it is in use so I can properly direct the file to the right spot. As currently trying to force it to the desktop when it is in use results in the file becoming lost.
 
The overarching question I guess would be how to detect if it is in use so I can properly direct the file to the right spot. As currently trying to force it to the desktop when it is in use results in the file becoming lost.
I'm not sure I understand what you mean by "in use." Are you saying some users have One Drive and other don't? Is this not in a business environment?
 
I'm not sure I understand what you mean by "in use." Are you saying some users have One Drive and other don't? Is this not in a business environment?
It is but it is up to each person whether they choose to enable OneDrive or not. Each person has a subscription and up to 1tb of storage but not everyone has it turned on and not everyone syncs the same folders (some only do documents rather than desktop).

As a business it isn't something we push as much as it just comes part of 365 and people choose whether or not to use it.
 
It is but it is up to each person whether they choose to enable OneDrive or not. Each person has a subscription and up to 1tb of storage but not everyone has it turned on and not everyone syncs the same folders (some only do documents rather than desktop).

As a business it isn't something we push as much as it just comes part of 365 and people choose whether or not to use it.
So, if I understand it correctly, you want to get the sync folder that the user selected when they enabled OneDrive. I converted your python code to VBA, and it didn't work in my environment. My corporate machine didn't have that specific Reg Key. Instead, I found my sync folder in the HKCU hive.
 

Users who are viewing this thread

Back
Top Bottom