简体   繁体   中英

Task running-use SYSTEM or Administrator user?

We have an application that runs on a schedule, setup in Task Scheduler. This task is created programatically by our configuration application.

Now, the application needs to access files in a specific directory, the default path a subdirectory in the currently logged in user's home directory.

We have tried setting it up using the SYSTEM account but it doesn't have access to the files and the task quits as soon as it runs.

Normally, we set it up with an administrator's password and flag to run when the user is logged in or not. However, some clients install this app on a system that doesn't require a login, means having a blank or no password. If we setup the task and manually change it to run without them logged in, it requires a password of some sort.

How can I programatically (using C# or VB.net) create this task to run where it will not:

  1. Require an administrator or user password to run or setup
  2. Be able to access the files in "almost" any directory
  3. Be able to run whether any user is logged in or not
  4. Not require creating a new user to run this under

The systems installed on range from Windows Server 2008 to Windows 10.

From your question, it appears you are describing a use case for a Window's service.

Specifically, you need a program that will run:

  • Without user interaction
  • Regardless of whether or not a user is logged in
  • With privileges necessary to access parts of the file-system that might otherwise be restricted by UAC.

Building a windows service will give you this ability without needing to impersonate a user or deal with storing admin account credentials (although you will need to have privileges to install it initially).

You can build a service in any .Net Language (including C# and VB.NET). Topshelf is a pretty good library for building Windows Services in .net and the tutorials/ documentation I've linked to can help you get started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM