Member 12643851 Ответов: 1

Ошибка отказа в доступе в приложении windows


i am developing a windows application that will automate a third party apllication using c#.....
but the problem is that ..my application is work only for 2 or 3 days after that it send error access denied and error in this section only..
i checked process is run in task manager but error remains same...

try
           {
               Process myproc= Process.GetProcessesByName("proc").FirstOrDefault();
               if (myproc!= null)
               {
                   var ffCondition = new PropertyCondition(AutomationElement.ProcessIdProperty, nestprocess.Id);
                   var ffWindows = AutomationElement.RootElement.FindAll(TreeScope.Children, ffCondition);
                   var soWindow = ffWindows.Cast<AutomationElement>().FirstOrDefault(w => w.Current.Name.Contains("wellcome to my third party application title baar "));
                   if (soWindow != null)
                   {

                       var soWindowPattern = soWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
                       if (soWindowPattern != null)
                       {
                           // Restore  third party window  application(activating it).
                           soWindowPattern.SetWindowVisualState(WindowVisualState.Normal);

                           // Pause to observe effect. Do not set a breakpoint here.
                           Thread.Sleep(100);

                           // Close window.
                           //soWindowPattern.Close();
                           SendKeys.SendWait("{f1}");
                           var soWindow1 = ffWindows.Cast<AutomationElement>().FirstOrDefault(w => w.Current.Name.Contains("entery for text boxes"));
                           //SendKeys.SendWait("{TAB 7}");

.....................
отображение ошибки в этом разделе Доступ запрещен ..


soWindowPattern.SetWindowVisualState(WindowVisualState.Normal);

и активируется стороннее окно ....


ошибка в деталях есть

System.ComponentModel.Win32Exception was unhandled
  HResult=-2147467259
  Message=Access is denied
  Source=mscorlib
  ErrorCode=-2147467259
  NativeErrorCode=5
  StackTrace:
       at MS.Internal.Automation.Misc.ThrowWin32ExceptionsIfError(Int32 errorCode)
       at MS.Internal.Automation.Misc.SetWindowPlacement(HWND hwnd, WINDOWPLACEMENT& wp)
       at MS.Internal.Automation.HwndProxyElementProvider.System.Windows.Automation.Provider.IWindowProvider.SetVisualState(WindowVisualState state)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
       at MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)
       at System.Windows.Automation.WindowPattern.SetWindowVisualState(WindowVisualState state)
       at CLICKTRADE_..................
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at CLICKTRADE_FOR_NSE.Program.Main() in  Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 


Что я уже пробовал:

не пробовал потому что мое приложение работает как ошибка strainge оно работает только 2 или 3 дня и после этого доступ к дисплею запрещен моему стороннему приложению

1 Ответов

Рейтинг:
1

Richard MacCutchan

Код ошибки-0x80004005, см. https://support.microsoft.com/en-gb/help/914232/you-may-receive-error-code-0x80004005-or-other-error-codes-when-you-tr[^Без дополнительной информации невозможно понять, почему это произошло.


Member 12643851

сэр я предоставил вам весь код, сброшенный на эту ошибку
собственно, что именно произойдет. когда я нажимаю кнопку, то он имитирует нажатие клавиши f1 для стороннего приложения ..после активации в фоновом режиме.. но он работал только через 2 или 3 дня после того, как он отобразил ошибку access denied в системе.ComponentModel.Win32Exception был необработан, поскольку я предоставляю трассировку стека выше

Richard MacCutchan

Да, и я дал вам ссылку на некоторую информацию Microsoft, которая может вам помочь. Но ни ваш код, ни детали исключения не предоставляют достаточной информации, чтобы можно было сказать, в чем заключается проблема. Вам нужно будет провести еще некоторое расследование, чтобы попытаться выяснить, что именно происходит, чтобы вызвать исключение. Извините, но мы не можем смоделировать вашу систему для вас.