Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey there,

I want to create Tasks on a server using an application on computers.

To be abled to work with tasks iam using the Task Scheduler Class Library from this article:

A New Task Scheduler Class Library for .NET[^]

To impersonate i use this:
User Impersonation in .NET[^]

To test it I wrote this simple code to run it on my computer:
C#
ImpersonateUser iU = new ImpersonateUser();
iU.Impersonate("servername", "accountname", "password");
//the account has admin privileges
try
{
    ScheduledTasks st = new ScheduledTasks("servername");
    foreach (string a in st.GetTaskNames())
    {
        MessageBox.Show(a);
    }
}
catch (Exception e)
{
    MessageBox.Show(e.ToString());
}
iU.Undo();


After the line
C#
ScheduledTasks st = new ScheduledTasks("servername");

I get an Access Denied Exception.

Does anyone know why?

Thanks in advance.
Posted
Comments
David_Wimbley 13-May-13 10:06am    
Does your username/pass that you are using for impersonation have proper permissions in the first place to mess with the task scheduler?
ANDiyo 14-May-13 2:17am    
Yes. I can login with the username/pass on the server and iam abled to create tasks there manually.
Kschuler 14-May-13 17:15pm    
What is the exact wording of the exception? Any more info there?
ANDiyo 15-May-13 5:12am    
0x80070005 (E_ACCESSDENIED)
Kschuler 15-May-13 8:46am    
Did you try googling that? Because I did and there were ALL KINDS of possible fixes you could try. http://www.google.com/search?q=0x80070005+%28E_ACCESSDENIED%29&sourceid=ie7&rls=com.microsoft:en-us:IE-ContextMenu&ie=&oe=

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900