internal string GetUserName()
 {
     if (this.Account == ServiceAccount.NetworkService)
     {
         return(@"NT AUTHORITY\NetworkService");
     }
     else if (this.Account == ServiceAccount.LocalSystem)
     {
         return("LocalSystem");
     }
     else if (this.Account == ServiceAccount.LocalService)
     {
         return(@"NT AUTHORITY\LocalService");
     }
     else
     {
         if (!UserName.IsNullOrWhiteSpace())
         {
             return(ChoEnvironment.ToDomainUserName(UserName));
         }
         else
         {
             ChoConsole.Write("Enter UserId: ");
             return(ChoEnvironment.ToDomainUserName(ChoConsole.ReadLine()));
         }
     }
 }
Пример #2
0
 public static void SetUACShield(this Button @this, bool showShield = true)
 {
     if (!ChoWindowsIdentity.IsAdministrator() && ChoEnvironment.AtLeastVista())
     {
         //Note: make sure the button FlatStyle = FlatStyle.System
         @this.FlatStyle = FlatStyle.System;
         // BCM_SETSHIELD = 0x0000160C
         ChoUser32.SendMessage(@this.Handle, ChoUser32.BCM_SETSHIELD, 0, showShield ? 0xFFFFFFFF : 0);
     }
 }
Пример #3
0
        public static void SetUACShield(this ToolStripMenuItem @this, bool showShield = true)
        {
            if (!ChoWindowsIdentity.IsAdministrator() && ChoEnvironment.AtLeastVista())
            {
                //SHSTOCKICONINFO iconResult = new SHSTOCKICONINFO();
                //iconResult.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(iconResult);

                //ChoShell32.SHGetStockIconInfo(
                //    SHSTOCKICONID.SIID_SHIELD,
                //    SHGSI.SHGSI_ICON | SHGSI.SHGSI_SMALLICON,
                //    ref iconResult);

                //@this.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                //@this.Image = Bitmap.FromHicon(iconResult.hIcon);
                @this.ImageScaling = ToolStripItemImageScaling.None;
                @this.Image        = ChoEnvironment.GetUACShieldImage();
            }
        }
Пример #4
0
        private void QueueProcessingThreadCallback(object state)
        {
            IChoQueuedMsgServiceObject <T> msgQObject = null;

            while (true)
            {
                try
                {
                    msgQObject = _queue.Dequeue() as IChoQueuedMsgServiceObject <T>;
                    if (msgQObject == null)
                    {
                        continue;
                    }
                    if (msgQObject.IsQuitServiceMsg)
                    {
                        break;
                    }

                    QueueMessageHandler(msgQObject);
                }
                catch (ChoFatalApplicationException fex)
                {
                    ChoEnvironment.Exit(-1, fex);
                }
                catch (Exception ex)
                {
                    ChoApplication.WriteToEventLog(ex.ToString(), EventLogEntryType.Error);
                    if (msgQObject != null)
                    {
                        ChoApplication.WriteToEventLog(ChoObject.ToString(msgQObject));
                    }
                    //ChoProfile.DefaultContext.Append(ex);
                    //if (!EventLog.SourceExists(ChoAssembly.GetEntryAssembly().GetName().Name))
                    //    EventLog.CreateEventSource(ChoAssembly.GetEntryAssembly().GetName().Name, "Application");
                    //EventLog.WriteEntry(ChoAssembly.GetEntryAssembly().GetName().Name, ChoApplicationException.ToString(ex));
                    //throw;
                }
            }
        }
Пример #5
0
        private void QueueMessageHandler(IChoQueuedMsgServiceObject <ChoExecutionServiceData> msgObject)
        {
            if (msgObject == null ||
                !ChoGuard.IsArgumentNotNullOrEmpty(msgObject.State)
                )
            {
                return;
            }

            ChoAsyncResult asyncResult = msgObject.State.Result as ChoAsyncResult;

            try
            {
                object retValue = msgObject.State.Func.Run(msgObject.State.Parameters, msgObject.State.Timeout, msgObject.State.MaxNoOfRetry, msgObject.State.SleepBetweenRetry);
                asyncResult.SetAsSuccess(retValue, true);
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                ChoTrace.Error("Thread aborted." + msgObject.State.ToString());
                asyncResult.SetAsAborted(true);
            }
            catch (ChoFatalApplicationException fex)
            {
                ChoTrace.Error(fex);
                ChoTrace.Error(msgObject.State.ToString());
                asyncResult.SetAsFailed(fex, true);
                ChoEnvironment.Exit(-1, fex);
            }
            catch (Exception ex)
            {
                ChoTrace.Error(ex);
                ChoTrace.Error(msgObject.State.ToString());
                asyncResult.SetAsFailed(ex, true);
            }
        }