Not running as different user

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 237
Last visit: Thu Jun 13, 2019 7:31 am

Not running as different user

Post by mqh777 »

I have a form that when compiled will just run some code, no interaction with the end user. This code when run from PowerShell ISE works as expected. It changed the Chrome Browser homepage to what you specify.

Code: Select all

	$policyexists = Test-Path HKLM:\SOFTWARE\Policies\Google\Chrome
	$policyexistshome = Test-Path HKLM:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs
	$regKeysetup = "HKLM:\SOFTWARE\Policies\Google\Chrome"
	$regKeyhome = "HKLM:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs"
	$url = ""
	if ($policyexists -eq $false)
		New-Item -path HKLM:\SOFTWARE\Policies\Google
		New-Item -path HKLM:\SOFTWARE\Policies\Google\Chrome
		New-ItemProperty -path $regKeysetup -Name PasswordManagerEnabled -PropertyType DWord -Value 0
		New-ItemProperty -path $regKeysetup -Name RestoreOnStartup -PropertyType Dword -Value 4
		New-ItemProperty -path $regKeysetup -Name HomepageLocation -PropertyType String -Value $url
		New-ItemProperty -path $regKeysetup -Name HomepageIsNewTabPage -PropertyType DWord -Value 0
		Set-ItemProperty -Path $regKeysetup -Name PasswordManagerEnabled -Value 0
		Set-ItemProperty -Path $regKeysetup -Name RestoreOnStartup -Value 4
		Set-ItemProperty -Path $regKeysetup -Name HomepageLocation -Value $url
		Set-ItemProperty -Path $regKeysetup -Name HomepageIsNewTabPage -Value 0
	if ($policyexistshome -eq $false)
		New-Item -path HKLM:\SOFTWARE\Policies\Google\Chrome\RestoreOnStartupURLs
		New-ItemProperty -path $regKeyhome -Name 1 -PropertyType String -Value $url
		Set-ItemProperty -Path $regKeyhome -Name 1 -Value $url

In PowerShell Stuido I have tried the following.

Script Engine: v3 host (windows forms)
output settings: No Manifest, alternate credentials Domain\AdminUser Password: P@$$word (this is an admin account that has local admin rights)

using these settings does not work. I run the compiled .EXE and it does not change the Chrome homepage. I have right clicked my .EXE and picked both "run as Admin" and "run as different user" and neither works.

Thanks for any help you can provide.

Posts: 14762
Last visit: Mon Apr 19, 2021 4:16 pm
Answers: 9
Has voted: 3 times
Been upvoted: 7 times

Re: Not running as different user

Post by jvierra »

This will only change the values for the admin account that it is specified to run under. If you set the policies it is not certain that the policies will be applied to a user on first login.

The functionality of this may also depend on the domain GP settings which will override local machine settings. I recommend using the domain GP template for Google to do this.