Skip to content

Commit 7c55fc7

Browse files
authored
Merge pull request #481 from SteveL-MSFT/store-check
Detect if `dsc.exe` is started from MSStore or Explorer and show a message and wait for key press
2 parents 0ac061c + 303a734 commit 7c55fc7

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

build.ps1

+18-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ param(
77
$architecture = 'current',
88
[switch]$Clippy,
99
[switch]$SkipBuild,
10-
[ValidateSet('msix','msixbundle','tgz','zip')]
10+
[ValidateSet('msix','msix-private','msixbundle','tgz','zip')]
1111
$packageType,
1212
[switch]$Test,
1313
[switch]$GetPackageVersion,
@@ -424,7 +424,7 @@ if ($packageType -eq 'msixbundle') {
424424
$msixPath = Join-Path $PSScriptRoot 'bin' 'msix'
425425
& $makeappx bundle /d $msixPath /p "$PSScriptRoot\bin\$packageName.msixbundle"
426426
return
427-
} elseif ($packageType -eq 'msix') {
427+
} elseif ($packageType -eq 'msix' -or $packageType -eq 'msix-private') {
428428
if (!$IsWindows) {
429429
throw "MSIX is only supported on Windows"
430430
}
@@ -433,21 +433,34 @@ if ($packageType -eq 'msixbundle') {
433433
throw 'MSIX requires a specific architecture'
434434
}
435435

436+
$isPrivate = $packageType -eq 'msix-private'
437+
436438
$makeappx = Find-MakeAppx
437439
$makepri = Get-Item (Join-Path $makeappx.Directory "makepri.exe") -ErrorAction Stop
438440
$displayName = "DesiredStateConfiguration"
439441
$isPreview = $productVersion -like '*-*'
440442
$productName = "DesiredStateConfiguration"
441443
if ($isPreview) {
442444
Write-Verbose -Verbose "Preview version detected"
443-
$productName += "-Preview"
445+
if ($isPrivate) {
446+
$productName += "-Private"
447+
}
448+
else {
449+
$productName += "-Preview"
450+
}
444451
# save preview number
445452
$previewNumber = $productVersion -replace '.*?-[a-z]+\.([0-9]+)', '$1'
446453
# remove label from version
447454
$productVersion = $productVersion.Split('-')[0]
448455
# replace revision number with preview number
449456
$productVersion = $productVersion -replace '(\d+)$', "$previewNumber.0"
450-
$displayName += "-Preview"
457+
458+
if ($isPrivate) {
459+
$displayName += "-Private"
460+
}
461+
else {
462+
$displayName += "-Preview"
463+
}
451464
}
452465
Write-Verbose -Verbose "Product version is $productVersion"
453466
$arch = if ($architecture -eq 'aarch64-pc-windows-msvc') { 'arm64' } else { 'x64' }
@@ -519,7 +532,7 @@ if ($packageType -eq 'msixbundle') {
519532
throw "Failed to create msix package"
520533
}
521534

522-
Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName.msix"
535+
Write-Host -ForegroundColor Green "`nMSIX package is created at $packageName"
523536
} elseif ($packageType -eq 'zip') {
524537
$zipTarget = Join-Path $PSScriptRoot 'bin' $architecture 'zip'
525538
if (Test-Path $zipTarget) {

dsc/src/main.rs

+38
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ fn main() {
2626
#[cfg(debug_assertions)]
2727
check_debug();
2828

29+
#[cfg(windows)]
30+
check_store();
31+
2932
if ctrlc::set_handler(ctrlc_handler).is_err() {
3033
error!("Error: Failed to set Ctrl-C handler");
3134
}
@@ -156,3 +159,38 @@ fn check_debug() {
156159
}
157160
}
158161
}
162+
163+
// Check if the dsc binary parent process is WinStore.App or Exploerer.exe
164+
#[cfg(windows)]
165+
fn check_store() {
166+
let message = r"
167+
DSC.exe is a command-line tool and cannot be run directly from the Windows Store or Explorer.
168+
Visit https://aka.ms/dscv3-docs for more information on how to use DSC.exe.
169+
170+
Press any key to close this window
171+
";
172+
let sys = System::new_with_specifics(RefreshKind::new().with_processes(ProcessRefreshKind::new()));
173+
// get current process
174+
let Ok(current_pid) = get_current_pid() else {
175+
return;
176+
};
177+
178+
// get parent process
179+
let Some(current_process) = sys.process(current_pid) else {
180+
return;
181+
};
182+
let Some(parent_process_pid) = current_process.parent() else {
183+
return;
184+
};
185+
let Some(parent_process) = sys.process(parent_process_pid) else {
186+
return;
187+
};
188+
189+
// MS Store runs app using `sihost.exe`
190+
if parent_process.name().to_lowercase() == "sihost.exe" || parent_process.name().to_lowercase() == "explorer.exe"{
191+
eprintln!("{message}");
192+
// wait for keypress
193+
let _ = io::stdin().read(&mut [0u8]).unwrap();
194+
exit(util::EXIT_INVALID_ARGS);
195+
}
196+
}

0 commit comments

Comments
 (0)