dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.21k stars 191 forks source link

Logon with a windows user that has no password #857

Closed rutemja closed 3 years ago

rutemja commented 3 years ago

Is your feature request related to a problem? Please describe. In my special case I have a lot of legacy PCs that are using a Windows user that has no password. When I try to create a task for this user I always get a System.ArgumentException: A username, password, and domain must be provided.

Describe the solution you'd like It should be possible to create a task for a user that has no password.

Describe alternatives you've considered I tried null and String.Empty as password.

dahall commented 3 years ago

Did you find a workaround to your issue? If so, will you share it so others can benefit?

rutemja commented 3 years ago

Sure. The trick is to instantiate the TaskService with the admin user (that has a password) and then call RegisterTaskDefinition with the user that has no password.

Solution in VB.NET (Sorry! :D):

Using scheduler = New TaskService(Nothing, adminUserName, domain, adminPassword)
    Dim definition = scheduler.NewTask()

    ' Change the definition

    scheduler.RootFolder.RegisterTaskDefinition("TestTask", definition, TaskCreation.Create, $"{domain}\\UserThatHasNoPassword", Nothing, TaskLogonType.InteractiveToken)
End Using