Exemplo n.º 1
0
 /// <summary>Writes service application information to the registry. This method is meant to be used by installation tools, which call the appropriate methods automatically.</summary>
 /// <param name="stateSaver">An <see cref="T:System.Collections.IDictionary" /> that contains the context information associated with the installation. </param>
 /// <exception cref="T:System.ArgumentException">The <paramref name="stateSaver" /> is null. </exception>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
 ///   <IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
 /// </PermissionSet>
 public override void Install(IDictionary stateSaver)
 {
     try
     {
         ServiceInstaller.CheckEnvironment();
         try
         {
             if (!this.haveLoginInfo)
             {
                 try
                 {
                     this.GetLoginInfo();
                 }
                 catch
                 {
                     stateSaver["hadServiceLogonRight"] = true;
                     throw;
                 }
             }
         }
         finally
         {
             stateSaver["Account"] = this.Account;
             if (this.Account == ServiceAccount.User)
             {
                 stateSaver["Username"] = this.Username;
             }
         }
         if (this.Account == ServiceAccount.User)
         {
             IntPtr intPtr = this.OpenSecurityPolicy();
             bool   flag   = true;
             try
             {
                 byte[] accountSid = this.GetAccountSid(this.Username);
                 flag = ServiceProcessInstaller.AccountHasRight(intPtr, accountSid, "SeServiceLogonRight");
                 if (!flag)
                 {
                     ServiceProcessInstaller.GrantAccountRight(intPtr, accountSid, "SeServiceLogonRight");
                 }
             }
             finally
             {
                 stateSaver["hadServiceLogonRight"] = flag;
                 SafeNativeMethods.LsaClose(intPtr);
             }
         }
     }
     finally
     {
         base.Install(stateSaver);
     }
 }