Page 1 of 1

user profile manipulation

Published: Dec 15, 2020 - 1:54 PM
by cyrilg
Hello,
I'm trying to install a Firefox update package from version 52.9esr to Firefox 68.9esr.
The problem is that this version upgrade creates a new default user profile.
The idea is to back up the file C:\Users\Username\AppData\Roaming\Mozilla\Firefox\profiles.ini to another folder during the installation (in my example, C:\temp) and then restore it to its original location after the installation is complete, in order to retain access to the user profile (containing bookmarks, passwords, etc.).

To do this, I have: `
from setuphelpers import *

uninstallkey = []

def install():
#copying the profiles.ini file from AppData to c:\Temp
print('saving the profiles.ini file')
filecopyto(user_appdata()+'\Mozilla\Firefox\profiles.ini','c:\Temp')

#killing the Firefox.exe process
print('closing Firefox')
killalltasks("firefox.exe")

#updating to Firefox 68.9.0esr (32-bit)
print('updating to Firefox 68.9.0esr (32-bit)')
install_exe_if_needed("Firefox Setup 68.9.0esr.exe",'/s',key='')

.....

Everything goes well when I run my installation from PyScripter on my development machine (running Windows 10 Pro); it correctly copies the profiles.ini file from C:\Users\Username\AppData\Roaming\Mozilla\Firefox\ to C:\Temp.

When I launch the installation of my package from the console to another machine (Debian 9 server, Wapt 1.7.4), I get an installation error:
IOError: [Errno 2] No such file or directory: u'C:\\Windows\\system32\\config\\systemprofile\\AppData\\Roaming\\Mozilla\\Firefox\\profiles.ini'

It is looking for the profiles.ini file in the wrong place.

I've tried various approaches, including using `
from os import path

appdatapath = path.expandvars('%APPDATA%')
filecopyto(appdatapath+'\Mozilla\Firefox\profiles.ini','c:\Temp')`

, but the problem persists: the package works fine locally on the development machine using PyScripter, but I get the same error when I try to install the package from the console on another test machine.

There's a subtlety I'm missing: why does my script look for the file in the correct location when I install from PyScripter, and then look for it in `C:\Windows\system32\config\systemprofile\AppData\Roaming\Mozilla\Firefox` when I install from the console?

Thank you in advance for your help.
Sincerely,
Cyril G

Re: User profile manipulation

Published: Dec 17, 2020 - 2:32 PM
by Aedenth
Hello,

when you test your package from PyScripter, the installation happens in your user's context.

When you run the installation on another machine, the installation is done as the SYSTEM user, who doesn't have a profile in the traditional sense.

If you only have one user on the machine, you'll need to retrieve the name of the last logged-in user profile and use that information to construct the correct path to C:\users\

I'm not sure if WAPT has a function to retrieve the last authenticated user on a machine.
Check the WAPT documentation; otherwise, there must be a registry key containing that information.

Re: User profile manipulation

Published: Dec 17, 2020 - 2:44 PM
by htouvet
in setuphelpers:

Code: Select all

get_last_logged_on_user()
-> returns mydomain\user

for a local user

.\user

Also

Code: Select all

get_loggedinusers()
returns a list ['user']

List of machine profiles:

Code: Select all

 local_users_profiles()
['C:\\Windows\\ServiceProfiles\\LocalService',
 'C:\\Windows\\ServiceProfiles\\NetworkService',
 'C:\\Users\\htouvet',
 'C:\\Users\\user1']