简体   繁体   English

Windows 7文件夹共享API

[英]Windows 7 folder sharing API

I wonder if it's possible to programmaticaly share folders in Windows 7 while running in restricted logon session: 我想知道是否可以在受限登录会话中运行时在Windows 7中以编程方式共享文件夹:

1) NetShareAdd returns ERROR_ACCESS_DENIED. 1)NetShareAdd返回ERROR_ACCESS_DENIED。 2) Command line net share says the same. 2)命令行网络共享也是如此。 3) But explorer has no problems creating new shares without invoking UAC. 3)但是,资源管理器在不调用UAC的情况下创建新共享没有任何问题。 How does it do that? 它是如何做到的?

Any help will be greatly appreciated. 任何帮助将不胜感激。

UAC in windows 7 is less strict than it was in Vista. Windows 7中的UAC不如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). Windows 7将资源管理器视为受信任的应用程序,因此它将在没有UAC提示的情况下静默创建共享(您可以在“控制面板”中更改此行为)。

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. 在这种情况下,Windows 7将您的程序视为非特权程序并拒绝访问,这就是错误消息的原因。

A solution could be adding a manifest to your program requesting an ExecutingLevel of requireAdministratior. 一种解决方案是在您的程序中添加清单文件,以请求ExecutingLevel的requireAdministratior。 See for example Demand UAC elevation for an application by adding a manifest . 例如,通过添加清单来查看应用程序的需求UAC海拔 But then your whole application runs as administrator. 但是随后您的整个应用程序将以管理员身份运行。 There are some more granular solutions. 还有一些更详细的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM