This project has moved and is read-only. For the latest updates, please go here.

Connect: access denied when supplying a username

Dec 3, 2009 at 2:13 PM

I am having problems connecting to the task scheduler when I specify a username & password.  Ultimately, I will need to connect to the task scheduler using a specific account.   

I am running the code whilst logged in under the local user which has administrator rights.  This is on a Windows 7 machine (although I have experienced this on Vista as well.)  If I don't specify username or password, i.e.

TaskService ts = new TaskService(null, null, null, null, false);
TaskService ts = new TaskService("myMachine", null, null, null, false);

then all is OK but if I specfiy the username & password (with or without specifying the domain), i.e.:

TaskService ts = new TaskService("myMachine", "myUser", null, "myPassword", false);
TaskService ts = new TaskService("myMachine", "myUser", "myDomain", "myPassword", false);

then I get E_ACCESSDENIED, despite actually being logged in as the account that I am specifying and running the app as Adminstrator.  I am assuming that for a local account, the domain is the same as the machine name.


Dec 4, 2009 at 6:25 PM

I just confirmed this and even tried it natively with the COM interfaces with the same results. Supplying a username and password with a machine name set to the local machine on my Vista environment fails. If I use the same username and password to connect to a remote machine, it works. For the next release, I have added a line of code to null out the machine name if it matches the local machine. This appears to be a Microsoft related oddity.