0

I want to add drive mapping from my c# app for specific user on remote machine. I'm trying to do it by adding new registry key.

When I add new drive mapping in registry, adding new key in:

HKEY_USERS\< USER >\Network

so, for example, to map \some_path\all under R:\ I make new key:

HKEY_USERS\< USER >\Network\R

with following values: enter image description here

such added drive is visible when I type

net use

in command line, but it's status is "Unavailable". It becomes "OK" after computer restart(and it's visible in Windows Explorer).

How can I achieve it without restarting computer? What process during restart changes drive status and makes it visible in Windows Explorer?

Or another approach: when i type add drive via:

net use R:\ \\some_path\all

it's immediately available in Windows Explorer and visible after net use command. What net use does beside adding new key to registry(as presented above)?

Jac Mos
  • 7,746
  • 4
  • 15
  • 21
  • Editing the registry is not equivalent to calling the underlying api that uses the keys. Logoff + logon would be a minimum requirement. Maybe that is not a real problem, maybe you simply need a .bat file. – Hans Passant Jul 04 '17 at 14:07
  • .bat file? What do You mean? With net use command inside? I can't use net use, because I want add drive mapping for any user(without passing users credentials) – Jac Mos Jul 04 '17 at 14:13
  • The only way to do this is to run code in the user's context. You could either write a background process that is always running in the user's context, or you could have a system service that uses WTSQueryUserToken to run a program as the user. Using a background process is slightly less efficient, but significantly easier to write. Either way you will need some way to communicate with the program and tell it what to do. Named pipes, perhaps, or if you're in a hurry you could take the easy way out and have the program poll for the existence of a file. – Harry Johnston Jul 04 '17 at 23:56
  • What should this process do? I have a code that run net use as current logged in user(I achieve that with task scheduler) but the problem is that I want to add mappings for other users also. I'm one step away from achieving that(I have to figure out what happens during logon or net use command that changes drive status, I'm trying to find it using procmon.exe, but, so far, without luck) – Jac Mos Jul 05 '17 at 05:42

0 Answers0