打开一个Windows共享文件夹&多个域名 [英] opening a windows shared folder & multiple domains

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

问题描述

嗨朋友

我想通过我的网站打开一个Windows共享文件夹,但共享文件夹&网站的主机位于私人互联网的不同域中。

我正在使用此代码并尝试了许多代码之前

hi friends
I want to open a windows shared folder through my website,but shared folder & website''s host are in different domains on private interanet.
I''m using this code and tried many code before

System.Diagnostics.Process command = new System.Diagnostics.Process();
command.StartInfo.FileName = @"explorer";
command.StartInfo.Arguments = @"\\server\shared folder";
command.StartInfo.UserName = "username";
command.StartInfo.Domain = "domain_name";
System.Security.SecureString pwd = new System.Security.SecureString();

foreach (char c in "user_password")
    pwd.AppendChar(c);

command.StartInfo.Password = pwd;
command.StartInfo.CreateNoWindow = false;
command.StartInfo.Verb = "open";
command.StartInfo.UseShellExecute = false;

try
{
    command.Start();
}

catch (Exception e11)
{
    Label1.Text = e11.Message;
}

command.Close();



但每次出现此错误时:


but every time I get this error :

<br />
login failed unknown username or bad password <br />



我不知道为什么以及如何解决这个问题..


I dont why and how to solve this..

推荐答案

在某些情况下需要执行此类任务。但正如谢尔盖强调的那样,应该避免这种情况。

如果你也需要,你尝试的方法是最糟糕的,永远不会奏效。在服务器上启动资源管理器进程将无法获得任何结果。主要问题是你想对开放的份额做什么。假设您启动了资源管理器实例,您只能在服务器上获得一个隐藏的资源管理器,并且您无法使用它。

所以我假设您要访问这些文件它。



嗯,有两种情况:

1)这些域位于同一个林中,或者位于必要的信任边界内。这样,您可以使用远程凭据创建线程。您的应用程序将在应用程序池凭据下运行,但该线程在所需的线程下运行,因此您可以访问远程资源。如果这适用于您,请从此处开始: C#中的完整模拟演示。 NET [ ^ ]。

两个注意事项:

- 如果需要,您可以更改整个工作线程的安全上下文,但是您可能会遇到本地资源的问题

- 默认情况下,asp.net可以模拟已登录或指定的用户,如果这适用于您从这里开始: http://msdn.microsoft.com/en-us/library/aa292118(v = vs.71).aspx [ ^ ]



2)远程域与本地域没有任何信任关系(或者您需要一次需要多个远程共享),您可以使用WNetAddConnection2 API函数打开远程网络连接。你需要p / invoke,但在这里你可以看到如何实现和使用它: http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share [ ^ ]



请注意,这些方法只允许您访问文件(前提是您拥有权利也),但你必须处理文件。
There are situations where such task is needed. But as Sergey highlighted, it should be avoided.
Still if you need too, the method you tried is far the worst, and will never work. You will get nothing from starting an explorer process on the server. The main question is what do you want to do with the opened share. Supposing, that you start the explorer instance, you would only get a hidden explorer on the server, and you can''t do much with it.
So I assume, you want to access the files in it.

Well, there are two scenarios:
1) The domains are in the same forest, or inside necessary trust boundaries. This way you can create a thread with the remote credentials. Your application will run under the application pool credentials, but that thread runs under the desired one so you can access remote resources. If this applies to you, start here: A Complete Impersonation Demo in C#.NET[^].
Two notes:
- you could change the security context of whole worker thread if needed, but you might encounter problems with the local resources
- asp.net can impersonate logged-in or specified user by default, if this applies to you start here: http://msdn.microsoft.com/en-us/library/aa292118(v=vs.71).aspx[^]

2) The remote domain is not in any trust relation with the local one (or you need many remote shares at once), you can open remote network connections with WNetAddConnection2 API function. You need p/invoke, but here you can see how to implement and use it: http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share[^]

Be aware, that these methods give you only the possibility to access files (provided you have the rights also), but you will have to deal with the files.


这篇关于打开一个Windows共享文件夹&amp;多个域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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