Re: How to get current drive mapping



Dave,

The only way I can think of possibly doing this would be to impersonate
the user that ran the process and then run WNetGetUniversalName while
impersonating. However, in order to do that, you will have to have access
to each user's username (easy) and password (not so easy) so you can make
the call to LogonUser.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Dave" <Dave@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5DBE7799-5B44-4AC4-B187-47B520A9A0C5@xxxxxxxxxxxxxxxx
Thanks Nicholas, but I think you've slightly misunderstood - I don't have
a
"client process" - I am getting a list of the currently running processes
and
trying to find out where they were run from.
I've looked at WNetGetUniversalName but it has the same problem as
WNetGetConnection which I am using now - it will only resolve drive
mappings
for the current logon session.
The Process.Mainmodule.FullPath gives me the location, but (for some
strange
reason) with a drive letter not a UNC. I can find the user account of the
process, and the sessionID, so surely it must be possible to find the
current
drive mapping for that logon session and thus the UNC path. (Of course,
the
mapping may have changed since the process was started, but there's not
much
I can do about that)
--
Dave


"Nicholas Paldino [.NET/C# MVP]" wrote:

Dave,

Unfortunately, the only option that you have here is to have the
client
process do the resolution of the mapped drive to the UNC path. You can
do
this on the client with the WNetGetUniversalName API function (you will
have
to make the call through the P/Invoke layer).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Dave" <Dave@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5D025924-A27A-4942-900F-FEE0EFBAA80E@xxxxxxxxxxxxxxxx
I am actually trying to get the UNC path of the main module of a process
running from a mapped drive, and I am trying to do this from a service.
The
ProcessModule class only provides the full path with the mapped drive
letter,
but the drive letter refers to the drive mapping for the user that
started
the process, and cannot be resolved to a UNC path from a service
running
under LocalSystem.
Presumably, therefore, I need to get the drive mapping either for the
user
account associated with the process, or possibly even for the process's
session ID (I am not clear whether mappings are per user or per
session).
Can
anyone give me a clue as to how I go about this?
--
Dave





.



Relevant Pages

  • Re: How to get current drive mapping
    ... ProcessModule class only provides the full path with the mapped drive letter, ... Presumably, therefore, I need to get the drive mapping either for the user ... session ID. ... The ProviderName property of the Win32_MappedLogicalDisk instance holds the UNC path name of the associated SessionID and the drive letter. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to get current drive mapping
    ... the only option that you have here is to have the client ... process do the resolution of the mapped drive to the UNC path. ... Presumably, therefore, I need to get the drive mapping either for the user ... session ID. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Mapping network resources from a service
    ... > create a drive mapping in the interactive user's TS session. ... I'm trying to allow some automatic tasks to be run whether the specific ... diag and clean the mapping. ...
    (microsoft.public.win32.programmer.kernel)