error when selecting "run whether user is logged on or not"

Jan 5, 2011 at 2:22 AM

So I'm launching the task editor dialog and playing with various scenarios - for the most part everything seems to be working as it should, however there's one critical piece that's causing me heartache.

Most of the time folks running my app will be fine with just letting it run when logged in - however a few folks will be runngin it on Windows 2003 or 2008 and they always log off the desktop when leaving - as such I'll need the option to have them select and account/pw option.

Ideally I'd like to launch the task editor dialog with the "Run only when user is logged on" for the 80/20 rule and let folks fiddle with the schedule and such all they want.  However I'd like it if the users could choose to click the "Run wheter user is logged on or not" radio button and provide a login name/pw as you can when you launch the dialog directly from the windows scheduler.  However when I do this I get a "NoImplementedExcpetion" thrown and the option is not saved (and the login name/pw dialog does not appear).

Presumably the error condition means what it says and the wrapper simply didn't support that option for ShowDialog - but thought I'd check just to be sure if there's a tricky "override" option or the like to allow such an operation or not...



Jan 5, 2011 at 2:46 AM

as an aside - getting similiar missing implementation errors when trying the wizard - I don't see much in the way of how to use it but my simple example just looks like this:  

        Dim ts As New TaskService()
        Dim myWizard As New TaskSchedulerWizard

        myWizard.TaskName = "This is a test"
        If (myWizard.ShowDialog() = Windows.Forms.DialogResult.OK) Then

            ts.RootFolder.RegisterTaskDefinition(myWizard.TaskName, myWizard.TaskDefinition)

        End If
once you get past the "Choose what triggers the task" page you get a "MissingMethodException was unhandled" error - "Void Microsoft.Win32.TaskScheduler.MonthlyTrigger..ctor()'.
Doesn't matter which option you choose, same error each time.
Am I missing something obvious?
Jan 7, 2011 at 10:38 PM

Sorry. I had overlooked a placeholder for some code that I never completed for this functionality. It has been added in source code drop 61872. Please try it out and let me know if it works for you.

Jan 8, 2011 at 2:26 AM

Thanks!  the wizard is now working properly - however the ShowDialog form still kicks out the "NoImplementedException" when I select the "run whether user is logged on or not" radio button.  I wasn't sure if both issues were supposed to be fixed in the version you posted or just the wizard.


Jan 11, 2011 at 5:59 PM

I just posted an updated code drop and new assemblies which should correct both problems. Make sure to extract all the assemblies from the file as a few have been updated. Please let me know if everything is working.

Jan 12, 2011 at 2:12 AM

closer!  It doesn't throw the NoImplementedException any longer but when I select the "run whether user is logged on or not" radio button and then exit the dialog after picking a user I don't ever get the dialog to provide a password, so an error is thrown: "logon failure: unknown user name or bad password".  Should it launch the dialog there (i.e. as it does in the Windows scheduler directly) or is this only supposed to work if we provide the user/pw when we create the task up front? 

thanks for working on this...

Jan 12, 2011 at 4:02 AM

The only time a logon dialog should appear is when "Run whether user is logged on or not" is selected and "Do not store password..." is not selected and the account is not a group or system account. If you are embedding the TaskPropertiesControl in your own dialog, you will need to check for those conditions and use the CredentialDialog to get the password. If you are using the TaskEditDialog, then you need to have the RegisterTaskOnAccept property set to true in order to be prompted for the password. The following is the code currently in the Ok button handler for TaskEditDialog in case you need to replicate it outside to prompt for a password.

if (RegisterTaskOnAccept)
  string pwd = null;
  if (this.TaskDefinition.Principal.LogonType == TaskLogonType.InteractiveTokenOrPassword ||
    this.TaskDefinition.Principal.LogonType == TaskLogonType.Password)
    pwd = InvokeCredentialDialog(this.TaskDefinition.Principal.UserId);
    if (pwd == null)
      throw new System.Security.Authentication.AuthenticationException(Properties.Resources.UserAuthenticationError);
  this.TaskService.RootFolder.RegisterTaskDefinition(this.Task.Name, this.TaskDefinition, TaskCreation.CreateOrUpdate,
    this.TaskDefinition.Principal.UserId, pwd, this.TaskDefinition.Principal.LogonType);
Jan 13, 2011 at 6:39 PM

ah, ok - I got it - I have all the paths worked out now and it's working well!  thanks much for your work on this.