如何在VB.NET代码中包含网络凭据。 [英] How to include network credentials in VB.NET code.
问题描述
我有一个小程序试图将文件保存在网络共享驱动器中。
如果我使用用户名密码自行登录该服务器,它将成功保存。服务器加入域和我的域。我访问该服务器上的文件时不需要输入域名。我只是使用用户名和密码。
如果我重新启动电脑并尝试再次运行程序,它将显示错误,因为凭证未存储在我的电脑中。
i想在我的代码中包含用户名和密码。
我怎么做。
我想在论坛中显示我的截图。
我尝试过的事情:
xlWorkBook.SaveAs(文件名:=\\10.51.199.49\log\CHANN SOFTWARE \test.xlsx,FileFormat:= 51,ReadOnlyRecommended:= False,CreateBackup:= False )
I have a small program which tries to save a file in network shared drive.
It will successfully save , if I login to that server once by myself using username password. The server is joined to domain as well as mine. I don't need to type domain name while i access the files on that server. I just use username and password.
If I restart my pc and try to run the program again, it will show error as the credentials haven't stored in my PC.
i want to include the username and password in my code .
how I do.?
I want to show screenshots in the forum how I do.?
What I have tried:
xlWorkBook.SaveAs(Filename:="\\10.51.199.49\log\CHANN SOFTWARE\test.xlsx", FileFormat:=51, ReadOnlyRecommended:=False, CreateBackup:=False)
推荐答案
您需要的功能称为 模拟 。
你可以在StackOverflow等上找到几个例子,还有一篇关于CP的文章: [ ^ ]。
The feature you need is called Impersonation.
You can find several examples on StackOverflow etc., and also an article here on CP: A small C# Class for impersonating a User[^].
这篇关于如何在VB.NET代码中包含网络凭据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!