DanysysTeam / PS-SFTA

PowerShell Set File Type Association
253 stars 53 forks source link

No system-wide defaults set #26

Open ZeroIchiro opened 1 year ago

ZeroIchiro commented 1 year ago

We are using this script embedded into our own script for deployments, and so far it works, when we run it in user context. However, so far, we are unable to change the File Associations systemwide for all users. Is there a way to achieve this or is this script "just not made" for this type of usage?

Danyfirex commented 1 year ago

Hello, It was designed to run from the current user. So It does not have a switch for handle wide system(I thought to add it time ago but never get time/a chance to work on it but You can edit script by yourself to work in MACHINE Registry Keys). Or You could probably use common remote execution if you're in a domain.

If You are not part of a domain the only way I can think right now to handle it is like this:

$username = 'Test'
$password = '123456'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword

$scriptBlock = {
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/DanysysTeam/PS-SFTA/master/SFTA.ps1'))
    Set-FTA "ChromeHTML" ".pdf" -Verbose #set chrome as default .pdf reader
}

Start-Job -ScriptBlock $scriptBlock -Credential $credential | Wait-Job | Receive-Job