Click here to Skip to main content
11,709,581 members (47,472 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET TaskScheduler
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:
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
ScheduledTasks st = new ScheduledTasks("servername");

I get an Access Denied Exception.

Does anyone know why?

Thanks in advance.
Posted 13-May-13 2:48am
ANDiyo159
Comments
David_Wimbley at 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 at 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 at 14-May-13 17:15pm
   
What is the exact wording of the exception? Any more info there?
ANDiyo at 15-May-13 5:12am
   
0x80070005 (E_ACCESSDENIED)
Kschuler at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 525
1 OriginalGriff 250
2 Peter Leow 219
3 Maciej Los 185
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856


Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 13 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100