ChrisGue
Posts: 93
Joined: Tue Feb 03, 2009 7:26 pm

create a task during installation

I use the AI 7.1.3 to create my installation.

I need to create a task (on vista and Win 7 only).
AI 7.1.3 do not offer all the features I require for the task I want to create, e.g. create a task in a subfolder, no trigger, use highest privileges.

So, I would like to create the task via the command line, importing an xml file, e.g.:
schtasks.exe /Create /TN myCompanyName\MyTaskName /XML {xml filename}

But prior in in the xml file a text has to be repleace with a file being install, as the installation location of the file depoends on the target system.

Is there a wy to do that?
Or does the current version of AI offer all the task features that Vista/Win7 offers?

Regards,
Christoph
Bogdan
Posts: 2791
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: create a task during installation

Hi,

If you have the Enterprise version of Advanced Installer you can do that, i.e. import an edit the XML at install time. The following article
in which we describe the steps required for you to accomplish this.

Your custom action should be added under the "Install" standard action, so its executed after the files are installed on the disk.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ChrisGue
Posts: 93
Joined: Tue Feb 03, 2009 7:26 pm

Re: create a task during installation

thanks for the answer. I wil try that (yes I have the enterprise edition).

are xml files in unicode supported? (with AI 7.1.3)

What custom action do I define for calling 'schtasks.exe'?
Is it 'new attached customaction'. Is the the schtasks.exe used which is already at the computer. Or is the file compiled to the installation and started that one?


Regards,
Chris
ChrisGue
Posts: 93
Joined: Tue Feb 03, 2009 7:26 pm

Re: create a task during installation

ok, I succeeded in installing the xml file with the correct path in it.

But executing the custom action always fails.
I tried attached custom action, then custom action -> exe with working dir and predefined custom action -> launch file or URL
It always fails.

e.g. from the log:
MSI (s) (D8:DC) [18:44:23:013]: Executing op: CustomActionSchedule(Action=SystemFolder,ActionType=1058,Source=C:\Windows\system32\,Target=schtasks.exe /Create /TN JumpingBytes\PureSyncVSS /XML "C:\Program Files\PureSync\PureSyncVSS.xml",CustomActionData=C:\Windows\system32\)
CustomAction SystemFolder returned actual error code 1 (note this may not be 100% accurate if translation happened inside sandbox)
MSI (s) (D8:DC) [18:44:23:124]: Note: 1: 1722 2: SystemFolder 3: C:\Windows\system32\ 4: schtasks.exe /Create /TN JumpingBytes\PureSyncVSS /XML "C:\Program Files\PureSync\PureSyncVSS.xml"

When I execute the commandline
schtasks.exe /Create /TN JumpingBytes\PureSyncVSS /XML "C:\Program Files\PureSync\PureSyncVSS.xml"
it works fine (well, admin privileges are required). It the custiom action executed with admin privileges? I think so?

So, what might be the problem here?
You find the installation here:
http://dl.jumpingbytes.com/PureSyncInst312test1.exe


And I did not find any description what's the differences of the execution properites:
- immediate
- deferred
- rollback
- commit
What to use here?

Thank you,
Chris
ChrisGue
Posts: 93
Joined: Tue Feb 03, 2009 7:26 pm

Re: create a task during installation

it seems the customn action is not executed with admin privileges.
I found out that there is a UI custom action to do this.
Why is this only possible via a UI custom action?

So, how can I start my UI custom action e.g. when the progress bar has reached 100%?

And how do I define that UI custom action??

Search the help for RunAsAdmin finds nothing :(
And the online help states this:
This custom action uses the following input installer properties:
RunAsAdminFile - this property should be set to the path of the file that needs to be launched.
RunAsAdminCmd (optional) - this property should be set to the command line to be passed to the file that will be launched.
RunAsAdminWorkingDir (optional) - this property should be set to the desired working directory, otherwise the current directory will be used as working directory.

But what are RunAsAdminFile, etc?? Where to define them?

Defining the UI custom action has only a function field. But no field to enter the exe and its parameters.
I tried
RunAsAdmin [SystemFolder]schtasks.exe /Create /TN ...

But this does not work.
Please help.

Thanks,
Chris
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: create a task during installation

Hi Chris,
are xml files in unicode supported? (with AI 7.1.3)
Advanced Installer supports the following encodings: UTF-8, UTF-16, ASCII and ISO-8859-1 (Latin-1) and Windows-1252.

Schtasks.exe should be present on every machine you run your installation on, so you don't need to include it in your package, just run the command line. Here is an article to help you with that.
You can schedule the custom action after the InstallFinalize standard action( add it from the InstallExecuteSequence context menu ). Also, if you set it with "Deferred, with no impersonation" execution option it will run under the SYSTEM account.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ChrisGue
Posts: 93
Joined: Tue Feb 03, 2009 7:26 pm

Re: create a task during installation

Thanks again for your answer.

after trying many, many, many different ways, I finally succeeded in adding my task.

But it would be fine to explain some things, menus, items in AI more clearly or describe them at all.
E.g.
RunAsAdmin
or
- immediate
- deferred
- rollback
- commit
and the different custom action (installed, attached, predefined, etc.)

Nevertheless AI is a great software.

Thanks you,
Chris
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: create a task during installation

Hello Chris,

You're welcome, glad to assist.

Here is a link that should help you understand how the menus from the Custom Actions page work:
http://www.advancedinstaller.com/user-g ... -page.html

Also, the following user guide article and sub articles explain how standard and custom actions work in general:
http://www.advancedinstaller.com/user-g ... tions.html

Please let me know if you have any questions.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ChrisGue
Posts: 93
Joined: Tue Feb 03, 2009 7:26 pm

Re: create a task during installation

thanks fo the links, I will check them.

Unfortunately I still have problem creating the task (on Win Vista/7):

When I define as user (or group) for the task the group 'USER', the task will be created during installation. So that is ok.
But when I want to start that task by commandline (schtasks.exe /RUN /TN taskname) it returns 'Access denied'
This is the same when I use the group SYSTEM
I have to edit that task and set the current user as user (or group) of the task. Then it works.

But when I want to add the task (during installation) with the current user specified in the XML file, the task cannot be created as the custom action is executed impersonated.

Do you have an idea how to solve that?


Why can the task not be created when using a deferred custom action? I think the installation must be done with higher privileges. Does the custom action not inherit the privileges of the installation?

Thank you,
Chris
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: create a task during installation

Hi Chris,
But when I want to add the task (during installation) with the current user specified in the XML file, the task cannot be created as the custom action is executed impersonated.
By default Windows Installer runs custom actions as the current user. If the MSI is elevated, custom actions will run as the elevated user. Please note that if you are running the MSI as an Administrator, it doesn't mean your custom actions will have full Administrator privileges. On Vista or higher any user can gain Administrator privileges through elevation. So if your custom actions need Administrator privileges, make sure they use the "...with no impersonation" execution option so they run under the local system account.

In this case you can use the "Launch File as Administrator" predefined UI custom action as you initially tried:
  • Simply set the properties mentioned in the article before calling the custom action and follow the indications from the article.
  • This can be done by adding "SetProperty" published events before the "DoAction" published event that will execute the custom action. Here is an article to help you with this.
You must set all these events in the order of their execution(top - bottom) on the "Next" button from a certain dialog you choose. In this case when the user for example clicks a button, the properties will be set and the custom action executed.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ChrisGue
Posts: 93
Joined: Tue Feb 03, 2009 7:26 pm

Re: create a task during installation

thanks again for the answer.

well, that now clarifies where to specify RunAsAdminFile, RunAsAdminCmd and RunAsAdminWorkingDir.
This is not described in the help and was completely unclear to me.

But it is not described exactly how to enter ' RunAsAdminFile' etc.
What to enter in the field 'Name'?
e.g. [RunAsAdminFile]
or just RunAsAdminFile
or SetProperty=RunAsAdminFile
or ??
It seems that wih [ ] is correct. Is this the case?

But with this, the user has again to confirm the execution of the file. I do not want this. The user has to do this when starting the installation anayway.
I do not see why the user shall confirm that message twice and no user would understand this.
And it does not work as well. The task is not added.

As the installation runs elevated, why then it does not work adding a task via the deferred custom action (that is not impersonated)?

Please advise.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: create a task during installation

Hi,
But it is not described exactly how to enter ' RunAsAdminFile' etc.
What to enter in the field 'Name'?
You can set the property name enclosed by brackets:

Code: Select all

[RunAsAdminFile]
You can read more about this type of control events here: http://www.advancedinstaller.com/user-g ... section139
But with this, the user has again to confirm the execution of the file. I do not want this.
Unfortunately this is how Windows works. One way or another that action needs elevation. This operation can be done in installation UI by using an elevation prompt or during install by running under SYSTEM account.
As the installation runs elevated, why then it does not work adding a task via the deferred custom action (that is not impersonated)?
Because Windows doesn't support it. Deferred custom actions run as the current user. On Vista and Windows 7 even Administrators need to elevate before executing operations that require higher privileges.

In your case the simplest solution would be to run "Schtasks.exe" as deferred with no impersonation and set /U and /P parameters (user context). This way it will have full privileges and run in the user context you want. Our scheduled tasks feature uses a similar approach. To retrieve the username and password you can add LogonInformationDlg dialog in Dialogs page.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”