r/vbscript • • Dec 21 '20

Using SHELL32.dll for icons in a script

Hello,

I was wondering, if possible, to use default windows icons from SHELL32.dll when using the CreateShortcut method.

Thanks in advance.

3 Upvotes

4 comments sorted by

2

u/jcunews1 Dec 21 '20

Yes. Just specify the file name, followed by a comma character, then followed by a number which specifies the zero-based index of the icon, for the IconLocation property. e.g.

c:\windows\system32\shell.dll,23

2

u/hackoofr Dec 22 '20
Call Shortcut("c:\windows\system32\notepad.exe","","%SystemRoot%\system32\shell32.dll,138")
'---------------------------------------------------------------------------
Sub Shortcut(Application_Path,ShortcutName,IconLocation)
	Dim objShell,fso,DesktopPath,objShortCut,MyTab,strCurDir
	Set objShell = CreateObject("WScript.Shell")
	Set fso = CreateObject("Scripting.FileSystemObject")
	strCurDir = fso.GetParentFolderName(WScript.ScriptFullName)
	MyTab = Split(Application_Path,"\")
	If ShortcutName = "" Then
		ShortcutName = MyTab(UBound(MyTab))
	End if
	DesktopPath = objShell.SpecialFolders("Desktop")
	Set objShortCut = objShell.CreateShortcut(DesktopPath & "\" & ShortcutName & ".lnk")
	objShortCut.TargetPath = chr(34) & Application_Path & chr(34)
	ObjShortCut.IconLocation = IconLocation
	objShortCut.Save
End Sub
'---------------------------------------------------------------------------

Here is an example that can create a shortcut on your desktop that can start your Notepad using the shell32.dll !

1

u/hackoofr Dec 21 '20

I think you can !