Skip to content

Commit 30b1277

Browse files
committed
Check if the script is running under a Windows service account (SYSTEM, NETWORK SERVICE, LOCAL SERVICE)
1 parent 8595028 commit 30b1277

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

scripts/Build-Accdb.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ param(
99

1010
)
1111

12+
# Check if the script is running under a Windows service account (SYSTEM, NETWORK SERVICE, LOCAL SERVICE)
13+
$serviceAccounts = @('SYSTEM', 'NETWORK SERVICE', 'LOCAL SERVICE')
14+
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
15+
if ($serviceAccounts | Where-Object { $currentUser -match $_ }) {
16+
Write-Warning "Warning: This script is running under a Windows service account ($currentUser). Microsoft Access should not be executed as a service!"
17+
}
18+
1219
[string]$tempFileName = "VcsBuildTempApp"
1320
[string]$accdbFileName = $tempFileName
1421
if ($FileName -gt "") {
@@ -28,6 +35,9 @@ else {
2835
$access.OpenCurrentDatabase($accdbPath)
2936
}
3037

38+
39+
40+
3141
[string]$addInProcessPath = ""
3242
if ($VcsAddInPath -gt "") {
3343
$addInProcessPath = [System.IO.Path]::ChangeExtension($VcsAddInPath, "").TrimEnd('.')
@@ -98,7 +108,6 @@ Write-Host ""
98108
if ( ($builtFileName -gt "") -and ($builtFileName -ne "$tempFileName.accdb") ) {
99109
Write-Host "Built: $builtFileName ($builtFilePath)"
100110
} else {
101-
102111
Write-Host "Build failed"
103112
if ([string]::IsNullOrEmpty($builtFileName)) {
104113
Write-Host " (builtFileName is empty)"

0 commit comments

Comments
 (0)