如何將.NET代碼映射到帳戶SVNdatamgmt的UNC路徑的Z:驅動器?可以從命令行映射UNC路徑,但不能從.NET映射控制檯應用程序
我試圖將本地驅動器映射到.NET控制檯應用程序內的網絡UNC路徑。該代碼似乎可以從服務帳戶(#2和#3)的命令行以及我的憑據(#4)工作。但是,當使用.NET源代碼從控制檯應用程序運行時,服務帳戶不起作用(#5),但是我的憑據可以工作(#6)。
昨晚,我注意到我有一個錯誤(#1)。等待30分鐘後,它就起作用了。所以你可以忽略#1。我想我會提到它,以防萬一它提供了有關正在發生的事情的線索。
控制檯應用程序以Windows Server 2008框的管理員身份運行。 SVCdatamgmt和macgyver都是這臺機器上的管理員。這些命令也在同一臺機器上運行。
============================================== ==========================
1)這不,昨晚工作:
C:>net use z: \\uwhc-sas2\SASHIMC /USER:SVCdatamgmt thepassword
System error 1909 has occurred.
The referenced account is currently locked out and may not be logged on to.
========================================== ==============================
2.)等待30分鐘,然後t他的工作(不域):
C:>net use z: \\uwhc-sas2\SASHIMC /USER:SVCdatamgmt thepassword
The command completed successfully.
========================== ==============================================
3。)這也適用(與結構域):
C:>net use z: \\uwhc-sas2\SASHIMC /USER:UWHIS\SVCdatamgmt thepassword
The command completed successfully.
============================================== ==========================
4)這也適用於我的憑據:
C:>net use z: \\uwhc-sas2\SASHIMC /USER:macgyver thepassword
The command completed successfully.
=========================================== =============================
5.).NET代碼映射d裏沃。 SVCdatamgmt憑據不起作用。
public static void MapNetworkDriveToUNC()
{
var command = @"net use " + mapDrive + " " + uncPath + " " + uncUser + " " + uncPass;
ExecuteCommand(command, 10000);
}
public static void UnmapNetworkDriveToUNC()
{
var command = "net use " + mapDrive + " /delete";
ExecuteCommand(command, 5000);
}
========================================= ===============================
6.)映射驅動器的.NET代碼。我的工作憑證(百戰天龍)
- 相同的代碼#5 -
========================= ===============================================
FYI:運行上面的每個命令之前,我已經使用此代碼斷開(取消映射)驅動器...
C:\>net use z: /delete
z: was deleted successfully.
我實現了這個:NET USE Z:\\路徑\路徑\路徑/ USER:the_user the_password ......並刪除它,我這樣做:淨使用Z:/刪除 – MacGyver 2013-12-09 17:09:55