BGrigg Posted December 16, 2022 Share Posted December 16, 2022 Hello, Ultimately I'm trying to change the file association of a file extension to the same app, but leveraging RunAs, so that every time the file extension is opened, it runs as a different user. But Windows doesn't support command-line parameters with file associations. So I figured I could script something with AutoIt, and then change the program to the AutoIt script (assuming the syntax that Windows uses is the same as it would be for command-line, application.exe file_path). My first step is to just see if I can get the script to run emulating the same exact behavior of the application, without even introducing the RunAs.exe into the equation. Then once I get that working, I'll start working on adding in the RunAs into it. I've tried a few different variations of the below, and then command-line would be: Notepad_Test.exe c:\test.txt. Run("C:\Windows\System32\notepad.exe ","$CmdLine[1]") Notepad opens up every time, but just with a blank file and not my Test.txt file. What am I missing? Link to comment Share on other sites More sharing options...
Subz Posted December 16, 2022 Share Posted December 16, 2022 Try: Run('C:\Windows\System32\notepad.exe "' & $CmdLine[1] & '"') Or ShellExecute("notepad.exe", $CmdLine[1]) Link to comment Share on other sites More sharing options...
BGrigg Posted December 16, 2022 Author Share Posted December 16, 2022 Nope, same result. Notepad opens but just with a blank file. Link to comment Share on other sites More sharing options...
ioa747 Posted December 16, 2022 Share Posted December 16, 2022 2 hours ago, BGrigg said: Nope, same result. Notepad opens but just with a blank file. check the result with ConsoleWrite($CmdLine[1] & @CRLF) I know that I know nothing Link to comment Share on other sites More sharing options...
Danyfirex Posted December 16, 2022 Share Posted December 16, 2022 make sure your cmdline has a correct path/value because this work for me: ShellExecute("notepad.exe", '"C:\Users\User\Desktop\Test.txt"') ShellExecute("notepad.exe", 'C:\Users\User\Desktop\Test.txt') Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Subz Posted December 16, 2022 Share Posted December 16, 2022 Tested both codes prior to posting, as @Danyfirex mentioned you need to check your paths, here is how I tested: C:\Temp\CompiledScript.exe C:\Temp\Test.txt Danyfirex 1 Link to comment Share on other sites More sharing options...
BGrigg Posted December 16, 2022 Author Share Posted December 16, 2022 PSA: Do not write scripts at night when overtired. (no, I'm not going to elaborate. 😉) Sorry to waste everyone's time with something STUPID on my end. Although I'm going to leave this open, as I'll post final result (with regards to RunAs and the default file association. Hoping that Windows won't have an issue with this process. Link to comment Share on other sites More sharing options...
rsn Posted December 16, 2022 Share Posted December 16, 2022 RunAs will set the association for the running user versus the logged in user unless you're setting it in HKLM. But the big caveat with HKLM is that the per user setting (HKCU) will override the per PC settings and Win10 will aggressively revert if the hash is missing or bad. Hash example here: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\UserChoice\Hash="LBtfCrcwPYW=" In my work environment, we use SetFTA.exe (found here) to generate that hash and set the association. A great example is the Win10 PCs reverting PDFs to Edge ( ! ) seemingly at random even when the user changes the association in Settings or via Acrobat Pro. Subz 1 Link to comment Share on other sites More sharing options...
Subz Posted December 16, 2022 Share Posted December 16, 2022 We also use a combination of SetFTA.exe and Group Policy for our file associations, common associations are set using GPO and SetFTA.exe for non-common associations. Link to comment Share on other sites More sharing options...
Danyfirex Posted December 16, 2022 Share Posted December 16, 2022 My Team wrote an AutoIt and PowerShell version for handle that. https://github.com/DanysysTeam/AutoIt-Scripts/tree/master/Scripts/SFTA https://github.com/DanysysTeam/PS-SFTA Saludos rsn and Subz 1 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now