Open a script via the context menu

Antworten
Gernot
Beiträge: 17
Registriert: 21 Mär 2021, 15:53

Open a script via the context menu

Beitrag von Gernot »

I want to run the min.vbs script when I open a file with Visual Studio Code from the Windows context menu (open with ...). Can anyone tell me how to adjust the following statement block to do this?

Code: Alles auswählen

[LinkFolder_CommonStartmenu]
set_basefolder common_startmenu
set_link
  name: "Visual Studio Code"
  target: %ProgramFilesSysNativeDir%\Microsoft VS Code\script\min.vbs
  icon_file: %ProgramFilesSysNativeDir%\Microsoft VS Code\Code.exe
end_link
Benutzeravatar
SisterOfMercy
Beiträge: 1524
Registriert: 22 Jun 2012, 19:18

Re: Open a script via the context menu

Beitrag von SisterOfMercy »

Uhm... Whiskey Tango Foxtrot.

The open with menu is not a context menu, this is a file association thing. A context menu entry would look like "open in Visual Studio Code".
Your linkfolder entry is also not correct. Don't forget the ""-signs, at least.

Let's start with the last thing. For a shortcut, you need to set the parameters of the shortcut. Don't forget to declare $InstallDir64$.

Code: Alles auswählen

[LinkFolder_install]
set_basefolder common_programs
set_subfolder ""
set_link
	name: "Visual Studio Code (open vbs file)"
	target: "$InstallDir64$\Code.exe"
	parameters: : "$InstallDir64$\script\min.vbs"
	working_dir: "$InstallDir64$"
	icon_file: "$InstallDir64$\Code.exe"
	icon_index: 0
end_link
To associate files with visual studio code you need to do something different. To do it machine wide:

Code: Alles auswählen

[Registry_install]
openkey [HKEY_LOCAL_MACHINE\Software\Classes\.vbs]
set "" = "Visual Studio Code Editor"

openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Visual Studio Code Editor]
set "" = "Visual Studio Code Editor"
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Visual Studio Code Editor\DefaultIcon]
set "" = '"$InstallDir64$\Code.exe"",1'
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Visual Studio Code Editor\shell]
set "" = "open"
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Visual Studio Code Editor\shell\open\command]
set "" = '"$InstallDir64$\Code.exe" "%1"'
But you should find a file that is already associated with visual studio code editor, then you only have to set it like this:

Code: Alles auswählen

[Registry_install]
openkey [HKEY_LOCAL_MACHINE\Software\Classes\.vbs]
set "" = "Name in hklm software classes that is already associated with Visual Studio Code Editor"
Adding a context menu, so that when you right click on a .vbs file, it shows "edit with visual studio code editor" you will have to add something like this. (I can't be bloody arsed to convert this)

Code: Alles auswählen

openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\icofile\shell\Edit with GIMP]
set "" = "Edit with GIMP"
openkey [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\icofile\shell\Edit with GIMP\command]
set "" = '"$InstallDir64$\bin\gimp-2.10.exe" "%1"'
Or so was it for windows 7. Have to test if that has changed. But anyway, machine wide file associations should still work like this. Per user is a shitshow.
Bitte schreiben Sie Deutsch, when I'm responding in the German-speaking part of the forum!
Antworten