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.
Locked
User avatar
mqh777
Posts: 237
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Tue Feb 25, 2014 1:01 pm

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



$form1_Load={
	
	$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 = "https://OurCompany.sharepoint.com/sites/corpportal"
	
		
	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
	}
	
	Else
	{
		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
	}
	Else
	{
		Set-ItemProperty -Path $regKeyhome -Name 1 -Value $url
	}
	
	$form1.Close()
}

In PowerShell Stuido I have tried the following.

Settings:
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.

jvierra
Posts: 14231
Joined: Tue May 22, 2007 9:57 am
Contact:

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.

Locked