Skip to content

[Help Wanted] Work as service but not as command line #29

@koraniar

Description

@koraniar

I modified DemoService to run ProcessExtensions.StartProcessAsCurrentUser("cmd.exe", "/d /s /c \"node Path\\To\\file\""), I have installed it and it works perfect,

So I made an executable to receive the route to execute as a parameter by this way

private static int RunAndReturnExitCode(RunVerb opts)
{
    string command = opts.commands.FirstOrDefault();
    Console.WriteLine(command); // This prints -> node Path\To\file 
    if (command == null || command == "")
    {
        return 1;
    }

    ProcessExtensions.StartProcessAsCurrentUser("cmd.exe", $"/d /s /c \"{command}\"");
    return 0;
}

I launch a CMD as System user using psexec with this command PsExec64.exe -i -s cmd.exe and at runnning the command CreateProcessAsUserCMD.exe --run "node Path\To\file" it responses an error

System.Exception: StartProcessAsCurrentUser: CreateProcessAsUser failed.  Error Code -2
   en murrayju.ProcessExtensions.ProcessExtensions.StartProcessAsCurrentUser(String appPath, String cmdLine, String workDir, Boolean visible) en C:\GitHub\CreateProcessAsUser\ProcessExtensions\ProcessExtensions.cs:l�nea 249
   en CreateProcessAsUserCMD.Program.RunAndReturnExitCode(RunVerb opts)
   en CreateProcessAsUserCMD.Program.<>c.<Main>b__0_0(RunVerb opts)
   en CommandLine.ParserResultExtensions.MapResult[TSource,TResult](ParserResult`1 result, Func`2 parsedFunc, Func`2 notParsedFunc)
   en CreateProcessAsUserCMD.Program.Main(String[] args)

I have tried to launch the executable from an installed service but it responses the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions