1
votes

For running our UI tests were using the task "Visual Studio test agent deployment", which has been deprecated now. So i have moved the tasks to use "Visual Studio Test" task.

This needs agents to be configured as interactive process rather than service. So i created a new build server with interactive process agent running with admin rights user.

For signing or code we are using signed certificates that gets installed on the build server. But for some reason this new build server seems to loose the certificate cred every single time the pipeline runs.

I have tried to to run a ps1 file to reinstall the cert with no success. Below id the code that i have for reinstalling the cert and i am using task "PowerShell on target machines" to run the script. The user running this script is admin on the box, is there a different way of getting the ps1 file to run as admin all the time?

Set-Location "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools"
Start-Process cmd.exe
Sleep 2
$WshShell = New-Object -ComObject WScript.Shell
Sleep 2
$WshShell.sendkeys(".\sn.exe -d  $KeyContainer{Enter}");
Sleep 2
$WshShell.sendkeys(".\sn.exe -i $PfxCertificatePath  $KeyContainer{Enter}");
Sleep 2;
$WshShell.sendkeys("$passWord{Enter}");
Sleep 2;
$WshShell.sendkeys("{Enter}");

Any help would be greatly appreciated.

1
is there a different way of getting the ps1 file to run as admin all the time? Hi, what's the result if you directly run the sn.exe command in cmd.exe in current admin account? As I know, this kind of action needs us to run cmd as admin even when we sign in the machine with admin account... So if you want a way to do that instead if using admin account in the box, I think it's not supported...LoLance
@LanceLi-MSFT on the server as well i have to run it as admin (even though i am logged in as admin account). is there a way to get the cmd.exe to run as admin through the pipeline?suprasad
Sorry but pipeline itself doesn't have this option. For now, only the PS in remote machine task(version3) can run ps as admin. Apart from that, cmd task is not supported... And to start cmd with admin rights in command-line like here, we have to manually enter the password after we run ` runas /noprofile /user:Administrator cmd`, which is not suitable for CI/CD. So I'm afraid the answer is negative.LoLance

1 Answers

0
votes

Is there a way to get the cmd.exe to run as admin through the pipeline?

As i know, for now only the version 3.0 of Powershell on Target Machine task supports our running it as admin. Apart from it, the Command-line task and PowerShell Task doesn't support this feature yet.

So I'm afraid the answer is negative, Azure Devops pipeline doesn't have the option to make us run those tasks(CMD task, PS task...) with admin rights. (According to your description, you're trying to get a different way of using PS on Target Machine task. )

Sorry for the inconvenience. Actually I think it could be one good idea so you could feel free to add your request(CMD task with admin...) for this feature on our UserVoice site, which is our main forum for product suggestions. But it may not be accepted by MS if it doesn't get enough votes.

Hope it helps:)