2011-06-13 2 views
2

저는 Active Directory 계정을 관리하는 도구에 사용될 .NET 클래스에 대해 작업하고 있습니다. 각 계정은 우리가 작업하고있는 계정의 유형에 따라 몇 가지 다른 서버에 위치 할 수있는 네트워크 홈 디렉토리를 갖습니다.원격 폴더를 공유하는 방법은 무엇입니까?

폴더를 만들고 삭제할 수 있지만 폴더를 공유하는 데 문제가 있습니다. I found some code here 내가 원하는 것 같지만 제대로 작동하지 않습니다. 내가 얻는 반환 값은 2이지만, 그것이 무엇을 나타내는 지 모르겠습니다.

테스트 응용 프로그램을 직접 실행 중이므로 공유하려는 폴더와 각 상위 폴더를 완전히 제어 할 수 있으므로 파일 사용 권한 문제가 아닙니다.

다음은 코드 내 (수정) 버전입니다 : 내가 다른 outParams를 출력하려고했습니다

char[] delim = { '\\' }; 
// folderPath is a string (UNC path) 
string[] drivePath = folderPath.Split(delim); 

// Create a ManagementClass object 
ManagementClass managementClass = new ManagementClass("Win32_Share"); 

// Create ManagementBaseObjects for in and out parameters 
ManagementBaseObject inParams = 
    managementClass.GetMethodParameters("Create"); 
ManagementBaseObject outParams; 

// Set the input parameters 
inParams["Description"] = ""; 
inParams["Name"] = drivePath[3]; 
inParams["Path"] = folderPath; 
inParams["Type"] = 0x0; // Disk Drive 

// Invoke the method on the ManagementClass object 
outParams = managementClass.InvokeMethod("Create", inParams, null); 

하지만 ReturnValue를 내가 얻을 수있는 모든 것 같습니다.

더 좋은 원격 폴더를 공유하는 다른 방법이 있습니까?

답변

1

나중에 다른 사람이이 사실을 발견 한 경우를 대비하여 스스로 답할 것입니다.

내가 PsExec를하고 NET SHARE 사용하는 매우 unsexy 답을가는 결국 : 우리의 환경에서 프로그램이 이미있는 폴더에 대한 모든 권한이있는 사용자에서 실행됩니다

// Retrieve drive path from AD 
char[] delim = { '\\' }; 
string[] drivePath = userAD.HomeDirectory.Split(delim); 

// Configure startup properties of process 
ProcessStartInfo startInfo = new ProcessStartInfo(); 
startInfo.CreateNoWindow = true; 
startInfo.FileName = "C:\\Windows\\System32\\psexec.exe"; 

// Build arguments for folder on alpha or student 
startInfo.Arguments = "\\\\" + serverName + " -s net share " + shareName + "=" folderPath + "$ /GRANT:\"authenticated users\",full"; 

Process process = new Process(); 

process.StartInfo = startInfo; 
process.Start(); 
process.WaitForExit(); 

주 공유. 특권이없는 사용자와 유사하게하려면 startInfo.Arguments에 이름과 암호를 지정해야합니다.

관련 문제