6

使用 C# WMI 我在另一台计算机上启动一个 exe,这个 exe 使用 C#Process类启动另一个 exe。最后一个 exe 尝试Directory.CreateDirectory使用网络路径(又名\\\\comp1\d$\dir\)进行调用。Directory.CreateDirectory抛出此异常:

Access to the path '\\\\blah\blah\blah' is denied.   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, DirectorySecurity dirSecurity)
   at System.IO.Directory.CreateDirectory(String path, DirectorySecurity directorySecurity)

如果我直接在计算机上的控制台中运行第三个 exe,则不会抛出此异常,并且一切正常。

正在创建目录的文件夹的安全设置具有“所有人”的完全权限。

我该如何解决这个问题?

4

3 回答 3

2

Also be aware that when launching an app via WMI, there is a third layer of rights. For instance, if you invoke a method on an existing WMI object, it may not delegate the callers rights, or even the rights of the host exe, but will have an Empty Principal. This may be happening to you.

Go to Computer Management, and under Services and Applications, right click on the WMI Control node and select Properties. Go to the Security Tab, and then navigate to the correct WMI Namespace (most likely root\CIMV2) and make sure the user you are using has the appropriate rights there as well.

于 2010-02-18T21:37:35.627 回答
1

正如 Aaron 所说,windows share 的安全性有两个组成部分,首先是 Share 本身的安全性。第二个是该共享中文件和文件夹的安全性。

两者都必须允许创建目录访问才能使其正常工作。

您还应该知道,EVERYONE 组包括域计算机帐户、内置系统帐户、域用户、来宾和经过身份验证的用户。

这意味着您要做的第一件事是查看实际运行的用户。如果它在机器帐户下运行并且它不是域的一部分,那么您将需要授予该机器帐户访问共享和文件系统的权限。

于 2010-02-18T20:49:05.290 回答
0

有关权限的一些建议,请参阅此线程。

http://www.eggheadcafe.com/community/aspnet/2/10058550/how-to-create-a-folder-in.aspx

于 2010-02-18T20:30:51.613 回答