Page 1 of 1

Run an AutoIt script as a local administrator?

Published: June 13, 2018 - 4:55 PM
by Jonattend
Hello,

I'm making good progress with WAPT and creating and modifying existing packages.

For educational purposes, I need to install an application that requires, on its first startup (and only then), the user to enter a name, organization, and serial number.

I've tried various things without success so far:
- regShot before and after inserting the serial number, then exporting to a .reg file
- silently executing the .reg file after installation (via the `def install()` function in the WAPT package): the software doesn't activate... there might be other file modifications/creations after the license is inserted.

Another test: via AutoIt
- installing the application via WAPT
- in WAPT's `def install()` function, running an AutoIt script to start the application and simulate keyboard input...
The program installs successfully, but the problem is that the AutoIt script is executed under the System account... and the program, if started under the System account, doesn't seem to recognize the script.

In my AutoIt script, I forced the program to launch as a local administrator.
It appears correctly in the processes, but my AutoIt script (launched as the system account) doesn't run...
Basically, I end up with one program running as a local administrator and a script running in a queue as the system account.
Launching both as the system account doesn't help...

I haven't found any option in the Python script to request that the script be launched as an administrator...

Perhaps there's a simpler method...?

PS: By installing the software normally and then manually running my AutoIt script (as an administrator), activation is successful...

Thanks for any suggestions. ;)

Re: Running an AutoIt script as a local administrator?

Published: June 14, 2018 - 1:45 PM
by Jonattend
Hello,
I was able to contact the software publisher who just provided me with a license file adapted to my license and my institution.
So, copying and pasting the license file into the correct location should be OK (via `def install()`).

I'm testing it and will give you feedback. ;)

Re: Running an AutoIt script as a local administrator?

Published: June 14, 2018 - 3:56 PM
by Jonattend
Still nothing... the publisher did provide me with a license file... but it needs to be launched once to activate... worse, it opens a dialog box... which I have to cancel before I can finally see that the software is activated... I'm continuing my search, but I'm starting to run out of ideas :roll:

Re: Running an AutoIt script as a local administrator?

Published: June 14, 2018 - 6:13 PM
by sfonteneau
Two possible solutions? 1.

Create an "interactive" scheduled task that launches the installation; in my opinion, keyboard emulation works within it.
Another possible solution:

Create an "interactive" Windows service that launches the installation, then run it.

Both solutions are very ugly...

I also can't get `runas` to work as the system account or use `psexec` as the system account.

Another solution:

I've seen a friend do it.

Integrate the administrator username and password into AutoIt (I know it's possible).
Launch the AutoIt installation in a `session_setup`; AutoIt will then launch automatically as administrator.

However... it's easy to retrieve the password from AutoIt...

Simon

Re: Running an AutoIt script as a local administrator?

Published: June 15, 2018 - 08:49
by Jonattend
Thanks for the suggestions...

I have an idea, but I don't know if it's feasible with WAPT:
- silent installation of the program via WAPT (SYS account)
- in the WAPT package, `def install()`: creation of an interactive scheduled task at Administrator account login
- in this task, opening the AutoIt file launching the program + keyboard simulation
- still in AutoIt: deletion of the administrator scheduled task + deletion of the AutoIt file itself... + reboot.

Perhaps a session setup would be simpler? (I haven't tested session setup yet...)

What do you think?

Re: Running an AutoIt script as a local administrator?

Published: June 15, 2018 - 09:41
by Jonattend
I just tried session_setup: it works fine for my local Administrator... but the problem is that it also runs for my domain users.

Ideally, the session setup should only need to be launched once by the Administrator and that's it.

The document clearly states that "The session_setup for each package is executed only once per package or package version and per user profile"...I need to find a way to disable session_setup after it has been launched by the Administrator...".

Currently in my session_setup():

Code: Select all

run(r'....\fichier_autoIT_activation_logiciel)
Final objective: session_setup():

Code: Select all

run(r'....\fichier_autoIT_activation_logiciel)
"desactiver le session_setup"
"suppression du fichier fichier_autoIT_activation_logiciel"

Re: Running an AutoIt script as a local administrator?

Published: June 15, 2018 - 11:13
by sfonteneau
The simplest way is to add a condition in the session setup.

Code: Select all

if get_current_user() == u'Administrateur':
         run(r'....\fichier_autoIT_activation_logiciel)

Re: Running an AutoIt script as a local administrator?

Published: June 15, 2018 - 4:51 PM
by Jonattend
Phew! I finally did it!

Thanks for the tip about session_setup and get_current_user() ;)

In my def install(), I install the software.

In session_setup():

Code: Select all

if get_current_user() == u'Administrateur':
         run(r'....\fichier_autoIT_activation_logiciel)
         delete_ay_next_reboot("C:\xxxxx\fichier_autoIT_activation_logiciel")
I've learned quite a lot from all of this :)
I have a second software program of the same type, I'm going to try that again and see the result.

Resolved!