Sinisterly
Tutorial [Serenity] Adding scripts to context menu (Windows) - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Computers (https://sinister.ly/Forum-Computers)
+--- Forum: Software & Programs (https://sinister.ly/Forum-Software-Programs)
+--- Thread: Tutorial [Serenity] Adding scripts to context menu (Windows) (/Thread-Tutorial-Serenity-Adding-scripts-to-context-menu-Windows)



[Serenity] Adding scripts to context menu (Windows) - Inori - 01-03-2016

I haven't slept in 24 hours, so naturally, I've learned a shitton and decided to post some of my info here. It's a quick tut, but I'll be outlining how to add custom scripts to your right click, or context, menu through editing registry keys.

First, open up a shell of your choice and run the regedit command. You'll get an admin prompt, so accept and continue.

From here, there's a choice we need to make. If you want a static command that shows up when clicking on your desktop, navigate to the following key:
Code:
HKEY_CLASSES_ROOT\Directory\Background\shell\

After you're there, create a key named whatever you want the menu item to be, in this case, Steam (because I'm a fucking nerd).
After you've made the key, create a subkey named whatever you want, though I find "command" works well for organization.
Once you've made that, edit the subkey's default REG_SZ value to the full file path of whatever static program you're running.
[Image: TZt0kDO.png][Image: cHp19cL.png][Image: W5yD3yK.png]

Elsewise, if you want the real shit, which is running a dynamic script like the one I'm detailing here (which I'll post in another thread) that takes arguments, navigate to:
Code:
HKEY_CLASSES_ROOT\*\shell\

Once there, go through the same key/subkey creation I outlined in the static method. The only difference is the REG_SZ key's value. Instead of something arbitrary like the steam path, you can run, say, a python script using the below value:
Code:
C:\Python27\python.exe "C:\Users\-\Desktop\Code\-\-\pomfloader.pyw" %1

The reason we need the full path to everything is because the registry has no access to your PATH environment variable, which is what lets you execute python files with just "python script.py".
The second argument, the script's path name, should be in quotes, but doesn't need to be. Just good practise.
The final argument, %1, is Window's version of sys, or process, .argv[1]. Normally, it would stand as a command line argument, but in this case identifies as the selected file, which is convenient. To implement that in your code, just use the aforementioned argv array.
[Image: e3pPCsd.png][Image: t2SU9Ua.png][Image: ggIK4Dk.png]


RE: [Serenity] Adding scripts to context menu (Windows) - Megan - 01-03-2016

Excellent tut, looking forward to seeing what else Serenity will put out.


RE: [Serenity] Adding scripts to context menu (Windows) - Nil - 01-03-2016

Very cool. Very cool indeed. Thanks.


RE: [Serenity] Adding scripts to context menu (Windows) - Bish0pQ - 01-03-2016

This looks very good, I will be testing this tomorrow on my Desktop. Thanks for sharing.


RE: [Serenity] Adding scripts to context menu (Windows) - mothered - 01-04-2016

This does In fact work, I've tested It out many years ago.

Prior to editing the registry, I recommend backing It up using the registry's "Export" feature. Any Incorrect editing of critical keys and/or values, may cause significant system Instability and/or loss of functionality.

A very well formatted, elaborated and Illustrated tutorial.
Good job.