Gitlab-Runner Windows service: build with administrative priviledges - windows-services

Problem
gitlab-runner in Powershell on build server finishes successfully (vb6.exe, devenv.com, msbuild.exe) if running in local terminal started with "run as administrator", whereas ending up in errors while running as Windows service configured as local administrator
Desired Behavior
building projects (vb6.exe, devenv.com, msbuild.exe) with administrative privileges via gitlab-runner as Windows service on isolated build server
Configuration
Windows Server 2019, Gitlab-Runner v.14.3.2 64bit, powershell mode, service running with local administrator account
Visual Studio (VS) builds need adminstrator privileges for interopability between VB6 UI (VS VB98) and VB6/C# (VS 2019) projects. During building VS writes in Windows Registry if interopt-mode in sub-project of VS solution has been selected (administrator permissions therefore mandatory).
Try outs
installed gitlab-runner as service recommended by https://docs.gitlab.com/runner/install/windows.html
temporary deactivated User Account Control with no success
adapted gitlab-ci.yml to call vb6.exe, devenv.com and msbuild.exe with Powershell command Start-Process -Verb runAs -Wait devenv.com ..., but ended up in errors for devenv.com because Start-Process seems to accept only applications with *.exe as file ending. devenv.exe is working but not returning/closing new terminal session by Start-Process which ends up in a hanging gitlab-ci-build-script. Additionally, terminal messages of the build script are not visible anymore because they are running in a new terminal session created by Start-Process.
Deactivating gitlab-runner service and starting via Windows auto-start-folder: running Powershell-Script: Start-Process -FilePath D:\development\gitlab-runner\gitlab-runner -ArgumentList 'run --working-directory D:\development\gitlab-runner --config D:\development\gitlab-runner\config.toml --service gitlab-runner --syslog' -Verb runAs -Wait, but configured user needs to login on every system start which is not the desired behavior of the build server.
gitlab-runner.exe/vb6.exe/devenv.exe/msbuild.exe - right click - properties - compatibility - change settings for all users - checkbox: run as administrator for all user activated - did not change the described behavior
gitlab-ci.yml
stages:
- deploy
variables:
PLATFORM: 'x86'
CONFIGURATION: 'Release'
myproject:
stage: deploy
when: manual
tags: [deploying]
script:
- Start-Process MSBuild.exe -Wait -Verb runAs -Argument 'AutomatedSetupBuild.proj'
- Start-Process devenv.com -Wait -Verb runAs -ArgumentList ".\mysolution.sln /Rebuild `"$CONFIGURATION|$PLATFORM`" /Project .\myproject\myproject.vbproj /ProjectConfig `"$CONFIGURATION|$PLATFORM`" /Log"
- Start-Process vb6.exe -Wait -Verb runAs -ArgumentList "/make `".\vbproject.vbp`" /out `"$env:TEMP/vb6-buildoutput.log`""

What works for me is to give the user I intend to install the runner as right to log on as a service. Go to Control Panel -> Administrative Tools -> Local Security Policy -> Security Settings -> Local Policies -> User Rights Assignment -> Log on as a service . You need to add the user you installed gitlab-runner to the list, including the local domain, and then install the runner according to https://docs.gitlab.com/runner/install/windows.html, also using the full username with domain.

Related

Install exe file silently using CMD and PowerShell

I am trying to install an exe created using Inno Setup.
When I try to install it using PowerShell with
Start-Process -wait C:\updatefile.exe /VERYSILENT
all folders are created at proper places, registry values are created, but console hangs and does not return unless Ctrl+C is pressed.
But if I install exe using command prompt with
start /wait C:\updatefile.exe /VERYSILENT
everything goes properly and command prompt returns.
What could be cause of this anomaly?
I need this exe to install through Dockerfile, but as PowerShell install is hanging, container does not install exe. Even with cmd version in Dockerfile, container does not create install folders.
After checking logs I found that exe service is being started by installer in end. If that is reason for hanging, is there some argument I can use to exit PowerShell?
The -Wait switch of PowerShell's Start-Process cmdlet also waits for child processes of the launched process to exit[1], whereas cmd.exe's internal start command does not.
As you note in a later comment, a service executable is launched by your installer at the end; given that services run indefinitely, Start-Process also waiting for that (child) process to terminate indeed explains the hang.
Here is a simple workaround:
cmd /c C:\updatefile.exe /VERYSILENT
When an executable is called via cmd /c, cmd.exe implicitly waits until the executable's process - and only it - terminates, even if it is a GUI application, just like start /wait would.
Given the behavior described in footnote [1], another workaround is to use the -PassThru switch with Start-Process (instead of -Wait) and pipe the result to Wait-Process:
Start-Process -PassThru C:\updatefile.exe /VERYSILENT | Wait-Process
[1] See GitHub issue #15555, which also discusses that Wait-Process acts differently in that only waits for the process itself to terminate.
As zett42 points out, the behavior of Start-Process -Wait is now at least briefly mentioned in the docs as well (emphasis added): "waits for the specified process and its descendants".
try
$arguments = "/Verysilent"
Start-Process -wait C:\updatefile.exe -ArgumentList $arguments

pushd throws access denied when trying to access windows 10 from jenkins job which is in windows 7 professional

I want to execute some SOAP suites which is located in a Windows 10 machine.
But I have my jenkins setup and job everything in a Windows 7 machine.
When I tried to execute the below Windows batch command:
c:
pushd \xyzsoapmachine01\c$
cd Program Files\SmartBear\ReadyAPI-2.5.0\bin
testrunner.bat -s "Automation Suite" -c "TestCase_JenkinsCheck" Z:\Projects\xyzsoapui-project.xml
popd
I get the error as pushd \xyzsoapmachine01\c$
Access is denied.
how to resolve this please?

Docker Container with support for Crystal Reports

I am trying create a Docker image to host my asp.net MVC app that has a dependency on Crystal Reports.
My dockerfile looks like this
FROM microsoft/iis
COPY ./bin/Release/Publish/ c:\\inetpub\\wwwroot
RUN ["powershell.exe", "Install-WindowsFeature NET-Framework-45-ASPNET"]
RUN ["powershell.exe", "Install-WindowsFeature Web-Asp-Net45"]
#install Crystal reports runtime
COPY Resources/Files/CRRuntime_64bit_13_0_21.msi .
RUN powershell.exe -Command Start-Process CRRuntime_64bit_13_0_21.msi -ArgumentList '/quiet' -Wait
The installing of the CRRuntime_64bit_13_0_21.msi fails. I logged onto my container and ran the msi install from powershell and produced a log. Its very long but here are 2 things that stand out:
Error 1904. Module C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win64_x64\pageobjectmodel.dll failed to register. HRESULT -2147024770. Contact your support personnel.
Action ended 17:20:50: InstallFinalize. Return value 3.
Action ended 17:23:56: INSTALL. Return value 3.
MSI (s) (3C:54) [17:23:56:467]: Product: SAP Crystal Reports runtime engine for .NET Framework (64-bit) -- Installation operation failed.
MSI (s) (3C:54) [17:23:56:467]: Windows Installer installed the product. Product Name: SAP Crystal Reports runtime engine for .NET Framework (64-bit). Product Version: 13.0.21.2533. Product Language: 1033. Manufacturer: SAP. Installation success or error status: 1603.
The first error does not seem to halt the install.
Any suggestions for troubleshooting this are welcome as are alternative ways of creating the image.
Also, just to confirm. The website loads and runs fine. I just can't use any of the features that require the Crystal Reports dependency.
Using the full Windows 2019 container mcr.microsoft.com\windows:1809 as a base, the installer works, which hints that it's just down to missing OS components.
I don't get the 'Error 1904' logged but maybe I'm on a different host OS.
The installer log shows that a custom action SetASPDotNetDllPath is failing.
If you:
Open the installer MSI (e.g. in Orca)
Locate and extract the action binary, save as dll
Inspect its imports (e.g. with dumpbin)
This shows a dependency on oledlg.dll.
This is its only dependency which isn't available in Server Core.
Its not great, but you can copy this version from the full windows container to fix it:
FROM mcr.microsoft.com/windows:1809 as dll_source
FROM microsoft/iis
#hack in oledlg dll!!
COPY --from=dll_source /windows/system32/oledlg.dll /windows/system32/oledlg.dll
COPY --from=dll_source /windows/syswow64/oledlg.dll /windows/syswow64/oledlg.dll
RUN ["powershell.exe", "Install-WindowsFeature NET-Framework-45-ASPNET"]
RUN ["powershell.exe", "Install-WindowsFeature Web-Asp-Net45"]
WORKDIR c:/temp
COPY CRRuntime_64bit_13_0_21.msi .
RUN powershell.exe -Command Start-Process c:\temp\CRRuntime_64bit_13_0_21.msi -ArgumentList '/l*v c:\temp\install.log' -Wait
I'm going to add an additional answer while Peters answer worked perfectly for installing Crystal Reports, I had an additional issue with missing Fonts when exporting to PDF from Crystal Report.
This is what I've ended up with. The key is the change in the image tag name to be an older version.
#windowsservercore-1803 required as it has the fonts we need in the report in order to export to PDF
FROM microsoft/iis:windowsservercore-1803
#install features we need
RUN ["powershell.exe", "Install-WindowsFeature NET-Framework-45-ASPNET"]
RUN ["powershell.exe", "Install-WindowsFeature Web-Asp-Net45"]
#hack in oledlg dll so that Crystal Runtime will install
COPY Resources/Files/64/oledlg.dll /windows/syswow64/oledlg.dll
COPY Resources/Files/32/oledlg.dll /windows/system32/oledlg.dll
#copy in Crystal MSI and install. Note it's 64bit version
WORKDIR c:/temp
COPY Resources/Files/CRRuntime_64bit_13_0_21.msi .
RUN powershell.exe -Command Start-Process c:\temp\CRRuntime_64bit_13_0_21.msi -ArgumentList '/quiet /l*v c:\temp\install64.log' -Wait
#Add website files
COPY ./bin/Release/Publish/ /inetpub/wwwroot
For some reason Microsoft have dropped lots of fonts from version 1803 to 1809. I can only assume to reduce the OS image size.

Unable to start process from powershell

Folks
I am trying to invoke a batch script from a power shell file and the invocation works fine if executed manually.
Start-Process C:\USR\test.bat
However i created a service in C# which is able to delete and write logs using the powershell script however it simply ignores this step and nothing happens. Is it because this script is invoked by a windows service ?
if (Test-Path \\xxxsharepathfullper\FileWatcher\target\watcher.mon) {
echo "File removed" >> C:\USR\logger.txt
Start-Process C:\USR\test.bat
Remove-Item \\xxxsharepathfullper\FileWatcher\target\watcher.mon
}
else {
}
Execution policy is unrestricted
Check access rights on a share, maybe your admin user don't have rights to access it.
You can try run the process as administrator and log any error:
Start-Process -FilePath "C:\USR\test.bat" -RedirectStandardError "testError.txt" -verb RunAs

Can we register PSSessionConfiguration on remote machine?

Is it possible to register a PS session configuration for machine A from machine B.
Cmdlet "Register-PSSessionConfiguration" works locally only??
First you need to enable PowerShell Remoting on the PC You Want to Access Remotely
In the PowerShell window, type the following command, and then hit Enter:
Enable-PSRemoting -SkipNetworkProfileCheck -Force
Set-Item WSMan:\localhost\Client\TrustedHosts *
Restart-Service WinRM
Test-WsMan $env:computername
If you’re on a home network where you want to go ahead and trust any PC to connect remotely, you can type the following cmdlet in PowerShell (again, you’ll need to run it as Administrator).
Set-Item wsman:\localhost\client\trustedhosts *
Or
Set-Item wsman:\localhost\client\trustedhosts 10.0.0.22
Or
Set-Item wsman:\localhost\client\trustedhosts '10.0.0.22,10.0.0.23'
Register a PSSessionConfiguration
To connect 'Computer1' let us register a session configuration on the server using a domain account.
Just type the following cmdlet and then hit Enter:
Invoke-Command -ComputerName Computer1 -ScriptBlock {Register-PSSessionConfiguration -Name SessionName -RunAsCredential 'domain\mydomainaccount' -Force }
Now I'll use this session configuration the next time I want to run a command on the remote computer.
Invoke-Command -ComputerName 'Computer1' -ScriptBlock { Get-ChildItem-Path \\Computer1\c$ } -ConfigurationName SessionName

Resources