I am currently attempting to run a Windows Azure pipeline in which a specific job requires executing a command under a different user account. To accomplish this, I am using the CPAU (www.joeware.net) command.
However, I have encountered an issue when running the self-hosted agent as a service. If the user account I used to log in differs from the one specified in the CPAU command line, it results in an error (-1073741502). The problem does not occur if I input the same username and password as the admin accound that runs the self-hosted agent in the CPAU command.
It's important to note that everything works as expected when the scripts are launched either in the local session or with the self-hosted agent in interactive mode.
I would greatly appreciate any insights or suggestions you might have to address this issue when working with a self-hosted agent as a service.
name: $(Rev:r)
resources:
repositories:
- repository: self
type: git
name: "git_repos"
stages:
- stage: __default
jobs:
- job: Job
variables:
- name: step_display_name
value: Run as another user
strategy:
matrix:
Windows:
demanded_agent_os: Windows_NT
pool:
name: test
demands:
- Agent.OS -equals $(demanded_agent_os)
workspace:
clean: outputs
steps:
- task: 6d15af64-176c-496d-b583-fd2ae21d4df4@1
inputs:
repository: self
submodules: recursive
- task: CmdLine@2
displayName: $(step_display_name)
inputs:
script: |
RMDIR /s /q C:\foo
MKDIR C:\foo
CALL C:\CPAU\cpau.exe -u DOMAIN\another.username -p "$(userPassword)" -ex "cmd.exe /c echo print bar file > C:\foo\bar.txt" -wait -lwp -outprocexit -cwd C:\
IF %ERRORLEVEL% NEQ 0 (
ECHO %ERRORLEVEL%
EXIT /B 1
)
TYPE C:\foo\bar.txt
With this example, when the self-hosted agent runs in interactive mode the job is successful, but fails in service mode with error code: "-1073741502".