I am not sure if this is even relevant on here or not? But I figured I should share anyway. Like I mean I don't know how many of you guys use your desktop now that there is the start screen? Or how many of you even use right click menu much but for myself right click is the most used functionality I use in Windows and quite frankly come to expect from other IT systems (web, Linux etc) so this may or may not apply.
I have for ever got sick and tired of right click -> open Send to Menu and creating a Desktop Shortcut for a file or app....then needing to go to the Desktop right click the newly made shortcut and then removing the trailing file extension, dash and words shortcut in brackets. If you are like me and you want a solution where you just right click -. Create shortcut and forget and not need to do anymore then look no further.
I have small AutoIT app (compiled script) that does exactly that.
Desktop (create shortcut).au3 SHA1 - 630A9CE23BF669035EEB089C2948BBD8B38BB505
Desktop (create shortcut).exe SHA1 - 829518AD4233E59D686822D960AAC71405D57CCD
Desktop (create shortcut).ico SHA1 - 16239287978841199F8A2FC56AA36EE55F197083
Download Link Desktop (create shortcut).zip
Virustotal readout - God knows why anyone would use any of the virus scanners flagging AutoIT as a virus. This indicates to me that they are merely only searching for header info and not actually decyphering any of the code. That should be alarming to anyone. Anyway here it is, it gets 2 false negatives out of 52.
Now the code so that you can compile it all your self. For the Geeks in other words
I have commented each part so that those of you just learning or getting a grasp of AutoIT can understand. It is really quite simple however it does take in to consideration a lot of things which many .au3 script writers tend to neglect, such as returning of the proper file extension does not mean StringTrimRight($filename, 4), as it doesn't account for long extension names nor does stopping at a period/point/fullstop.....what happens when a directory has a period? What about names of files that have other periods such as This.is.an.example.file.name.au3
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Desktop (create shortcut).ico #AutoIt3Wrapper_Outfile=Desktop (create shortcut).exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 18.104.22.168 Author: Jarmezrocks Script Version: 1.0 Script Function: The purpose of creating this was due to an annoyance with Windows 7 where I was constantly editing the shortcuts created from the right click 'Send To' create 'Desktop (create shortcut)' where I would need to remove the junk that Microsoft attached as a postfix i.e. - (short cut) and remove the file extension as well. E.g. Notepad.exe -> creates a shortcut 'Notepad.exe - (shortcut)' when what I really wanted created was a shortcut called 'Notepad' This AutoIT script was created to solve this issue/annoyance. Usage: Place the compiled exe where ever you like (here's the inception part LOL) right click the compiled exe and create a shortcut (remember you won't have to do this ever again haha) rename it 'Desktop (create shortcut)' the same as the Desktop (create shortcut).Desklink item in the Send To menu. Locate your Send To menu: Start -> Run -> type this: shell:sendto -> press enter This opens the directory for your Send To items, likely located somewhere like C:\Users\<User Name>\AppData\Roaming\Microsoft\Windows\SendTo Paste the shortcut to the exe here Note: You will now have a duplicate in the Send To menu, so I advise that you hide the old .Desklink item Right click -> File Properties -> Hidden Done! Test by Right clicking any file and choosing Send To -> Desktop (create shortcut) Acknowledgements: AutoIT Forums; User Harlequin for this post/thread -> http://www.autoitscript.com/forum/topic/86839-how-get-file-extension/#entry623386 User Voodooman for this post/thread -> http://www.autoitscript.com/forum/topic/122807-remove-extension-from-the-filenameexample/?p=1110846 Future plans: Following versions (still testing - *I have a bug I need to iron out) should allow the user to double click the executable and Choose to install it to the Send To context menu and automate the part outlined above in the usage section (hide the old desklink) and create a shortcut of it's self. It should do checking so that if the user double clicks the exe again it checks for either the existing Desklink extension or the shortcut.lnk and prompt the user if they want to remove it and restore the original Windows functionality. #ce ---------------------------------------------------------------------------- Global $Input = $CmdLineRaw ; Obtain the selected file full path (name of file and location) as a string parsed as a command line parameter i.e %1 Global $LinkFileName = RemoveExt(GetFileName($Input)); Generate the file name from the input using the following functions ; These are pretty self explained - Thanks Voodooman (You may have necro-bumped an expremely old thread created by n00b years before who has now become a developer but we all forgive you - your post is valid) Func RemoveExt($Input) Local $ExtArray = StringSplit($Input, ".") Return StringReplace($Input, "." & $ExtArray[$ExtArray], "", -1) EndFunc ;==>RemoveExt Func RemoveExtRegExp($Input) Return StringRegExpReplace($Input, "\.[^.]*$", "") EndFunc ;==>RemoveExtRegExp Func GetFileName($Input) Local $PathArray = StringSplit($Input, "\/") Return $PathArray[$PathArray] EndFunc ;==>GetFileName ; Importance of the following. As pointed out by Harlequin using any StringRightTrim methods of obtaining the extension doesn't account for several things ; "." can located in the path of a folder name and "." can appear more than once within files or folders i.e What would one do when trying to return ; the extension of a html file or any other long extension file type? Func CreateLink() If $CmdLineRaw Then ;Check if it's a command parameter i.e. %1 or path to the file you want a shortcut made for For $YLoop = StringLen($CmdLineRaw) To 1 Step -1 ; Loop through the all of the "." in the path and string from the last "." If StringMid($CmdLineRaw, $YLoop, 1) == "." Then $Ext = StringMid($CmdLineRaw, $YLoop) ; Generate the extension type $YLoop = 1 EndIf Next Local $Type = RegRead("HKEY_CLASSES_ROOT\." & $Ext, "") ; Look up the type from the registry to find the application Local $FileName = $CmdLineRaw Local $LnkFileLocate = (@DesktopDir & "\" & $LinkFileName & ".lnk"); Here is the working part - Generate the Desktop shortcut from the derived file name Local $WorkingDirectory = "" Local $Icon = RegRead("HKEY_CLASSES_ROOT\" & $Type & "\DefaultIcon", ""); Derive the file type icon from the registered application Local $IconNumber = 1 Local $Description = "" ; I decided to leav this blank Local $State = @SW_SHOWNORMAL ;Can also be @SW_MAXIMUM or @SW_SHOWMINNOACTIVE or even @SW_HIDE If Not FileExists($LinkFileName) Then ;Check there isn't already as shortcut FileCreateShortcut($FileName, $LnkFileLocate, $WorkingDirectory, "", $Description, $Icon, "", $IconNumber, $State); Generate the shortcut EndIf EndIf EndFunc ;==>CreateLink CreateLink() ; Execute the Function