Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,814,238 Members 49,053 Now Online
XDA Developers Android and Mobile Development Forum

Custom 'Desktop (create shortcut)' - Remove .fileextension - Shortcut

Tip us?
 
Jarmezrocks
Old
(Last edited by Jarmezrocks; 5th May 2014 at 03:00 PM.)
#1  
Jarmezrocks's Avatar
Senior Member - OP
Thanks Meter 453
Posts: 926
Join Date: Mar 2011
Location: Gold Coast

 
DONATE TO ME
Default Custom 'Desktop (create shortcut)' - Remove .fileextension - Shortcut

Hi guys n girls,

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

Problem/Issue
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.



Solution
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.
https://www.virustotal.com/en/file/6...is/1398978188/

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

Code:
#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: 3.3.10.2
 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[0]], "", -1)
EndFunc   ;==>RemoveExt

Func RemoveExtRegExp($Input)
	Return StringRegExpReplace($Input, "\.[^.]*$", "")
EndFunc   ;==>RemoveExtRegExp

Func GetFileName($Input)
	Local $PathArray = StringSplit($Input, "\/")
	Return $PathArray[$PathArray[0]]
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
Attached Thumbnails
Click image for larger version

Name:	screen1.jpg
Views:	197
Size:	56.9 KB
ID:	2726951   Click image for larger version

Name:	screen2.jpg
Views:	194
Size:	89.9 KB
ID:	2726952  
"Hey! What is this?" \_(ツ)_/

help find a cure for Narcolepsy
donations to this cause do not come directly to me, they are
anonymous but please tell me so I can give you thanks
 
GoodDayToDie
Old
#2  
Recognized Developer
Thanks Meter 2,699
Posts: 5,682
Join Date: Jan 2011
Location: Seattle
Thanks for sharing. I can't say I've ever actually done this - leaving aside the fact that I don't use the desktop to store things much, if I were to do so I'd be more likely to use mklink instead of the context menu (I use the command line *way* more than I use any Metro app, and nearly as much as I use the desktop with a mouse) - but it's good to have solutions, and it'll probably help somebody. I just tried creating such a shortcut and I agree the added name stuff is annoying.
Win8/Windows RT projects:
List of desktop apps for hacked RT devices

WP8 projects:
Native Access WebServer and Libraries
WP8 Interop Unlocks
Storage Cleanup tool

WP7 projects:
XapHandler, Root Webserver, OEM Marketplace XAPs, Bookmarklets collection (Find On Page), Interop-unlock hacks.


Do not private message me with questions that should have been posted on the forum! Not only are you wasting your time - I'm not going to bother writing an answer to such a question for only one person - but I will probably block you from PMing me in the future as well.
 
Jarmezrocks
Old
#3  
Jarmezrocks's Avatar
Senior Member - OP
Thanks Meter 453
Posts: 926
Join Date: Mar 2011
Location: Gold Coast

 
DONATE TO ME
Thanks mate

Well, I tend to post things more so for the discovery. To me it was more fascinating working out the code to use to solve the issue rather than the issue it's self. Like when you think about it, the research and time that went into developing the code to generate the shortcuts to save time probably took longer than what it would take to correct a million shortcuts....but that's beyond the point. IMHO we as people should change how we do things if we learn that there is a better way. It takes sharing your discoveries with others before the true benefits are realised.
"Hey! What is this?" \_(ツ)_/

help find a cure for Narcolepsy
donations to this cause do not come directly to me, they are
anonymous but please tell me so I can give you thanks
 
Uncle Scrooge
Old
#4  
Uncle Scrooge's Avatar
Junior Member
Thanks Meter 3
Posts: 13
Join Date: Mar 2013
There is a long-known small software that allows you to do just what you wanted and more, with a simple and user-friendly GUI.

You can find it on google looking for "vista shortcut overlay manager" aka fxvisor.
It allows you to replace or remove the arrow on the shortcut icons and to remove the "- Shortcut" extension, permanently (you can uninstall the program after you've done".

It was originally designed for Windows Vista, but works just great even on 7 and 8/8.1. Just download it accordingly to your 32 bit or 64 bit Windows version (32 bit version doesn't work on Windows-x64 and vice-versa).

 
Jarmezrocks
Old
(Last edited by Jarmezrocks; 14th May 2014 at 07:47 PM.)
#5  
Jarmezrocks's Avatar
Senior Member - OP
Thanks Meter 453
Posts: 926
Join Date: Mar 2011
Location: Gold Coast

 
DONATE TO ME
Quote:
Originally Posted by Uncle Scrooge View Post
There is a long-known small software that allows you to do just what you wanted and more, with a simple and user-friendly GUI.

You can find it on google looking for "vista shortcut overlay manager" aka fxvisor.
It allows you to replace or remove the arrow on the shortcut icons and to remove the "- Shortcut" extension, permanently (you can uninstall the program after you've done".

It was originally designed for Windows Vista, but works just great even on 7 and 8/8.1. Just download it accordingly to your 32 bit or 64 bit Windows version (32 bit version doesn't work on Windows-x64 and vice-versa).


This only does what the registry edit above does. It still does not replace the file extension attached on the end. And one may as well edit for one as they would do for all. Back to square 1. Thanks for the pointer though I did already know about these guys and have used their app before, some other forum member might find this valuable.
"Hey! What is this?" \_(ツ)_/

help find a cure for Narcolepsy
donations to this cause do not come directly to me, they are
anonymous but please tell me so I can give you thanks
 
Uncle Scrooge
Old
#6  
Uncle Scrooge's Avatar
Junior Member
Thanks Meter 3
Posts: 13
Join Date: Mar 2013
I don't understand.
The "Vista Shortcut Manager" program worked for me, on my Windows 8.1 32 bit.

It DOES remove the "- Shortcut" extension when I create desktop shortcuts.
 
Jarmezrocks
Old
#7  
Jarmezrocks's Avatar
Senior Member - OP
Thanks Meter 453
Posts: 926
Join Date: Mar 2011
Location: Gold Coast

 
DONATE TO ME
Quote:
Originally Posted by Uncle Scrooge View Post
I don't understand.
The "Vista Shortcut Manager" program worked for me, on my Windows 8.1 32 bit.

It DOES remove the "- Shortcut" extension when I create desktop shortcuts.

Aggggghhhhhh DW

What I meant was...


What about the file extension?

notpad.exe normally goes to -> notepad.exe - Shortcut

With "Vista Shortcut Manager" (the same registry edit mentioned by another member)

notepad.exe goes to -> notepad.exe

I still then need to double long click or right click shortcut properties and remove .exe from the end.

What I want then is this

notepad.exe goes to -> notepad

"Vista Shortcut Manager" doesn't remove the .exe off the end of the shortcut it created, it only removes "- Shortcut" from the end. In other words, if one has to go to the shortcut created, right click and edit the shortcut and remove ".exe" or (insert any file extension here) then what is the point?
If I have to edit the shortcut to do that, then I may as well edit the shortcut to remove ".exe" AND "- Shortcut" at the same time! The idea behind this was to create shortcuts that require no additional 'touch ups' no edits or changing in anyway.

If you're happy to have the file extension left on the end of the file you created a shortcut from then that's fine; this is probably not aimed at you.

But yes thank you for pointing out that helpful app for other people that want the functionality without needing to know why/how etc.....which kind of goes against what XDA is all about. XDA is about developers sharing code, ideas, mods to various devices and computers that we can test, trial, give feedback, improve or just plain use in everyday life.
Again....this isn't specifically about the shortcut nor the desklink applet that creates them, this is more about the code that I posted, and how it 'could' potentially assist other developers who are doing something of their own that might be using say hmm get file extension of some file....say a smali file (which is denoted by a 4 character length as opposed to the more traditional 3 character length like apk) and allowing developers to "recycle" a single function that works for all file extensions rather than write a block of code for each instance. They may do this using AutoIT, or they may look at my code and see how this can be translated (with ease) to work with other languages such as C# and so forth.
Anyway I hope this makes more sense to you now?
"Hey! What is this?" \_(ツ)_/

help find a cure for Narcolepsy
donations to this cause do not come directly to me, they are
anonymous but please tell me so I can give you thanks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes