private Interfaces.ICommandResult AddAccount(string windowsServiceName) { try { WindowsServiceLogonUtil.ChangeWindowsServiceLogon(windowsServiceName, m_account, m_password); WindowsGroupUtil.CreateGroup(Microsoft.TeamFoundation.Migration.Toolkit.Constants.TfsIntegrationExecWorkProcessGroupName, Microsoft.TeamFoundation.Migration.Toolkit.Constants.TfsIntegrationExecWorkProcessGroupComment); WindowsGroupUtil.AddMemberToGroup( Microsoft.TeamFoundation.Migration.Toolkit.Constants.TfsIntegrationExecWorkProcessGroupName, m_account); var rslt = DBRoleUtil.CreateWindowsLogin(m_account); if (rslt == DBRoleUtil.AccountsResult.Fail) { return(new ServiceAccountRslt(ResourceStrings.ErrorFailToAddAccountToTFSIPEXECRole, this)); } else { rslt = DBRoleUtil.CreateTFSIPEXECRole(); } if (rslt == DBRoleUtil.AccountsResult.Fail) { return(new ServiceAccountRslt(ResourceStrings.ErrorFailToAddAccountToTFSIPEXECRole, this)); } else { rslt = DBRoleUtil.AddAccountToTFSIPEXECRole(m_account); } if (rslt == DBRoleUtil.AccountsResult.Fail) { return(new ServiceAccountRslt(ResourceStrings.ErrorFailToAddAccountToTFSIPEXECRole, this)); } else { return(new ServiceAccountRslt(this)); } } catch (Exception e) { return(new ServiceAccountRslt(e.ToString(), this)); } }
private AccountValidationResult GrantPermissions(ref AccountValidationResult result) { string account = WindowsIdentity.GetCurrent().Name; if ((result & AccountValidationResult.NotInTFSIPEXECRole) != 0) { try { var rslt = DBRoleUtil.CreateWindowsLogin(account); if (rslt != DBRoleUtil.AccountsResult.Fail) { rslt = DBRoleUtil.CreateTFSIPEXECRole(); } if (rslt != DBRoleUtil.AccountsResult.Fail) { rslt = DBRoleUtil.AddAccountToTFSIPEXECRole(account); } if (rslt != DBRoleUtil.AccountsResult.Fail) { result &= ~AccountValidationResult.NotInTFSIPEXECRole; } } catch { } } if ((result & AccountValidationResult.NotInTFSIPEXECWorkProcessGroup) != 0) { try { WindowsGroupUtil.CreateGroup(Constants.TfsIntegrationExecWorkProcessGroupName, Constants.TfsIntegrationExecWorkProcessGroupComment); WindowsGroupUtil.AddMemberToGroup(Constants.TfsIntegrationExecWorkProcessGroupName, account); result &= ~AccountValidationResult.NotInTFSIPEXECWorkProcessGroup; } catch { } } return(result); }