[SOLVED] Run as administrator without a password (when the system account isn't sufficient) \o/

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

September 25, 2019 - 3:08 PM

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)

- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

September 25, 2019 - 4:05 PM

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)

Tranquil IT
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

September 25, 2019 - 4:32 PM

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?
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
User avatar
vcardon
WAPT Expert
Messages: 278
Registration: Oct 06, 2017 - 10:55 p.m.
Location: Nantes, France

September 25, 2019 - 11:11 PM

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
Vincent CARDON
Tranquil IT
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

September 26, 2019 - 8:54 AM

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
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
florentR2
Messages: 100
Registration: February 13, 2020 - 5:23 PM

April 30, 2020 - 10:23

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?
olaplanche
Messages: 178
Registration: January 26, 2017 - 11:11

April 30, 2020 - 10:38

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!
- Installed WAPT version: 2.6.0.16795 Enterprise
- Server OS: Linux / Debian Bookworm
- Administration/package creation machine OS: Windows 10
florentR2
Messages: 100
Registration: February 13, 2020 - 5:23 PM

April 30, 2020 - 10:45 AM

Cool, thanks, that can also help for those who don't like the SYSTEM account for an installation
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

April 30, 2020 - 2:48 PM

Can you try using the run_as_administrator function?

Code: Select all

from common import run_as_administrator

run_as_administrator('sample.exe','--args')
florentR2
Messages: 100
Registration: February 13, 2020 - 5:23 PM

May 6, 2020 - 5:31 PM

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.
Locked