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.
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Not running as different user

Post by mqh77777 »

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 5 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked