?
Solved

Read/edit shortcut file in VB.Net 2005

Posted on 2007-07-23
6
Medium Priority
?
2,429 Views
Last Modified: 2013-11-26
I have a location to a shortcut file (.lnk) in a string variable

        Dim sAppShortcut As String = Registry.LocalMachine.GetValue(sKey & "\" & sGameID & "\AppExePath", "")

I need  to read it and grab the 'Target' .exe name into a string variable called sAppExePath2

Thanks
0
Comment
Question by:Ryan_R
  • 4
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
ToFro earned 500 total points
ID: 19554101
First you need to add a reference to Windows Script Host Object Model like this:
Project >> Add Reference >> COM >> Windows Script Host Object Model >> Ok

Then add the following import statement to your code:
Imports IWshRuntimeLibrary

After that some code like this should do the job:

Dim shortCutPath, exePath As String
Dim shell As New WshShell()
Dim link As IWshShortcut

shortCutPath = "C:\Documents and Settings\All Users\Desktop\MyShortcut.lnk"
link = shell.CreateShortcut(shortCutPath)
exePath = link.TargetPath
0
 
LVL 15

Author Comment

by:Ryan_R
ID: 19554399
Your code works - thanks.   125 points set aside for that.
If you can help me out with the following I'll double the points.


Here is a portion of code that I'm working with. For some reason - even though the returned exePath is correct (and testing it by shell-ing the exePath works too).

In short - despite the file existing on my PC - the If statment that checks ths later on fails - saying the file (exePath) doesn't exist.
Any thoughts?

------
 Dim sAppShortcut As String = Registry.GetValue("HKEY_LOCAL_MACHINE\" & sKey & "\" & sGameID, "AppExePath", "")
        Dim shortCutPath, exePath As String
        Dim sTemp3 As String = Mid(sAppShortcut, Len(sAppShortcut) - 3)
        If sTemp3 = ".lnk" Then
            Dim shell As New WshShell()
            Dim link As IWshShortcut

            shortCutPath = sAppShortcut
            link = shell.CreateShortcut(shortCutPath)
            exePath = link.TargetPath
            MsgBox("shortcut")
        Else
            exePath = sAppShortcut
        End If
        MsgBox(exePath)
        Shell(exePath)

        If My.Computer.FileSystem.FileExists(exePath) Then 'Registry.LocalMachine.GetValue(sKey & "\" & sGameID & "\AppExePath", "")) = False Then
            MsgBox("The executionable file for this game cannot be found. VGEE will not continue to load this game.", MsgBoxStyle.Critical, "File Not Found")
            MsgBox("VGEE did not add the new game.", MsgBoxStyle.Critical, "VGEE")
            blnError = True
            Exit Sub
        Else
            MsgBox("It's all good")
            blnError = True
            Exit Sub
        End If
------
0
 
LVL 15

Author Comment

by:Ryan_R
ID: 19554408
looks like I'm missing a "Not" in that If statment - easiest fixes are the best ones  :)
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 15

Author Comment

by:Ryan_R
ID: 19554415

Welcome to EE as well.
You're well on your way to being one of the top yearly experts in this zone  :o)
0
 
LVL 6

Expert Comment

by:ToFro
ID: 19554647
>Welcome to EE as well.
>You're well on your way to being one of the top yearly experts in this zone  :o)

Thanks mate. I registered just to see if I could accumulate enough points to qualify for the free premium membership, so that I could start asking questions. Turns out answering questions is quite an addictive pastime :)

Btw, the milestones on your profile page is a nice idea, I hope you don't mind if I borrow it?
0
 
LVL 15

Author Comment

by:Ryan_R
ID: 19555069
No that's fine - I *borrowed* it from someone too

I started answering Q's here too for the exact same reason as you - only 1 year ago - to fill in spare time
Of course - I never thought I would get 100,000 points or become a Cleanup Volunteer.

When the new Vista zone came out - I had a shot at that since I saw the top 15 list was quite low - and I've been 3rd for a long time now. Now that I've got my Guru cert I've turned off the email alerts so I don't get around to as many Q's as before.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question