• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1069
  • Last Modified:

Convert Kernel Device Path to Regular Path (Just string parsing)

I call GetProcessImageFileName and it returns a string like:

"\Device\HarddiskVolume1\Program Files\Internet Explorer\iexplore.exe"

I need the regular path, so it should be c:\Program Files\..." etc.

I have a function that will call QueryDosDevice and convert "\Device\HarddiskVolume1" to "C:". However, my function won't accept the full path, just the "\Device\HarddiskVolume1" portion. My string is a LPTSTR, if someone  could write something simple to conver this that would be great.

Also, I know about the GetModuleFileNathEx and it doesn't really work properly, so I need to use this method.
0
NetworkArchitek
Asked:
NetworkArchitek
  • 5
  • 3
1 Solution
 
AxterCommented:
Do a character search for a third '\\' character, and set it to zero before passing it to QueryDosDevice

TCHAR *Pos1 = _tcschr(mypath, '\\');

if (Pos1)
{
TCHAR *Pos2 = _tcschr(Pos1 , '\\');
if (Pos2)
{
TCHAR *Pos3 = _tcschr(Pos2 , '\\');
if (Pos3)
{
 Pos3[0] = 0;
 //Now pas mypath to QueryDosDevice
0
 
AxterCommented:
>>Also, I know about the GetModuleFileNathEx and it doesn't really work properly, so I need to use this method.

Exactly how does it not work?
Please give details.
0
 
NetworkArchitekAuthor Commented:
I'll try your solution. Well the problem with GetModuleFileNameEx is that if the process is svchost or wuaclt.exe it seems to return a null path.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
NetworkArchitekAuthor Commented:
That doesn't seem to work. I had to change it a bit (add curly braces etc) to get it to compile but Pos1, Pos2, and Pos3 end up pointing to exactly the same strings so when you do a Pos3[0] = 0; it just makes everything null.

My original string is held in LPTSTR and I don't call QueryDosDevice directly. I call a function called GetDrive. So if GetDrive has the signature:

BOOL GetDrive( LPCTSTR pszDosName, CString& outputDriveLetter )

 And my original string is held in a variable called lpPath, what's the best way to accomplish this? Thanks in advance.
0
 
AxterCommented:
>>That doesn't seem to work. I had to change it a bit (add curly braces etc) to get it to compile but Pos1, Pos2, and Pos3 end up pointing to exactly the same
>>strings so when you do a Pos3[0] = 0; it just makes everything null.
Yes, I forgot to increment it before the next search.
Try the following:
CHAR *Pos = _tcschr(mypath, '\\');

if (Pos)
{
Pos = _tcschr((++Pos) , '\\');
if (Pos)
{
Pos = _tcschr((++Pos), '\\');
if (Pos)
{
 Pos[0] = 0;
 //Now pas mypath to QueryDosDevice
0
 
AxterCommented:
>>I'll try your solution. Well the problem with GetModuleFileNameEx is that if the process is svchost or wuaclt.exe it seems to return a null path.

I would still use this as the primary method, and then use the more complex method if you get a NULL path from this API.
0
 
NetworkArchitekAuthor Commented:
Ok wonderful! One more issue and then I'll accept. Of course, I'm losing my original path. Here is my code:

---------------------
TCHAR *Pos1 = _tcschr(lpPath, '\\');
TCHAR *Pos2, *Pos3;
if (Pos1)      
{
TCHAR *Pos2 = _tcschr(++Pos1 , '\\');
if (Pos2)
{
TCHAR *Pos3 = _tcschr(++Pos2 , '\\');
f (Pos3)
Pos3[0] = 0;
}
}
                              
CString csTemp2;
GetDrive(lpPath, csTemp2);
output += csTemp2;
--------------

output is a CString. Could you modify it so that output becomes the correct path. i.e. "C:\Program Files\..." blah blah.  Just to be clear, csTemp2 after the GetDrive call has "C:" as its value. Thanks.
0
 
AxterCommented:
>>output is a CString. Could you modify it so that output becomes the correct path. i.e. "C:\Program Files\..." blah
>>blah.  Just to be clear, csTemp2 after the GetDrive call has "C:" as its value. Thanks.\

You can just make a copy of the original path, and use the copy to pass to GetDrive.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now