Run batch as administrator - import schtask with highest privileges - Advanced Installer Community
Frimlik
Posts: 5
Joined: Thu Mar 28, 2019 1:39 am

Run batch as administrator - import schtask with highest privileges

Good morning,

what I want to do is to import scheduled task, that would have checked the "Run with highest privileges" checkbox in Task scheduler window, while installation. I successfully created custom action which runs a batch file with command which imports the scheduled task:

Code: Select all

schtasks /Create /XML TaskFileToImport.xml /TN NarozeninySvatky\NarozeninySvatky
Problem is this line:

Code: Select all

<RunLevel>HighestAvailable</RunLevel>
I'm able to import this XML with cmd run as Administrator, but when run from the batch during setup, it writes an error:

Code: Select all

The trust relationship between this workstation and the primary domain failed.
Can I do anything about this?

Thanks a lot for all advices.
George
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Run batch as administrator - import schtask with highest privileges

Hello George,

Can you please proceed like this:

1. go to "Custom Actions" page of your setup project and select your BAT custom action

2. in the right pane check the "When the system is being modified (deferred)" execution time flag and the "Run under the LocalSystem account with full privileges (no impersonation)" execution option flag

3. rebuild and test again the setup install

and let us know how this worked?

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Frimlik
Posts: 5
Joined: Thu Mar 28, 2019 1:39 am

Re: Run batch as administrator - import schtask with highest privileges

Well, that's what I tried, so it does not work.

But I tried another approach - to write a C++ program which does the same thing as the batch, build it and add exe file as temporary file. Then to create Custom action and run this exe file. Now it works as I wanted.

In another thread at this forum I've found and advice to try to run the whole Setup as administrator (Install Parameters (under Package Definition in left pane) -> Run as Administrator), but I have no more time to try it and I'm happy that this "workaround" (which just hasn't come on my mind earlier :D ) works. Maybe just help for other users... :)

George
Catalin
Posts: 7852
Joined: Wed Jun 13, 2018 7:49 am

Re: Run batch as administrator - import schtask with highest privileges

Hello George,

I am glad you got this working.

Also, thanks for your followup on this and for contributing to our forums with your solution. This is highly appreciated and I am sure this will be of help for further users facing a similar scenario.

All the best,
Catalin
:D
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”