Or better yet, forget about this and put your dat file in \systemroot and be done with it. Program Files can change after install IIRC using a power toy (or perhaps the shell, it’s been a long time since I have done it). Besides, if you can write to program files, you are already an elevated user, so writing to a file in \systemroot is no different.
d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Ken Cross
Sent: Tuesday, August 19, 2008 4:36 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How can I get the path of "%programfiles% when using ZwCreateFile in driver?
Since it doesn’t change, save it in the registry during installation.
If you use Windows Installer (MSI) to install, then save
[ProgramFilesFolder] in the registry somewhere your driver can find.
If you use an INF file, DirId %16422% is the Program Files folder.
Then your driver can read it from the registry at startup time or when
needed.
HTH,
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@dayang.com.cn
Sent: Tuesday, August 19, 2008 4:41 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] How can I get the path of "%programfiles% when using
ZwCreateFile in driver?
My driver need to open a file in the directory of “%HOMEDRIVE%\Program
Files\Common Files\filename.dat”. That means, if my system is in c: , then
the directory is “c:\Program Files\Common Files\filename.dat”. Now I use
ZwCreateFile() with a path of L"\??\C:\Program Files\Common
Files\filename.dat" to open it. But if someone’s system is installed in d:
or others,then it will not work.
After many tries, I know I can use var “SystemRoot” in driver as
L"\SystemRoot\System32\filename.dat" . But I cannot use
L"\SystemRoot\…\Program Files\Common Files\filename.dat" . So I cannot
find system disk by “SystemRoot”. I also cannot use L"\HOMEDRIVE\Program
Files\Common Files\filename.dat". It seems “HOMEDRIVE”, “programfiles”
and “commonprogramfiles” cannot be used in kernel driver. So are there any
variable equals to “%HOMEDRIVE%” or "%HOMEDRIVE%\Program Files" or
"%HOMEDRIVE%\Program Files\Common Files"?
Or by other means how can I get the path of “%HOMEDRIVE%\Program
Files\Common Files\filename.dat”?
Thanks.
-Liu
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer