How to change a scheduled task's account to 'Syste
Posted 12 October 2006 - 21:46
Pasted following is a post I wrote to installshield groups. I am trying my luck here :-)
I used _LaunchAppEx() to execute a commandline to change a scheduled task as following (to change 'MyTask' to under 'System' account):
_LaunchAppEx("schtasks", "/change /tn \"MyTask\" /ru \"System\"", WAIT, SW_HIDE, -1, nvExitCode);
but the nvExitCode always returns 1, instead of 0.
The result is that the task I want to change is not changed at all, using the same commandline manually (schtask /change /tn "MyTask" /ru "System") changed the task.
I don't know how to look into further on why nvExitCode returns 1 but not 0? Anybody can give a hint?
Or is there a better way I should use to do the work (manual way is not considered)? I have successfully executed all commands needed with _LaunchAppEx() in my IS Script functions so far, what special points for this 'schtasks'? I remembered in one thread saying that VBS should be used, but can't remember the reasons.
Even if this (_LaunchAppEx()) way doesn't work, I would like to know why :-)
I also tried HideAppAndWait() to wrap the command, the function returned 0, but the task account was not changed.
Posted 13 October 2006 - 15:37
Did you try with schtasks.exe (I believe you must include the extension)? Maybe also try with the full path to schtasks.exe.
Posted 13 October 2006 - 19:21
Thanks so much for your reply and suggestions.
I tried items you mentioned, both methods (LaunchAppEx and LaunchAppAndWait) returned good results (0).
Once I added the .exe to schtasks, the nvExitCode in LaunchAppEx() became 0 now, but unfortunately the account still remained unchanged. I also tried full path, it's the same (nvExitcode=0, but account not changed).
I think it could be related to the limitation of right of Windows Installer (or InstallShield?), but not sure what that is. BTW I am using Basic project.
If you want to try it by yourself, there is an easy way (in Win2003): Start->Settings->Control panel->Scheduled Tasks, then add a task (I selected CALCULATOR), but don't enter password for the default 'administrator' account, click 'ok' to complete (it will warn you that the task may not be able to run without inputing password, just click 'ok'). Now if you execute [schtasks /change /tn "CALCULATOR" (or whatevername you use) /ru "System"], you will see the task 'run as' is changed to 'NT AUTHORITY/SYSTEM', and you can 'run' it.
You can delete the task and recreate it, then try with a package simply with the command wrapped as a custom action, and see if you can get more clue what's going one behind it. It would be great if you can post your comments on the reason (something I did wrong, or why IS script can't have it done).
Posted 18 October 2006 - 18:02
Posted 01 November 2006 - 14:35
As luck has it, I needed to get my install to set up a program to launch automatically at log in time. I came up with this:
Get your install to set the registry with the following:
Data: Path to your app+ app name, for example:
I tested this manually (ie typing it into the registry) as well as getting the install to run this, and both worked properly.
I hope this helps.