B
B
Boris the Animal2021-06-11 14:41:50
PowerShell
Boris the Animal, 2021-06-11 14:41:50

ASP.NET Core 3.1 + IIS + Powershell SDK. How to run a third party application through PowerShell in a virtual machine?

The web application is installed on a Windows 10 virtual machine. It is launched from under IIS in the application pool that I created and set the parameters in its settings:
Identity / Identity - A user with admin rights, but not the one that I am logged into the virtual machine.
Start Mode / Start mode - AlwaysRunning
Idle-Time-Out (minutes) / Idle timeout in minutes - 60

This code works if I run the application from under debug in Visual Studio or on my computer, where the Identity parameter is in the application pool in IIS / The identity is set to the same user that I am logged into Windows.

PowerShell powerShell = null;
try
{
    powerShell = PowerShell.Create();
    // Здесь подписка на обработчики событий...
    string clientCommandLineArgs = "...";
    var sb = new StringBuilder(); // там ещё одна команда, поэтому собираю результаты для лога так

    var startProcessResult = await powerShell
        .AddScript($"Start-Process \"{clientCommandLineArgs}\";")
        .InvokeAsync()
        .ConfigureAwait(false);
    sb.AppendLine(string.Join("; ", startProcessResult.Select(x => $"Start-Process: {x.ToString()}")));

    _logger.Information(template + $"PowerShell:{Environment.NewLine}{sb}");
}
finally
{
    if (powerShell is not null)
    {
        // Отписка от обработчиков событий...
    }
}


I'm trying to launch a UWP app from a link. You can create special links, register them in the application manifest and launch them using this link. This is exactly how I run the application, rather than specifying the path to the *.exe file.

How to solve the problem and what is the problem in general? In that different users or in what?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2021-06-17
@rPman

As far as I know, the only way to run a process as a user other than the one logged in without being prompted for a login and password is to use the task scheduler service.
You create a task without launch conditions, specify in the properties that you have a different user, enter the login password - that's it. Now, to run this task, you need to write schtask /run ...
ps it was discussed here how to do it from the power shell, but iis rights are not enough
pps, I launched a special process from under the desired user, which monitored a special file for commands and launched it (for atomic operations, so as not to cut databases, this file was renamed to temporary, started, deleted and again waiting if there are a lot of processes writing to the file - for each file, for example, with a PID in the name), but the service itself needs to be started somehow if you need automatic start when you turn on the computer, i.e. ppps service
again Once upon a time, there was a third-party srvany utility that raised a service that allowed you to run the specified utility under the rights of the service, and these rights themselves were configured in the registry.
upd. in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question