Getting System.ComponentModel.Win32Exception (5): Access is denied on Azure-Release

huangapple go评论96阅读模式
英文:

Getting System.ComponentModel.Win32Exception (5): Access is denied on Azure-Release

问题

我正在使用 Appium WinAppDriver 通过一个 .bat 文件来运行 UI 自动化测试。当我在代理上手动运行 .bat 文件时,一切都如预期运行,但在 Azure Release 中运行时出现了 System.ComponentModel.Win32Exception (5):拒绝访问异常。

尝试过:
BuildUser 是在我的代理机器 DOTNET4 上拥有管理员权限的帐户。
我尝试使用 BuildUser 帐户和我的本地帐户来运行发布管道。

还尝试了不同的方式以管理员身份运行 .bat 文件。

我为包含 WinAppDriver.exeAzureAgent.exe 和 AUT 的文件夹提供了完全控制权限。

Azure 代理服务正在使用 Windows 服务中的 BuildUser 帐户运行。我使用 以管理员身份运行 运行这个 .exe

.bat 文件的内容附在下面:

@echo off
set TESTDIR=%~1
set LaunchedFromWinAppDriver=True
set ApplicationExe=C:\Git\filePathToExe\application.exe
C:\Git\filePathToExe\AppExeCommandLineRunner.exe -X "%ApplicationExe%"::"%TESTDIR%"

导致异常的代码段:

public static void KillApplication()
{
    try
    {
        string windowHandle = WindowDriver.CurrentWindowHandle;
        Log.Debug("CurrentWindowHandl:" + windowHandle);
        [DllImport("user32.dll")]
        static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
        IntPtr windowHandlePtr = new IntPtr(Convert.ToInt64(windowHandle, 16));
        Log.Debug("WindowHandlePtr:" + windowHandlePtr.ToString());
        uint processId;
        GetWindowThreadProcessId(windowHandlePtr, out processId);
        Log.Debug("Process Id for killing is: " + (int)processId);
        Process process = Process.GetProcessById((int)processId);
        process.Kill();
    }
    catch(Exception ex)
    {
        Log.Error("FailedToKill:", ex);
        throw;
    }
}

当在 Azure Release 管道中运行时,函数 GetWindowThreadProcessId 返回 0,然后 process.Kill 生成异常。此外,如果我使用其他逻辑提供有效的进程 ID,它也会失败,并产生相同的拒绝访问异常。

当在代理上手动运行 .bat 文件时,GetWindowThreadProcessId 返回与 AUT 关联的有效进程 ID。

我认为这个问题是权限问题。

英文:

I am running UI-Automation Test with Appium WinAppDriver using a .bat file. When I run the .bat file manually on the agent everything goes as expected but it produces
System.ComponentModel.Win32Exception (5): Access is denied exception when running through Azure Release.

Tried:
BuildUser is the account having admin privileges on my agent machine DOTNET4.
I have tried running the release pipeline using both BuildUser account and also my local account.

Tried different ways to run the .bat file as admin too.

I provided Full Control of folder in which I have WinAppDriver.exe, AzureAgent.exe, & Folder having AUT.

Azure Agent Service in running using the BuildUser account in Windows Services. I have this .exe running using Run as Administrator.

Getting System.ComponentModel.Win32Exception (5): Access is denied on Azure-Release

Contents of .bat file is attached:

@echo off
set TESTDIR=%~1
set LaunchedFromWinAppDriver=True
set ApplicationExe=C:\Git\filePathToExe\application.exe
C:\Git\filePathToExe\AppExeCommandLineRunner.exe -X "%ApplicationExe%"::"%TESTDIR%"

Code Snippet that is causing Exception:

public static void KillApplication()
        {
            try
            {
                string windowHandle = WindowDriver.CurrentWindowHandle;
                Log.Debug("CurrentWindowHandl:"+windowHandle);
                [DllImport("user32.dll")]
                static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
                IntPtr windowHandlePtr = new IntPtr(Convert.ToInt64(windowHandle, 16));
                Log.Debug("WindowHandlePtr:" +windowHandlePtr.ToString());
                uint processId;
                GetWindowThreadProcessId(windowHandlePtr, out processId);
                Log.Debug("Process Id for killing is: " + (int)processId);
                Process process = Process.GetProcessById((int)processId);
                process.Kill();
            }
            catch(Exception ex)
            {
                Log.Error("FailedToKill:", ex);
                throw;
            }
        }

Function GetWindowThreadProcessId returns 0 when run using Azure Release pipeline and then process.Kill generates the exception.process. Additionally if I give a valid Process id using some other logic it fails to Kill that as well giving same access id denied.

GetWindowThreadProcessId returns a valid process id on which AUT is attached when the .bat file is run manually on the agent.

I believe this issue is due to a permission issue.

答案1

得分: 0

上述问题发生的原因是Azure代理监听器正在以“服务”的形式运行。当我在系统中以交互式桌面会话手动运行Agent.Listener.exe时,问题得以解决。

Listener.exe的路径:"C:\agent\bin\Agent.Listener.exe"

英文:

The above issue was happening because the Azure Agent Listener was running as a service. It solved when I run the Agent.Listener.exe manually on the system in a interactive desktop session.

Path to Listener.exe: "C:\agent\bin\Agent.Listener.exe"

huangapple
  • 本文由 发表于 2023年7月17日 14:13:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76701886.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定