Page 1 of 2
[SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: September 25, 2019 - 3:08 PM
by olaplanche
I'm sharing something I just managed to do that I've never seen on the forum.
Let me give you the example of my latest package for installing the Archiwizard v8.0.1 software:
This is an MSI file; the setup returns the wrong uninstallkey, so we can forget about the install_msi_if_needed command...
The MSI file only installs silently under the administrator account, so we can forget about the `run` command since a package is executed under the system account...
To bypass all these problems, from the system account it's possible to run a process as administrator in PowerShell without having to provide the password! And the best part is that when you provide the correct uninstallkey in the package retrieved with the command "wapt-get list-registry archiwizard", the application uninstall works correctly.
Here is the code for my package:
Code: Select all
# -*- coding: utf-8 -*-
from setuphelpers import *
uninstallkey = ['{AF474B4B-28ED-4AAE-A623-BB78E4D4AEC7}']
def install():
print('installing wapt-archiwizard')
run_powershell('Start-Process msiexec.exe -Wait -ArgumentList "/I %s\ArchiWIZARD-2020-x64(8.0.1).msi /quiet" -verb runAs' % basedir)
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: September 25, 2019 - 4:05 PM
by htouvet
Thank you, very interesting...
A small correction:
add an "r" before the powershell command because there are backslashes that could be misinterpreted.
Code: Select all
run_powershell(r'Start-Process msiexec.exe -Wait -ArgumentList "/I %s\ArchiWIZARD-2020-x64(8.0.1).msi /quiet" -verb runAs' % basedir)
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: September 25, 2019 - 4:32 PM
by olaplanche
OK thanks.
I am now trying to create a registry key in the session setup for software activation:
Code: Select all
def session_setup():
registry_set(HKEY_CURRENT_USER,makepath('Software','Graitec','License Manager'),'GRAITEC_LICENSE_FILE',r'7621@servername;',type=REG_SZ)
Only the "Graitec" key exists, so the "License Manager" key must be created, followed by the reg_sz value "GRAITEC_LICENSE_FILE".
My code isn't working, do you have any ideas?
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: September 25, 2019 - 11:11 PM
by vcardon
Olivier,
it's fantastic to see how you've progressed with the tool and that you're using some of the time you save with it to share such clever tips with others.
At Tranquil IT, we're big fans of free software, even though we're well aware that it's difficult to make a living from a strictly free and community-driven model.
Seeing your initiative to share your experience helps reassure us that we're doing something useful and that we're managing to get interested and motivated people involved in the project.
Best regards,
Vincent
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: September 26, 2019 - 8:54 AM
by olaplanche
I solved the registry problem, I always forget to add an r in front of the string to prevent certain characters from being interpreted (the space in my case).
Final package code:
Code: Select all
# -*- coding: utf-8 -*-
from setuphelpers import *
uninstallkey = ['{AF474B4B-28ED-4AAE-A623-BB78E4D4AEC7}']
def install():
print('installing wapt-archiwizard')
run_powershell(r'Start-Process msiexec.exe -Wait -ArgumentList "/I %s\ArchiWIZARD-2020-x64(8.0.1).msi /quiet" -verb runAs' % basedir)
def session_setup():
registry_set(HKEY_CURRENT_USER,r'Software\\Graitec\\License Manager','GRAITEC_LICENSE_FILE','serverport@servername;',type=REG_SZ)
In response to vcardon:
It is with pleasure that I share my findings, I am a fan of the wapt product and I support your free and community-based model.
Looking forward to meeting the team at the AdminSys event in Toulouse on October 17th
THANKS
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: April 30, 2020 - 10:23 AM
by florentR2
Code: Select all
run_powershell(r'Start-Process msiexec.exe -Wait -ArgumentList "/I %s\ArchiWIZARD-2020-x64(8.0.1).msi /quiet" -verb runAs' % basedir)
Good morning,
This case really interests me.
With the powershell option
runAs Does this launch as administrator without asking for any other information or password?
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: April 30, 2020 - 10:38 AM
by olaplanche
Yes, as strange as it may seem, it works without providing the admin account password...
To be more precise, it works when the PowerShell command is run by the system account; obviously, it doesn't work from a user account.
I solved all my problems with old software not installing correctly using the system account this way, and it's worked every time since!
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: April 30, 2020 - 10:45 AM
by florentR2
Cool, thanks, that can also help for those who don't like the SYSTEM account for an installation
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: April 30, 2020 - 2:48 PM
by sfonteneau
Can you try using the run_as_administrator function?
Code: Select all
from common import run_as_administrator
run_as_administrator('sample.exe','--args')
Re: [SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/
Published: May 6, 2020 - 5:31 PM
by florentR2
sfonteneau wrote: ↑Apr 30, 2020 - 2:48 PM
Can you try with the run_as_administrator function?
For the test I am doing (Autocad 2020) the command works fine on the packaging machine if I test the package.
However, I still can't deploy the software on a machine.
The problem might be elsewhere; I'll start a new thread, that will probably be better.