Tutorial :Windows 7 folder sharing API



Question:

I wonder if it's possible to programmaticaly share folders in Windows 7 while running in restricted logon session:

1) NetShareAdd returns ERROR_ACCESS_DENIED. 2) Command line net share says the same. 3) But explorer has no problems creating new shares without invoking UAC. How does it do that?

Any help will be greatly appreciated.


Solution:1

UAC in windows 7 is less strict than it was in Vista. Windows 7 regards Explorer as a trusted application so it will silently create the share without a UAC prompt (you can change this behavior in the Control Panel).

Your application isn't a trusted one (OK, you trust it, but the operating system does not). Probably you also don't explicitly demand administrator rights in your application. In that case Windows 7 treats your program as unprivileged and refuses access, that why the error message.

A solution could be adding a manifest to your program requesting an ExecutingLevel of requireAdministratior. See for example Demand UAC elevation for an application by adding a manifest. But then your whole application runs as administrator. There are some more granular solutions.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »