DanysysTeam / PS-SFTA

PowerShell Set File Type Association
253 stars 53 forks source link

"Sometimes" the HTTPS protocol set by the {Set-PTA ChromeHTML https} command gets deleted by SystemSettings.exe when it opens! #28

Open AmirTerani opened 9 months ago

AmirTerani commented 9 months ago

For some reason Win11's Settings app's Default Apps/Google Chrome Page doesn't like the HTTPS settings generated from the script every the time.

The association works if we use it but when we open the Settings app to confirm their assignment, more like the Schrödinger's cat, sometimes HTTPS gets deleted right away as if it doesn't like the hash that was generated for it. Don't have this issue with .htm, .html, .pdf, or http. image

To work around it, I open the Settings app to its Chrome page earlier in the script and then run the Set-PTA command in a loop with a few seconds wait till Get-PTA confirms that the setting is stuck for good. It seems to work, but it's clunky and intrusive when System Settings pops up in the middle of a background running script. It also slows down the deployment because each loop needs about 15 seconds for everything to settle in.

As the Process Monitor shows here, I set http and it was fine but https had to go through the loop 4 times before SystemSettings.exe leaves it alone. image

Any help fixing this is greatly appreciated.

Thank you, @-

Danyfirex commented 9 months ago

does this happens "sometimes" or "all time" have you tried in other Windows 11 to be sure?

AmirTerani commented 9 months ago

Only sometimes but more often than we can let it go. Yes, this is one of the steps in our task sequence when we image a new laptop. Out of the 40 we imaged recently, about 30 of them had this happening. I can reproduce it in VMs as well. The strange thing is when it sticks, it sticks for good. Even if I delete and set it again, it seems to work every time afterward.

AmirTerani commented 9 months ago

I spoke too soon. Just got the same issue but with HTTP this time. I'll let you know if it happens with any of the file types as well. Thank you for looking in to it.

Danyfirex commented 9 months ago

I don't have access to Windows 11 right now. but I'll try with some virtual machines soon. Please paste the exactly command you're using here.

AmirTerani commented 9 months ago

Sure thing. We are using a vanilla Win11 Enterprise 22H2 installation, fully updated and patched, before getting the latest Chrome and Adobe Reader installed on it.

You should be able to reproduce it by running the {Set-PTA ChromeHTML https} and then opening System Settings to check for it. If you are using a VM, make sure to create a checkpoint/snapshot right before running the command for the first time so if it worked fine, you can revert back to it and repeat it until it fails.

We started off with this code:

Set-FTA Acrobat.Document.DC .pdf Set-PTA ChromeHTML http Set-PTA ChromeHTML https Set-FTA ChromeHTML .htm Set-FTA ChromeHTML .html

But to get around the issue, so far that simple 5 liner has evolved to this:

`Start-Process ms-settings:defaultapps?registeredAppMachine=Google%20Chrome

Sleep 15

$i=0 Do{ Set-FTA Acrobat.Document.DC .pdf $i++ Sleep 15 } While ((Get-FTA .pdf) -ne "Acrobat.Document.DC" -or $i -ge 6) Write-Host "[$(Get-Date -Format 'MM-dd-yyyy HH:mm:ss.fff')] Got $(Get-FTA .pdf) set as the Default App for .pdf files on try #$i."

$i=0 Do{ Set-PTA ChromeHTML http $i++ Sleep 15 } While ((Get-PTA http) -ne "ChromeHTML" -or $i -ge 6) Write-Host "[$(Get-Date -Format 'MM-dd-yyyy HH:mm:ss.fff')] Got $(Get-PTA http) set as the Default Protocol for http on try #$i."

$i=0 Do{ Set-PTA ChromeHTML https $i++ Sleep 15 } While ((Get-PTA https) -ne "ChromeHTML" -or $i -ge 6) Write-Host "[$(Get-Date -Format 'MM-dd-yyyy HH:mm:ss.fff')] Got $(Get-PTA https) set as the Default Protocol for https on try #$i."

$i=0 Do{ Set-FTA ChromeHTML .htm $i++ Sleep 15 } While ((Get-FTA .htm) -ne "ChromeHTML" -or $i -ge 6) Write-Host "[$(Get-Date -Format 'MM-dd-yyyy HH:mm:ss.fff')] Got $(Get-FTA .htm) set as the Default App for .htm files on try #$i."

$i=0 Do{ Set-FTA ChromeHTML .html $i++ Sleep 15 } While ((Get-FTA .html) -ne "ChromeHTML" -or $i -ge 6) Write-Host "[$(Get-Date -Format 'MM-dd-yyyy HH:mm:ss.fff')] Got $(Get-FTA .html) set as the Default App for .html files on try #$i."

Sleep 15

Get-Process SystemSettings -ErrorAction SilentlyContinue | Stop-Process`

Please let me know if I can help.

Thanks again, @-

mrmattipants commented 9 months ago

As soon as you mentioned that this was occurring on newly imaged machines, I recalled running into this issue myself, in the past.

Unfortunately, this is not a new issue, as I even ran into this problem with the "SetUserFTA.exe" Tool, a couple years back.

From what I've been able to gather, the Registry Keys/Values for the File Type Association, that you are attempting to Update, need to already exist, before they can be updated.

I'm not sure if the Developers of PS-SFTA have accounted for this issue, but the Developer of "SetUserFTA" has acknowledged this Issue (in the Comments Section, on his site).

When I have some free-time I'll do some testing, to see if I can re-produce your issue.

The Application that I personally ran into problems with was MODI (Microsoft Office Document Imaging), when attempting to Set the File Type Associations for .TIF and .TIFF.

I'll see if I can re-produce those results, with the current version PS-SFTA, as well.

Danyfirex commented 9 months ago

Try with SetUserFTA too to be sure if you get same result.