I have to start my application with admin privileges ( very important ).
When I execute this code without admin privileges everything is perfect. There is an icon in MyComputer.
NETRESOURCE nrServer;
memset(&nrServer, 0, sizeof (NETRESOURCE));
nrServer.dwType = RESOURCETYPE_ANY;
nrServer.lpLocalName = L"S:";
nrServer.lpRemoteName = L"\\\\192.168.32.36\\folderName";
nrServer.lpProvider = L"";
auto dwError = WNetAddConnection2(&nrServer, L"user", L"pass", 0);
But when I execute this code above in application with admin privileges, there is no icon in MyComputer.
I think that can be usefull: Mapped network drives are not showing in My Computer
Is there any way to execute winapi function as not admin when my application has admin privileges?
from
WNetAddConnection2Walso
technically this mean if code run as LocalSystem in the
\GLOBAL??\folder will be create symbolic link to network disk. otherwise link will be created under\Sessions\0\DosDevices\<token LogonId>\and will be visible only for threads(processes) which have the same LogonId in token
if your code have admin privileges - it usually (almost always) have debug privileges. with this we can open process with LocalSystem token and impersonate it before call
WNetAddConnection2.possible also get TCB privilege and after this call
WTSQueryUserToken, convert primary token to impersonation token, viaDuplicateToken, and impersonate -SetThreadToken. and callWNetAddConnection2finally.ok. i try first simply impersonate to LocalSystem
let we have function
which set LocalSystem or token with Tcb privileges to current thread (as far i know all LocalSystem tokens have TCB privilege but anyway write 2 different code for get exactly token with TCB or with LocalSystem)
and
which enable debug privileges in current thread token (it must exist in admin token)
in this case code can be next:
code work ok and really network location created, but with next view:
despite this - drive is browsed correct on click. i not research why is Disconected word in description. but possible some problems with permissions here
if try create drive for concrete LUID, code will be more complex
with this result full ok
now code for util functions:
and..