【问题标题】:Azure function Process.Start() C# as different user got Access denied errorAzure function Process.Start() C# as different user got Access denied error
【发布时间】:2020-04-03 06:54:48
【问题描述】:

我正在尝试通过提供用户的用户名和密码,使用 Process.Start 命令在 azure function (v2) 中运行可执行文件

string nwPath = <path/to/bla.exe>
string dirName = Path.GetDirectoryName(nwPath);
var processInfo = new ProcessStartInfo()
            {
                WorkingDirectory = dirName,
                FileName = nwPath,
                UserName = <username>,
                Password = secureString,
                Domain = <domain>,
                UseShellExecute = false,
                Arguments = @"p1 p3",
                Verb = "runas"
            };
Process.Start(processInfo);

此函数使用传入的用户名和密码在本地运行。当我将它部署到天蓝色时,我收到以下错误 访问被拒绝

我已经通过点击上传按钮上传了azure函数中的可执行文件,可执行文件路径是

C:\home\wwwroot\functionname\bla.exe

如果我使用以下命令运行该进程,它将在 azure 上运行

Proccess.Start(@"path/to/bla.exe")

我假设在用户下运行的进程无权访问可执行文件。

我们可以授予用户访问 azure 函数中的可执行文件的权限吗?

【问题讨论】:

    标签: azure-functions


    【解决方案1】:

    由于 azure func 的架构,您似乎无法指定用户权限。

    尝试在ProcessStartInfo 中使用HostingPath 作为WorkingDirectory

       private static string HostingPath =>
                Environment.GetEnvironmentVariable("AzureWebJobsScriptRoot") // local_root
                ?? (Environment.GetEnvironmentVariable("HOME") == null
                    ? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
                    : $"{Environment.GetEnvironmentVariable("HOME")}/site/wwwroot");
    

    【讨论】:

    • 添加托管路径后没有运气。可执行路径存在,但在指定用户下运行的进程没有读取或写入权限。我想为用户添加读取权限。
    • @SudhakarReddy 你的控制台应用程序想要做什么?另外,您可以尝试在不传递用户名和密码的情况下运行吗?
    • 因此,如果我无法提供文件夹权限,那么有什么方法可以在 azure 中运行可执行文件?我想在特定用户下运行可执行文件。
    • 如果您的 .exe 应用程序尝试将一些数据写入 /site/wwwroot 文件夹,它将收到异常
    猜你喜欢
    • 2019-11-11
    • 2021-05-14
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多