1

I want to log a string to an external file in my UMDF driver. For example

// create/open file CString filePath = _T("C:\\Metric.csv"); CHandle hFile(CreateFile(filePath, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL));

This returns 5 (Access Denied).

Is this because UMDF driver cannot access files or resources that require user credentials? If so, which dir can i possibly create/modify a csv file.

JCGM
  • 85
  • 7
  • Could you provide a compilable code? Just create a file, with only a ```main``` function where you want to write to a file? – Melon Feb 28 '19 at 06:26
  • Do you **literally** mean `C:\\Metric.csv`? Because the root directory is indeed a restricted location, so this appears to be _by design_. Pick an appropriate path instead. – MSalters Feb 28 '19 at 11:52
  • @MSalters Can you tell me which is the appropriate path? I tried to get the module directory but it returns "C:\Windows\System32" which is also a restricted location. – JCGM Mar 01 '19 at 00:45
  • 1
    Try the path returned by [**GetTempPath**](https://learn.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-gettemppathw). Depending on the user your *user-mode* driver runs as, it may not have a profile folder available. If it does, you could also try [**SHGetKnownFolderPath(FOLDERID_LocalAppData)**](https://learn.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath). But as it is, no standard users are allowed to write to `C:\`. The reason security settings block C:\ is because people might try to create files in C:\. – Ian Boyd Mar 01 '19 at 03:37
  • GetTempPath() returned "C:\Windows\Temp" and I was able to create my csv file in that directory. Thank you! – JCGM Mar 01 '19 at 08:04

0 Answers0