如何要求访问.NET胖客户端应用程序中的Windows共享? [英] How can I demand access to a Windows share in a .NET thick-client app?

查看:94
本文介绍了如何要求访问.NET胖客户端应用程序中的Windows共享?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个胖客户端,该胖客户端需要访问可能未登录客户端的共享上的资源.客户端可能在Windows域上,也可能是没有域的混合环境,因此用户必须本地登录服务器.过去,一种解决方法是在用户桌面上创建共享的快捷方式,该快捷方式将打开Windows资源管理器,该资源管理器将打开一个密码提示,以授予或拒绝对该共享的访问.如何在不依赖Windows资源管理器的情况下使用户登录共享?我可以让我的应用程序执行Windows资源管理器做什么以要求访问共享?

We have a thick-client that needs to access resources on a share where a client may not be logged on. The client might be on a Windows domain or it could be a mixed environment without a domain, so the user would have to log on to the server locally. In the past, one work around was to create a shortcut on the user's desktop to the share, which opens Windows Explorer, which opens a password prompt that grants or denies access to the share. How can I get the user to signon to the share without relying on Windows Explorer? What does Windows Explorer do that I can have my app do to demand access to the share?

我已阅读从C#网站中的网络共享访问文件应用,但我正在WinForms应用中执行此操作,并希望它具有交互性.我还阅读了如何提示输入密码 ,但是该代码只是提示用户输入字符串,而不是调用要求并授予共享访问权限的UI.我宁愿我的应用程序不知道用户的密码,也不会触发操作系统要求访问网络资源.

I have read Access files from network share in c# web app, but I am doing this in a WinForms app and want it to be interactive. I have also read How to prompt for a Password, but that code just prompts for strings from the user rather than invoking the UI that demands and grants access to the share. I would rather not have my app know the user's password as much as trigger the OS to demand access for the network resource.

推荐答案

您可以查看Win32 API CredUIPromptForCredentials(如果您在Vista/Win2k8上运行,则可以查看CredUIPromptForWindowsCredential,请检查winver以确定对哪个调用制作.)

You could take a look at the Win32 API CredUIPromptForCredentials ( or CredUIPromptForWindowsCredential if you're running on Vista/Win2k8, you should check the winver to decide which call to make).

此方法实际上会调用常规凭据提示,但您会获得凭据(我知道这很糟糕).

This method actually invokes the regular credentials prompt but you get the credentials (awful, I know).

PInvoke.Net具有示例代码显示了如何调用此代码C#中的函数(在PInvoke示例中,如果您在保存中指定为false,则必须传递CREDUI_FLAGS.DO_NOT_PERSIST来获取标志.很奇怪,我知道).

PInvoke.Net has sample code showing how to call this function from C# (in the PInvoke sample you have to pass CREDUI_FLAGS.DO_NOT_PERSIST for flags if you've specified false in save. Weird, I know).

有关的详细信息(以及不受管理的示例)基思·布朗(Keith Brown)Wikibook 关于安全性

一旦获得凭据(使用安全字符串),您就可以模拟用户访问资源(使用登录用户).

Once you get the credentials (in a secure string) you can then impersonate the user to get to the resource (using logonuser).

这很丑.我了解您希望Windows显示标准提示对话框,并且您不希望了解凭据.

And it's ugly. I understand you want Windows to show the standard prompt dialog and you don't want to know about the credentials.

我想知道像使用System.Diagnostics.Process在远程UNC上启动隐藏的explorer.exe这样的丑陋的技巧是否可以解决问题.您必须找到一种方法来等待用户输入凭据,然后终止生成的资源管理器进程.

I'm wondering if a ugly hack like using System.Diagnostics.Process to launch a hidden explorer.exe on the remote UNC would not do the trick. You'd have to find a way to wait for the user to have entered the credentials and then kill the spawned explorer process.

这篇关于如何要求访问.NET胖客户端应用程序中的Windows共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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