Jump to content

Trying to pass command-line parameter to another application


BGrigg
 Share

Recommended Posts

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

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

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...