/// <include file='doc\ServiceProcessInstaller.uex' path='docs/doc[@for="ServiceProcessInstaller.Rollback"]/*' />
 /// <devdoc>
 ///    <para>Rolls back service application information that was
 ///       written to the registry by the installation procedure. This method is meant to be used by installation tools, which process
 ///       the appropriate methods automatically.</para>
 /// </devdoc>
 public override void Rollback(IDictionary savedState)
 {
     try
     {
         // remove the SeServiceLogonRight from the account if we added it.
         if (((ServiceAccount)savedState["Account"]) == ServiceAccount.User && !((bool)savedState["hadServiceLogonRight"]))
         {
             string username     = (string)savedState["Username"];
             IntPtr policyHandle = OpenSecurityPolicy();
             try
             {
                 byte[] sid = GetAccountSid(username);
                 RemoveAccountRight(policyHandle, sid, "SeServiceLogonRight");
             }
             finally
             {
                 SafeNativeMethods.LsaClose(policyHandle);
             }
         }
     }
     finally
     {
         base.Rollback(savedState);
     }
 }
        /// <include file='doc\ServiceProcessInstaller.uex' path='docs/doc[@for="ServiceProcessInstaller.Install"]/*' />
        /// <devdoc>
        ///    <para>Writes service application information to the registry.
        ///       This method is meant to be used by installation tools, which call the appropriate methods automatically.</para>
        /// </devdoc>
        public override void Install(IDictionary stateSaver)
        {
            try
            {
                ServiceInstaller.CheckEnvironment();
                try
                {
                    if (!haveLoginInfo)
                    {
                        try
                        {
                            GetLoginInfo();  // if the user hits "cancel" this will throw
                        }
                        catch
                        {
                            stateSaver["hadServiceLogonRight"] = true;  // this prevents rollback from trying to remove logonRights for the user
                            throw;
                        }
                    }
                }
                finally
                {
                    // save out that information (but not the password)
                    stateSaver["Account"] = Account;
                    if (Account == ServiceAccount.User)
                    {
                        stateSaver["Username"] = Username;
                    }
                }

                if (Account == ServiceAccount.User)
                {
                    // grant the right to run as a service to the given username. If we don't do this,
                    // the service will be unable to start under that account.
                    IntPtr policyHandle         = OpenSecurityPolicy();
                    bool   hasServiceLogonRight = true; // we use 'true' here for the default because later in rollback we do
                                                        //   "if not hasServiceLogon revoke logon priviledge"
                    try
                    {
                        byte[] sid = GetAccountSid(Username);
                        hasServiceLogonRight = AccountHasRight(policyHandle, sid, "SeServiceLogonRight");
                        if (!hasServiceLogonRight)
                        {
                            GrantAccountRight(policyHandle, sid, "SeServiceLogonRight");
                        }
                    }
                    finally
                    {
                        stateSaver["hadServiceLogonRight"] = hasServiceLogonRight;
                        SafeNativeMethods.LsaClose(policyHandle);
                    }
                }
            }
            finally
            {
                // now install all the contained services. They will use the Username and Password properties to do
                // their installation.
                base.Install(stateSaver);
            }
        }
예제 #3
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);
     }
 }
예제 #4
0
 /// <summary>Rolls back service application information written to the registry by the installation procedure. This method is meant to be used by installation tools, which process the appropriate methods automatically.</summary>
 /// <param name="savedState">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="savedState" /> is null.-or- The <paramref name="savedState" /> is corrupted or non-existent. </exception>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
 /// </PermissionSet>
 public override void Rollback(IDictionary savedState)
 {
     try
     {
         if ((ServiceAccount)savedState["Account"] == ServiceAccount.User && !(bool)savedState["hadServiceLogonRight"])
         {
             string accountName = (string)savedState["Username"];
             IntPtr intPtr      = this.OpenSecurityPolicy();
             try
             {
                 byte[] accountSid = this.GetAccountSid(accountName);
                 ServiceProcessInstaller.RemoveAccountRight(intPtr, accountSid, "SeServiceLogonRight");
             }
             finally
             {
                 SafeNativeMethods.LsaClose(intPtr);
             }
         }
     }
     finally
     {
         base.Rollback(savedState);
     }
 }
 public override void Rollback(IDictionary savedState)
 {
     try
     {
         if ((((ServiceAccount)savedState["Account"]) == ServiceAccount.User) && !((bool)savedState["hadServiceLogonRight"]))
         {
             string accountName  = (string)savedState["Username"];
             IntPtr policyHandle = this.OpenSecurityPolicy();
             try
             {
                 byte[] accountSid = this.GetAccountSid(accountName);
                 RemoveAccountRight(policyHandle, accountSid, "SeServiceLogonRight");
             }
             finally
             {
                 SafeNativeMethods.LsaClose(policyHandle);
             }
         }
     }
     finally
     {
         base.Rollback(savedState);
     }
 }