Click here to Skip to main content
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 3: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 545
1 OriginalGriff 285
2 Shweta N Mishra 244
3 BillWoodruff 230
4 Mathew Soji 225
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 13 May 2013
Copyright © CodeProject, 1999-2014
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