Winforms App本地服务器登录问题 [英] Winforms App local server login issue

查看:96
本文介绍了Winforms App本地服务器登录问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个应用程序,可以将文件复制到我们网络上的另一台计算机上.这是我们用于日常备份的简单XP计算机.但是,您需要先登录计算机,然后才能执行任何操作.因此,除非我先在备用PC上使用资源管理器打开一个共享文件夹并输入我的登录详细信息,否则该应用程序将无法运行.登录备份PC后,该应用程序运行正常.但是,如果我不首先登录,该应用程序将引发异常,表明它无法访问目标文件夹.

现在我似乎找不到找到将网络凭据添加到复制过程的方法,因此我认为我需要以某种方式将其提供给应用程序?

我想避免设置FTP服务器,因为我觉得这对于相对简单的事情来说是不必要的.


因此,在复制文件之前,我需要我的应用程序登录"到备份PC.

任何帮助将不胜感激.
谢谢

Hi
I have a app that copies files to a different machine on our network. It''s a simple XP machine we use for daily backups. However, you need to login to the machine before you can do anything. So the app doesn''t work unless I first open a shared folder with Explorer on the backup PC and enter my logon details. Once I''ve logged onto the Backup PC, the app runs fine. But if I don''t logon first, the app throws an exception stating that it can''t access the destination folder.

Now I can''t seem to find a way to add network credentials to the copy process, so I figured I need to give it to the app somehow??

I want to avoid having to setup a FTP server as I feel it''s unnecessary for something that should be relatively simple.


So I need my app to "login" to the Backup PC before it tries to copy the files.

Any help would be appreciated.
Thanks

推荐答案

您的应用程序如何运行?是在Windows Scheduler下还是什么?

假设它在调度程序下运行,此时您可以定义一组凭据.这将形成应用程序将在其下运行的安全上下文.

现在检查您的备份计算机.转到管理我的电脑",然后在组\用户"下进行检查.在运行程序时使用的安全上下文(例如MYDOMAIN \ AUser)需要被授予访问权限,以便它对计算机具有权限.

如果一切正常,则无需通过资源管理器登录". Windows将为您协商这一点,并确定您的程序对该计算机具有权限并允许访问.

不要忘记使用完整的UNC,而不是使用特定于用户配置文件的共享驱动器名称.因此,不要使用

F:\ BackupFolder \

使用类似
的东西
\\ BackupMachineName \ c
How is your application being run? Is it under windows scheduler or something?

Say it''s running under scheduler, you can define a set of credentials at this point. This will form the security context that the application will run under.

Now check your backup machine. Go to ''Manage my Computer'' and check under groups \ users. The security context you''re using when running your program (e.g MYDOMAIN\AUser) needs to be granted access so that it has rights to the machine.

If all that is OK, you won''t need ''log on'' via explorer. Windows will negotiate this for you and determine that your program has rights to the machine and allow access.

Don''t forget to use full UNC rather than shared drive names which are specific to user profiles. So instead of using

F:\BackupFolder\

Use something like

\\BackupMachineName\c


\ BackupFolder \


您可以尝试将线程设置为当前Windows主体,让这种情况恰好在程序开始时发生

您将需要使用System.Security.Principal; 使用System.Threading;

\BackupFolder\


You can try setting the thread to the current windows principal, have this happen right at the start of your program

You''ll need using System.Security.Principal; and using System.Threading;

WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);

Thread.CurrentPrincipal = principal;



如果您是在域中运行此程序,则应该无问题地访问另一台计算机.

您能确认吗?



If you''re running this within a domain, you should be able to access the other machine no probs.

Can you confirm this?


这是一个普通的winforms应用程序,只需单击一下按钮,即可将文件简单地复制到备份PC上的共享文件夹中.

无论我使用映射驱动器还是完整的UNC,我都有相同的问题.

如果要编写文件浏览器应用程序(例如Total Commander或用于资源管理器的简单替换应用程序),那么在连接到另一台PC上的共享文件夹之前,如何验证它?

我忘了在第一篇文章中补充说我正在使用C#和.NET 3.5 SP1
It''s a normal winforms app that will do a simple copy of files to the shared folder on the backup PC on a button click.

I have the same problem whether I use a mapped drive or full UNC.

If you were to write a file browser app (Something like Total Commander, or a simple replacement app for explorer), how would you have it authenticate before connecting to a shared folder on another PC?

I forgot to add to the first post that I''m working with C# and .NET 3.5 SP1


这篇关于Winforms App本地服务器登录问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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