Windows 7 文件夹共享 API [英] Windows 7 folder sharing API

查看:47
本文介绍了Windows 7 文件夹共享 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在受限登录会话中运行时以编程方式共享 Windows 7 中的文件夹:

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

1) NetShareAdd 返回 ERROR_ACCESS_DENIED.2) 命令行 net share 说的一样.3)但资源管理器在不调用 UAC 的情况下创建新共享没有问题.它是如何做到的?

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?

任何帮助将不胜感激.

推荐答案

Windows 7 中的 UAC 不如 Vista 严格.Windows 7 将资源管理器视为受信任的应用程序,因此它会在没有 UAC 提示的情况下静默创建共享(您可以在控制面板中更改此行为).

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).

您的应用程序不受信任(好吧,您信任它,但操作系统不信任).可能您也没有在应用程序中明确要求管理员权限.在这种情况下,Windows 7 会将您的程序视为非特权程序并拒绝访问,这就是错误消息的原因.

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.

一个解决方案可能是向您的程序添加一个清单,请求一个 requireAdministratior 的 ExecutingLevel.参见例如 通过添加清单要求应用程序的 UAC 提升.但随后您的整个应用程序以管理员身份运行.还有一些更精细的解决方案.

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.

这篇关于Windows 7 文件夹共享 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆