Change what user code deploy executes scripts under windows

Viewed 92

I have a code deploy project with an app spec.yml file. It has a list of hooks that call powershell scripts.

The code deploy has scripts within that is moved onto the ec2 machine. I’m then trying to use scripts within my app spec to call the scripts copied to the deploy folder


version: 0.0
os: windows
files:
  - source: /deploy
    destination: /things
hooks:
  AfterInstall:
    - location: ./install.ps1
      timeout: 300

These powershell scripts call other batch files to setup services


# Fail on all errors
$ErrorActionPreference = 'Stop'

# Are you running in 32-bit mode?
#   (\SysWOW64\ = 32-bit mode)

if ($PSHOME -like "*SysWOW64*")
{
  Write-Warning "Restarting this script under 64-bit Windows PowerShell."

  # Restart this script under 64-bit Windows PowerShell.
  #   (\SysNative\ redirects to \System32\ for 64-bit mode)

  & (Join-Path ($PSHOME -replace "SysWOW64", "SysNative") powershell.exe) -File `
    (Join-Path $PSScriptRoot $MyInvocation.MyCommand) @args

  # Exit 32-bit script.

  Exit $LastExitCode
}

D:
cd d:/install/scripts
Call installservices.bat 

And then the batch script looks like this..which installs a windows service

App.exe /install 
App2.exe/install

The issue I am running into is when the code deploy executes these powershell scripts it’s from a specific “environment” for code deploy but not as a user on windows.

It executes under this directory C:\Windows\system32

So the installer that is called automatically is not able to find a user data folder on the current executing user to drop config files to complete the install.

If I manually run the powershell script from the directory it works fine as I’m logged in as user, its in the context of code deploy executing the script that it no longer works

Is there a way to execute power shell scripts outside of how code deploy executes it, or execute as a specific user on windows?

I see Linux has a run as option for their app spec, but that option is not for windows.

This is on a windows Ec2 machine

0 Answers
Related