WIL Dialogs running under System context

Started by hienpham, April 23, 2015, 11:19:06 AM

Previous topic - Next topic

hienpham

Hi all,
  I have a Winbatch process that checks a system for the company violation (such as folders shared to Everyone) and fix them. It fix the violation and sends out a message (created with the WIL Dialog) to the current user to remind him/her and asks him/her not to repeat that kind of violation again. For confirmation, he/she has to click an OK button. Everything works perfectly when we add the process to the registry RUN key or when we force it to run remotely, the user gets the warning UI. But when we set the process to run in an Scheduled Task under the system context, the process still runs fine (discover and fix the violation) but the current user does not get the Warning UI.
Do we have any way to make the user see the warning UI and give him the possibility to click the OK button even though the process is run under the system context?
We cannot make the process run in the Task Scheduler using a system administrator account because we have to change the admin account password frequently.

Thanks so much for any help.

hien

td

Before we get to far off course, are you always executing your scripts on Windows 7/2008 R2 or newer?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hienpham

Thanks TD,
It will be on Windows 7 and 8. If we have to deal differently with each OS, it will not be a problem because we can check the OS in the script and have different codes for each situation.

td

Based on your comments about Admin accounts, I am guessing that you have already discovered that a scheduled task will not interact with the desktop unless you select the 'Run only when user is logged on'.  I image that you have also discovered that you cannot specify the 'logged on' option when you specify SYSTEM as the user account to run your task under.

The are at least two ways to work around this without running the scheduled task as an administrator but neither of them are particularly appealing.  One would be to create a second script the runs with the logged on users credentials.  You would need devise a method to start this script and for this script and your scheduled task script to communicate back and forth with each other.  You could use something as simple as a shared file for communication.

The other approach would be to attempt to use the wtsSendMessage function in our scheduled task to display a message on the desktop of a logged on user.  The function's messages are limited to the title and text format like the WinBatch Message function but it does allow for a choice of buttons and icons.   I have not tried this with a system credentialed scheduled task but I do know that it will work with a service running in session 0 on Windows 7 and 8.  Normally services cannot display UI messages on a user's desktop on Windows 7/8.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hienpham

Thanks TD for your very valuable advices.
  I did not think about the 'logged on' option when I wrote the Winbatch program to implement the main script.
I'm looking now for the object attribute that allows me to force the cron job to "Run only when the user is logged on" to see if the user can see the script UI when that option is on.



hienpham

Hi TD,
  You said that :
   "I image that you have also discovered that you cannot specify the 'logged on' option when you specify SYSTEM as the user account to run your task under."
Is it true that if we set up a cron job running under the System context we cannot set it to "Run only when the user is logged on"?

td

Yes, I believe that is the case.  If you use the Task Scheduler's UI to setup a task, you will notice that the 'Run only when user is logged on' option is disabled when you also specify 'SYSTEM' as the user account and a task cannot interact with an interactive desktop, when that option is not selected.  That is why I mentioned possible workarounds as well.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hienpham

I got it. Again thanks so much for your great help.
With Winbatch forum, it looks like that I have a closed coworker that I have a full trust for his/her knowledge. You and Deana have helped me a lot in my projects.

hien