0

I have a windows service that I use to monitor PC stats and health and one of its features is monitoring hard drive space. But I would also like to keep an eye on mapped network drives as well.

System.IO.DriveInfo contains everything I need, however, mapped network drives are only accessible when called from a console app running with user permissions. When DriveInfo.GetDrives() is called from a service, only physical drives are returned. I understand the reason for this, but is there any way to work around it and get free space for a logged-in user's mapped drives from a windows service?

Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
Wobbles
  • 3,033
  • 1
  • 25
  • 51
  • Services are strongly limited in what they can do since Vista. The Task Sheduler is a less limited Alternative that covers just about all service uses cases. – Christopher Dec 22 '19 at 20:49
  • have you considererd using WMI ? – Clint Dec 22 '19 at 20:54
  • https://stackoverflow.com/questions/4278373/how-to-start-a-process-from-windows-service-into-currently-logged-in-users-sess – Ctznkane525 Dec 22 '19 at 21:05
  • Impersonate the user in the Windows Service or simply run the Windows Service in the account of the user. By the way, the Windows Task Scheduler is _also_ a Windows Service. The TS simply makes it easier for you to run a process in the context of the user's account without you having to worry about setting up an impersonation context. –  Dec 22 '19 at 21:20
  • @Ctznkane525 Not trying to start a process. – Wobbles Dec 22 '19 at 22:48
  • @MickyD Unfortunately because of the other hardware I am monitoring, the service itself must run at LocalSystem or higher. Sounds like I may need 2 services. – Wobbles Dec 22 '19 at 22:50
  • You should be able to impersonate the user still. Of course you will need their credentials –  Dec 22 '19 at 23:50

0 Answers0