This project has moved. For the latest updates, please go here.

Non-Interactive for current user?

Apr 3, 2012 at 11:48 AM

I've read through the various posts on the whole interactive issue and I'm a little unclear on something.

I'm using the DLL as part of a management tool that can create Scheduled Tasks on remote machines.  This tool is normally run using alternate credentials (i.e. via RUNAS)

Long story short, I have a checkbox on a form that says "Run Interactively" as well as some textboxes to allow the user to specify credentials under which the task can run.

If I specify credentials for the task I can get it to create an interactive or non-interactive task.  However, if I leave the credentials fields blank it creates the task with the credentials of the user running the application (this is absolutely fine).  However, it will never create a non-interactive tasks.

I am trying to create tasks on Windows 2008 R2  and here's the code

        Me.bln_Interactive = Me.chk_Interactive.Checked


        If Me.bln_taskConfigured Then
            Try
                If Me.chk_RunAsSystem.Checked Then
                    ts.RootFolder.RegisterTaskDefinition(Me.txt_Description.Text, td, TaskCreation.Create, "SYSTEM", Nothing, TaskLogonType.ServiceAccount, Nothing)
                Else
                    If Me.bln_Interactive Then
                        td.Settings.RunOnlyIfLoggedOn = True
                        ts.RootFolder.RegisterTaskDefinition(Me.txt_Description.Text, td, TaskCreation.Create, Me.txt_ID.Text, Me.txt_Password.Text, TaskLogonType.InteractiveTokenOrPassword, Nothing)
                    Else
                        td.Settings.RunOnlyIfLoggedOn = False
                        ts.RootFolder.RegisterTaskDefinition(Me.txt_Description.Text, td, TaskCreation.Create, Me.txt_ID.Text, Me.txt_Password.Text, TaskLogonType.Password, Nothing)
                    End If
                End If
                ts.Dispose()
            Catch ex As Exception
            End Try

Apr 3, 2012 at 1:48 PM

Right, just out of interest I added a little check to see if Me.txt_ID.Text and Me.txt_ID.password were empty and, if so, to give them my userID and password

When I do this I can create non-interactive tasks (i.e. User does not have to be logged on).  So, it seems that if you create the task and pass null values for userid and password it will default to the current user's credentials BUT the tasks is ALWAYS interactive.  Is this a bug?  

Coordinator
Apr 3, 2012 at 4:24 PM

When Registering a task that you desire to run only if the user is logged into an interactive session, use the TaskLogonType.InteractiveToken value. Passing a null value for the user will pull the name from the current session, but the TaskLogonType will determine how the credentials are used. You can get a full explanation of those values in the help file for the library or from the documentation from the COM library here.


Apr 3, 2012 at 4:39 PM
Edited Apr 3, 2012 at 4:40 PM

Maybe I wasn't clear (or I'm being stupid).  I want to be able to pass null values for userID and password have it create a NON-interactive task.  This doesn't seem to work with any of the LogonTypes.  If I specify a LogonType of Password then I MUST pass a value for UserID and Password.  If I specify LogonInteractive it will always create an interactive task (naturally)

So, essentially, I want to not pass credentials but have the task created as "Run whether user is logged on or not".  Maybe this isn't possible?

Coordinator
Apr 4, 2012 at 5:17 AM

You are correct. The base COM library will not support what you want to do. To run non-interactively, you must supply a password and use a LogonType that accepts a password.

Apr 4, 2012 at 9:53 AM

Ah well.  It's as I expected then.  I'll just have to force the users to enter some credentials for each task they create. 

Apr 10, 2012 at 9:24 AM

I have the exact same problem. I noticed that the above can be done if I run my application "as administrator".  Somehow you should rise the permissions of the .NET application in order to make this possible. If someone has any knowledge of that, let me know.

I know just "try" to set it and catch the authorization exception in case it doesn't work. (I think I'll add a dialog that urges the user to change the run settings manually in case he wants to run it non-interactive)

My line of code:

ts.RootFolder.RegisterTaskDefinition(TASK_NAME, theTask.Definition, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount,null);
Apr 10, 2012 at 11:26 AM
It's possible if you use Impersonation. I have a VB.NET class that I found online that I can send you.

Matt

On 10 April 2012 10:24, nschoot <notifications@codeplex.com> wrote:

From: nschoot

I have the exact same problem. I noticed that the above can be done if I run my application "as administrator". Somehow you should rise the permissions of the .NET application in order to make this possible. If someone has any knowledge of that, let me know.

I know just "try" to set it and catch the authorization exception in case it doesn't work. (I think I'll add a dialog that urges the user to change the run settings manually in case he wants to run it non-interactive)

My line of code:

ts.RootFolder.RegisterTaskDefinition(TASK_NAME, theTask.Definition, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount,null);

Read the full discussion online.

To add a post to this discussion, reply to this email (taskscheduler@discussions.codeplex.com)

To start a new discussion for this project, email taskscheduler@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Coordinator
Apr 11, 2012 at 5:19 PM

There is also an impersonation class in the library. You can find it at http://taskscheduler.codeplex.com/SourceControl/changeset/view/77318#78561.