开发者

Impersonation not working in scheduled task

开发者 https://www.devze.com 2023-02-19 16:21 出处:网络
I have a very simple program that copies file from one location to another, and I have scheduled it run everyday using the windows scheduler.

I have a very simple program that copies file from one location to another, and I have scheduled it run everyday using the windows scheduler.

  1. But when the scheduler launches it, it fails and logs System.UnauthorizedAccessException: Access to the path '' is denied.
  2. If I just launch the program by double clicking it, it fails with the same error as above.
  3. But when I run the program manually by doing a Run as and use the same credential that I used in the windows scheduler it runs successfully.

The credential used in all the three cases is the one that I use to login to the system.

Can anybody please help me in understanding why this is happening?

Thank you

Update

No reason could be found for this behaviour, so implemented the following workaround -

  1. Wrote a program to copy the file.
  2. Wrote a launcher program. This program launched the file copy program by imperson开发者_开发百科ating the user.
  3. Scheduled the launcher program in windows scheduler.

Used info at http://www.codeproject.com/KB/cs/Execute_Command_in_CSharp.aspx to impersonate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号