Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok I'm trying to get the following to work with VS 2010 & Win 2K8 Server:

[Security] - User Impersonation[^]

If I use a local folder it works fine, but when I choose a network mapped drive I get the following:
CSS
Result:
        Failed to open the file, error: 3
        The system cannot find the path specified.


I have coded in the user name, password, domain and file and made the following change in main:
XML
// We support a user name, password, domain (optional) and filename (optional)
if((argc < 3) || (argc > 7))
{
    Usage();
    //return 0;
}


The reason I'm trying to get this to work is we are working on implementing security for our network (There's an idea huh), and our senior programmer likes to have everything is one big giant directory so we are trying to restrict user access to certain folders, but by doing so our applications won't work. So we would like to give the application the "rights to do so" and this seems like the best way, but I can't get it to work on mapped drives.

Not sure if it matters but this is in a terminal services enviroment.
Thanks in advance!!
Posted
Updated 1-Sep-11 4:48am
v3
Comments
MacRaider4 1-Sep-11 12:44pm    
Ok, I figured out one issue and that is if I use the UNC path it does work... I forgot to take out the : after the $ before. The big downside is I'd have to change every instance in every application to the UNC vs the mapped drive letter (pretty time consuming). Any one have any other ideas?

A mapped drive created by a application running under the local system account is visible to all logon sessions. So if you want to the mapped drive to be visible under the impersonated user context create it as mentioned.
 
Share this answer
 
UAC is likely your problem. By default, network drives mapped in a user session are NOT mapped into administrative space(or other user space for that matter). You have to enable "linked" connections on the client by setting the following key: (This should work on term server as well)

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]

"EnableLinkedConnections"=dword:00000001


Once you do that, drives mapped in user space will be available in admin space and your code should work.

The same sort of thing happens if you try to copy from a mapped drive to another mapped or local location where privilege elevation has to occur. Without the linked connections, you'll get a 'path not found' error and the only way to make the copy go is to switch from a named drive to a UNC path. This key fixes that problem as well.

HTH,
Jason
 
Share this answer
 
Comments
MacRaider4 2-Sep-11 9:57am    
I'm not seeing anything about Linked Connections in that part of the registry. I checked both as myself and as the servers administrator account.
It's so much fun doing things wrong for so many years and then trying to do things the right way.
Jason Gleim 2-Sep-11 10:14am    
If the key doesn't exist, add it. Copy and paste this into a file and name it "linkedconnections.reg" Then run it from an admin account.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]

"EnableLinkedConnections"=dword:00000001
MacRaider4 14-Sep-11 12:27pm    
Sorry been busy with 12,000 different things...
ok so we have kinda gotten this to work. However a lot of what we do uses spawn (wspawnlp) of which we are able to get the application to spawn but that "application" isn't able to see the directory so the spawned process isn't inheriting the permissions.
Does this mean we'll have to have the impersonation in each and everything we write that a user may use? Or is there something we're missing with the impersonation?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900