Jump to content

Open a file with an autoit compiled script thru windows context menu


careca
 Share

Go to solution Solved by MHz,

Recommended Posts

Hi ppl, got a problem and am kinda lost, the objective is to right click an mp3 file in windows, and have the context menu entry to open with my player, is this integration where im lost, i was thinking that maybe i could make the script grab the file location by clipboard operations, and then use that to start playback, but it's this integration where im lost, because as soon as i start the player it may load the list automatically, i mean, how can i make it detect that it is starting from a context menu entry, how can i tell it is not a "normal" startup?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Ok so this is sort of what i need:

[HKEY_CLASSES_ROOT\*\shell\BPlayer]
"MUIVerb"="BPlayer"
"SubCommands"="Play;List"
"icon"="C:\\Windows\\BPlayer\\BPlayer.ico"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Play]
@="Play"
"icon"="C:\\Windows\\BPlayer\\BPlayer.ico"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Play\command]
@="C:\\Windows\\BPlayer\\Beats Player 1.6.exe /P"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\List]
@="Add to list"
"icon"="C:\\Windows\\BPlayer\\BPlayer.ico"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\List\command]
@="C:\\Windows\\BPlayer\\Beats Player 1.6.exe /L"
If $CmdLine[1] = "/P" Then
    ;Send("^c")
    ;Sleep(50)
    ;$File = ClipGet()
    ;MsgBox(64, 'clipboard', $File)
    Exit
ElseIf $CmdLine[1] = "/L" Then
    Exit
EndIf

What i need now is to grab the path of the clicked item.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • Solution

Hi careca,

I have some concerns why you are using the Windows directory. My example is not going there. :ermm:

Another is writing to HKCR. This is a merged root key created for easy reading of classes. It is not a good idea to write to it.

2 keys exist for writing classes are

  • HKCUSOFTWAREClasses
  • HKLMSOFTWAREClasses

Writing to HKCR can mess things up as it does not know to which of those 2 above paths that it is writing to. :

Notice in the CommandStore that keys are listed as for e.g. Windows.playmusic. This is done so keys are unique. So may I suggest you follow with a similar naming scheme. :idea:

This is a regfile that I tested with

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\BPlayer]
"MUIVerb"="BPlayer"
"SubCommands"="BPlayer.Play;BPlayer.List"
"icon"="C:\\BPlayer\\BPlayer.ico"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\BPlayer.Play]
"MUIVerb"="Play"
"icon"="C:\\BPlayer\\BPlayer.ico"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\BPlayer.Play\command]
@="\"C:\\BPlayer\\Beats Player 1.6.exe\" /P \"%1\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\BPlayer.List]
"MUIVerb"="Add to list"
"icon"="C:\\BPlayer\\BPlayer.ico"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\BPlayer.List\command]
@="\"C:\\BPlayer\\Beats Player 1.6.exe\" /L \"%1\""

This is the script that was compiled as "Beats Player 1.6.exe" to test with

Global $action, $file_to_play
If $CMDLINE[0] Then
    For $1 = 1 To $CMDLINE[0]
        Switch $CMDLINE[$1]
            Case '/P'
                $action = 'play'
            Case '/L'
                $action = 'list'
            Case Else
                If FileExists($CMDLINE[$1]) Then
                    $file_to_play = $CMDLINE[$1]
                EndIf
        EndSwitch
    Next
EndIf

MsgBox(0, @ScriptName, _
    '$action = ' & $action & @CRLF & _
    '$file_to_play = ' & $file_to_play & @CRLF _
)

If I right click on "Beats Player 1.6.exe" and select BPlayer -> Play from the context menu then I get a Msgbox with this

---------------------------
Beats Player 1.6.exe
---------------------------
$action = play

$file_to_play = C:\BPlayer\Beats Player 1.6.exe


---------------------------
OK   
---------------------------

In the registry, %1 is replaced with the path of the highlighted file from explorer. This is how you get the path. :)

Link to comment
Share on other sites

Thanks for the input, the objective is to right click on audio files and open them with the player,

not right click on the player exe, so how should i use the %1? as a parameter?

I need to pass the highlighted files to the player, that's where im stuck.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

You associated it with * key in classes in the 1st post which is any file type and my using right click on "Beats Player 1.6.exe" is just an example of a file chosen. You can see in the regfile content that I posted that "%1" is in it that gets added to the registry. The registry automatically does a substitution with %1 with the file path when you click the entry in the context menu. The substitution of "%1" is the 2nd parameter passed to the script which in my example is the value that $file_to_play is assigned to.

Link to comment
Share on other sites

Ok, so i discarted the /L parameter, and grabbing some ideas of yours, ended up with this:

If $CmdLine[1] = "/P" Then
    If FileExists($CmdLine[2]) Then
        $array4 = StringLen($CmdLine[2])
        $array3 = StringInStr($CmdLine[2], "\", 0, -1)
        $array2 = $array4 - $array3
        $SubTextFolder = StringTrimRight($CmdLine[2], $array2)
        $SubTextFile = StringTrimLeft($CmdLine[2], $array3)
        GUICtrlCreateListViewItem('1' & '|' & $SubTextFolder & '|' & $SubTextFile, $cListView)
        GUICtrlSetState(-1, $GUI_FOCUS)
        $FileT = $SubTextFolder & $SubTextFile
        Play()
    EndIf
EndIf

The line is registry is:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Play\command]
@="C:\\Windows\\BPlayer\\Beats Player 1.6.exe /P "%1""

Now to complete this, it would be nice if i was able to keep the player open, and whenever i clicked from the context menu,

it could open the files in the same window, instead of it opening a new instance of the player everytime.

know what i mean?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Personally, if you want to play safe, I'd stick to using .mp3 instead of * in your classes entry, but you really need to understand what you are doing when playing with the Registry.

You will probably find there are one or more entries already for programs that play mp3's.

You wouldn't want to corrupt one of them, but just add your own, possibly making it the default, or a right-click context menu entry, like 'Play with Careca player'.

There would be plenty of examples for players and associations in the Examples & Helps section of the forum.

Before playing with the Registry, which can be really dangerous and potentially Nuke your system, I would do some study on it.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I appreciate ya'll concerns with my pc, but, let's focus on the actual issue. :P

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

To open in the same window then you are going to need to be creative. Some use a shell extension dll to handle this. Or perhaps you could use communication with the current running script and the one being started. I have no simple solution to handle this. A number of examples exist in the forums for script communication which you could look at. :)

Link to comment
Share on other sites

Thank you for your help.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

I appreciate ya'll concerns with my pc, but, let's focus on the actual issue. :P

That is totally up to you of course, but your comments have shown that you have a limited understanding of the Registry.

To save you from some potentially big issue, to solve your little issue, I gave you some advice.

Which is yours to take, only if you wish.  o:)

P.S. And I'm not impeding MHz quality help, so should be no problem.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I took the advice, and wrote to HKLMSOFTWAREClasses, so no need to worry, i understand the concerns,

but i was just much more worried on how to make the script work the way i intended.

Greetz

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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...