2015-04-21 12 views
9

Sto utilizzando System.DirectoryServices.DirectoryEntry per creare l'utente di Active Directory e tutto funziona bene tranne per alcune proprietà specifiche di Desktop remoto.Modifica le proprietà del Terminal Server utente di Active Directory con C#

Esempio:

newUser.Properties["msTSConnectClientDrives"].Value = false; 
newUser.Properties["msTSConnectPrinterDrives"].Value = false; 
newUser.Properties["msTSDefaultToMainPrinter"].Value = false; 

Questo non genera alcuna eccezione, quindi credo che le proprietà sono trovati nell'oggetto, ma non hanno alcun effetto. Quando vado nella finestra delle proprietà di quell'utente, nella scheda "Ambiente", queste 3 caselle di controllo sono ancora controllate.

Mi manca qualcosa di particolare per queste proprietà?

Grazie per il vostro aiuto.

EDIT:

dispiace sono stato molto occupato, ecco un esempio di codice:

private string CreateNewADAccount(string accountName, string accountPassword) 
    { 
     try 
     { 
      PrincipalContext context = new PrincipalContext(ContextType.Domain, "SV-LITE", @"LITE\xxxxxxxx", "yyyyyyyy"); 

      UserPrincipal newUser = new UserPrincipal(context); 
      newUser.SamAccountName = accountName; 
      newUser.UserPrincipalName = accountName; 
      newUser.Name = "LiteUser2015 - " + accountName; 
      newUser.DisplayName = "LiteUser2015 - " + accountName; 
      newUser.SetPassword(accountPassword); 
      newUser.PasswordNeverExpires = true; 
      newUser.UserCannotChangePassword = true; 

      newUser.Save(); 

      // Set advanced properties 
      if (newUser.GetUnderlyingObjectType() == typeof(DirectoryEntry)) 
      { 
       DirectoryEntry entry = (DirectoryEntry)newUser.GetUnderlyingObject(); 

       entry.Properties["msTSConnectClientDrives"].Value = false; 
       entry.Properties["msTSConnectPrinterDrives"].Value = false; 
       entry.Properties["msTSDefaultToMainPrinter"].Value = false; 
       entry.Properties["msTSInitialProgram"].Value = "test"; 

       entry.CommitChanges(); 
      } 

      return newUser.Guid.ToString(); 

     } 
     catch (Exception e) 
     { 
      MessageBox.Show("Failed to create PrincipalContext. Exception: " + e); 
     } 

     return null; 
    } 

risposta

0

Potrebbe avere qualcosa a che fare con la versione del sistema operativo server che si sta utilizzando. Ho trovato questa risposta su another site che parla di Windows 2000 e 2003. Dovrebbe funzionare per Windows2008 e soprattutto:

Per 2000/2003 è necessario accedervi utilizzando l'estensione ADSI Terminal Services . Il riferimento di ciò è qui:

http://msdn.microsoft.com/en-us/library/aa380823(VS.85).aspx

+0

Sono su Windows 2008 – Karnalta

+0

OK (probabilmente avrei dovuto chiedere in un commento). Comunque, ecco l'articolo di MSDN che afferma che Windows 2008 e versioni successive lo supportano: https://msdn.microsoft.com/en-us/library/cc220553.aspx –