c# - 如何使用 C# 保存网络凭据
问题描述
需要为我的工作执行此代码。
string filePath = "\\\\192.168.7.202\\Sample\sample.log"
var accessControlList = Directory.GetAccessControl( filePath );
不幸的是,如果没有网络凭据,此代码将无法工作。所以必须在我使用的计算机上添加 192.168.7.202 的网络凭据。
谁能知道如何通过 C# 脚本添加 Netowrk 凭据及其 IP 地址、用户名和密码?
这是我的代码,但不起作用......
string ipAddress = "192.168.7.202";
string username = "Administrator";
string password = "abcd";
NetworkCredential netCredential = new NetworkCredential(username, password, ipAddress);
CredentialCache theNetCache = new CredentialCache();
theNetCache.Add("192.168.7.202", 3389, "Basic", netCredential);
string filePath = "\\\\192.168.7.202\\Sample\sample.log"
var accessControlList = Directory.GetAccessControl( filePath ); **//Error occur without Credential**
可能不必永久保留凭据,至少 Directory.GetAccessControl(filePath) 需要它。
谁能给我一个解决方案...?
仅供参考,我自己将 192.168.7.202 的凭据添加到红色框中,使 Directory.GetAccessControl 运行良好。希望我可以在 C# 脚本上做到这一点..
解决方案
推荐阅读
- c# - Unity ML 代理程序包管理器未导入执行器脚本
- json - 如何将 Json 字符串转换为 HashMap?
- spring - H2 db 在 spring 4 中自动生成表
- java - 移除或替换 findbugs、PMD、checkStyle 插件 android
- .htaccess - htaccess 从子域重定向到域自定义 404 页面
- export - AG-grid 导出到具有组数的 excel
- android - recycleView 中未显示 Firebase 的图像
- jenkins - Jenkins Helm 备份因 WebIdentityErr 而失败
- fabricjs - 禁用 ClipPath 外的对象选择
- php - 我可以在函数中使用参数并在下面的if语句中回显它吗