0

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.

MB34
  • 4,210
  • 12
  • 59
  • 110
  • What version(s) of Windows does this run on/do you support? – Stinky Towel May 07 '18 at 20:21
  • see last line in post – MB34 May 07 '18 at 20:21
  • Please clarify your question because you put "...where it will **not** require an admin to setup" - does the "not" also apply to items 2, 3 and 4? But that may be moot because it sounds like you're asking for any program to register itself as a service and access any files on the system without needing any admin permissions at any point from setup to running - that's impossible on every modern secure operating system and a terrible design. – Dai May 07 '18 at 21:03
  • I'm really asking, too, whether there are options for my application to be run in the above described scenario. This application does a file sync with our servers and we *should* be able to use the Backup system account but it, too requires a password. We don't always have a password, whether it be a user password or even an admin password. – MB34 May 07 '18 at 21:08
  • I mean the Backup Operators group account – MB34 May 07 '18 at 21:22

1 Answers1

0

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.

Will
  • 43
  • 6
  • I agree with you. I wished I had the source to the application, however. They are not yet letting me access that source code. ;-( I'm only gathering options. – MB34 May 08 '18 at 13:10
  • One other issue is that the sync must be on a timer. It is not recommended to run a timer in a service. – MB34 May 08 '18 at 15:05
  • @MB34 Where are you getting that from? You can run timers in a servie - just be sure to use the right Timer class (i.e. not the WinForms timer, but the threading timer): https://stackoverflow.com/questions/246697/best-timer-for-using-in-a-windows-service – Dai May 08 '18 at 15:28
  • @MB34 I'm not sure why you say that- running a timer or a scheduled task inside a windows service is a common and accepted practice. Here's a link showing a basic example of how to do it: [WindowsService with Timer](http://docs.topshelf-project.com/en/latest/configuration/quickstart.html). – Will May 08 '18 at 17:35