Skip to content

Commit 8b7a0d8

Browse files
Try to prevent update of user-type Windows installation when running as admin (microsoft#148428) (microsoft#155631)
* Try to prevent update of user-type Windows installation when running as admin (microsoft#148428) * update win32: detect admin mode in initialize Co-authored-by: João Moreno <[email protected]>
1 parent 3558758 commit 8b7a0d8

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

src/vs/code/electron-main/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ export class CodeApplication extends Disposable {
11811181
// Initialize update service
11821182
const updateService = accessor.get(IUpdateService);
11831183
if (updateService instanceof Win32UpdateService || updateService instanceof LinuxUpdateService || updateService instanceof DarwinUpdateService) {
1184-
updateService.initialize();
1184+
await updateService.initialize();
11851185
}
11861186

11871187
// Start to fetch shell environment (if needed) after window has opened

src/vs/platform/update/electron-main/abstractUpdateService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export abstract class AbstractUpdateService implements IUpdateService {
5959
* optimization, to avoid using extra CPU cycles before first window open.
6060
* https://github.com/microsoft/vscode/issues/89784
6161
*/
62-
initialize(): void {
62+
async initialize(): Promise<void> {
6363
if (!this.environmentMainService.isBuilt) {
6464
return; // updates are never enabled when running out of sources
6565
}

src/vs/platform/update/electron-main/updateService.darwin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export class DarwinUpdateService extends AbstractUpdateService {
3838
super(lifecycleMainService, configurationService, environmentMainService, requestService, logService, productService);
3939
}
4040

41-
override initialize(): void {
42-
super.initialize();
41+
override async initialize(): Promise<void> {
42+
await super.initialize();
4343
this.onRawError(this.onError, this, this.disposables);
4444
this.onRawUpdateAvailable(this.onUpdateAvailable, this, this.disposables);
4545
this.onRawUpdateDownloaded(this.onUpdateDownloaded, this, this.disposables);

src/vs/platform/update/electron-main/updateService.win32.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ export class Win32UpdateService extends AbstractUpdateService {
7171
super(lifecycleMainService, configurationService, environmentMainService, requestService, logService, productService);
7272
}
7373

74+
override async initialize(): Promise<void> {
75+
if (this.productService.target === 'user' && await this.nativeHostMainService.isAdmin(undefined)) {
76+
this.logService.info('update#ctor - updates are disabled due to running as Admin in user setup');
77+
return;
78+
}
79+
80+
super.initialize();
81+
}
82+
7483
protected buildUpdateFeedUrl(quality: string): string | undefined {
7584
let platform = 'win32';
7685

0 commit comments

Comments
 (0)