Windows 7 folder sharing API

≡放荡痞女 提交于 2019-12-10 10:45:15

问题


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.


回答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.



来源:https://stackoverflow.com/questions/2233200/windows-7-folder-sharing-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!