Visual Basic: Extract the Target file from a shortcut file .lnk Tutorial
Here’s a tutorial for using Visual Basic to extract the target file from a shortcut file. This is helpful when you have shortcuts that point to a folder where a new file has been added since the last time you checked.
What is a shortcut file?
A shortcut file is a file that contains a list of shortcuts that you can use to open files or folders. When you double-click a shortcut file, Windows launches the programs in the list, exactly as if you had typed the full path to the file or folder.
If you want to delete a shortcut file, right-click it and choose ‘Remove Shortcut.’ Add a shortcut file to the Desktop. Right-click an empty area on the desktop and choose New > Shortcut.
In the ‘Type’ text box, type a name and then press Enter. In this example, we will call our new shortcut file My JPG Files. In the ‘Location’ text box, type %USERPROFILE%DesktopMy JPG Files (make sure you include the double backslashes at the end of your filename) and then press Enter again.
Right-click on MyJPGFiles and select Properties from the popup menu. Leave all the settings as they are. Now enter the following commands in the ‘Target’ field: Click Finish. Right-click on MyJPGFiles again and select Properties from the popup menu.
The dialog will now look similar to this: Click OK and then click Close. Select the desktop shortcut to MyJPGFiles and right-click it, choose Properties. Check the ‘Start In:’ field, select your default folder (usually C:Program Files), click Apply, then click OK to close the properties window.
Now you can open JPG files with your new icon!
Extracting the target file using VB
In this tutorial, we will show you how to extract the target file from a shortcut file. This can be useful if you want to use the shortcut file without the associated file.
To start, open up a new VB project and create a new shortcut file. Right-click on the shortcut and select ‘Create Shortcut’. Name the shortcut ‘ExtractFile.lnk’ and click on OK. Next, open up the ‘ExtractFile.lnk’ shortcut in Visual Studio and add the following code:
Sub ExtractFile() ‘ Extracts the target file from the shortcut Dim objShell As Shell Set objShell = CreateObject(‘WScript.Shell’) Dim fso As Object Set fso = CreateObject(‘Scripting.FileSystemObject’) Dim strPath As String strPath = Me.FullName If (InStr(1, strPath, ‘.lnk’)) > 0 Then fso.CopyFile(Me.Clipboard, _ objShell.GetTempFolder & ‘argetfile.txt’, True) Else MsgBox ‘The path to the .lnk file is not correct!’ End If End Sub
Next, right-click on the ‘ ExtractFile’ shortcut in the Visual Studio project. Select ‘Properties’ from the menu. On the ‘Shortcut’ tab, locate the Target field and click on it to select.
Add the following:Target: %ProgramFiles%Microsoft SDKsWindowsv7.1BINmspdbengine.exe
This will tell Windows where your mspdbengine.exe is located so that MSBuild will be able to find it to process its build instructions contained within its manifest file.
Close the Properties window and return to Visual Studio if you haven’t already. Press F5 to compile your solution. (Note: If you don’t have a desktop with a shortcut on it, create one by right-clicking on the Visual Studio icon and choosing ‘Create Shortcut’.)
You should be able to now run the mspdbengine.exe from your application’s shortcut in Visual Studio.
How to extract the target file from a shortcut
In this tutorial, we will show you how to extract the target file from a shortcut. A shortcut is a file that contains the path to a program or document. When you double-click a shortcut, Windows takes you to the location where the shortcut was created. Sometimes, you may want to extract the target file from a shortcut.
To do this, follow these steps:
1. Right-click on the shortcut and select Properties from the menu.
2. In the Properties dialog box, click on the Location tab.
3. In the Location field, type the full path to the target file that you want to extract.
4. Click on OK to save your changes and close the Properties dialog box.
5. Right-click on the shortcut again and select Uninstall from the menu. The target file will be deleted from your computer.
6. The installed shortcut will be removed from the Start menu and Control Panel. When you select a file that is part of a shortcut, Windows displays the contents of the shortcut in its default view mode (i.e., it shows all the shortcuts contained in the folder).