0

I have an .exe application written in vb.net. When I make shortcuts to the application, say on desktop (or anywhere else) and then click on them I want to programatically get the path to that shortcut, ie. C:/Users/xxx/Desktop/shortcut.lnk.

I want this so I can store the pairs shortcuts : (program + different cmd args).

okkko
  • 1
  • 1
  • Have you seen this other question: http://stackoverflow.com/questions/1125958/how-do-i-discover-how-my-process-was-started ? – Rowland Shaw Jun 01 '10 at 10:05
  • Now I have, but still don't know how to get what I want. Dim pc As PerformanceCounter = New PerformanceCounter("Process", "Creating Process ID", Process.GetCurrentProcess.ProcessName) Dim sDic As Specialized.StringDictionary = Process.GetProcessById(CType(pc.NextValue, Integer)).StartInfo.EnvironmentVariables I tried this and no value in sDic contains "Desktop" (I put a shortcut to my desktop). – okkko Jun 01 '10 at 13:16
  • From http://msdn.microsoft.com/en-us/netframework/aa569609.aspx#Question5: System.WMI Win32_Process has a field CommandLine. Please refer to the MSDN documentation for details about this class. I looked into it a bit but it seems to complicated/don't know how to do it.. – okkko Jun 01 '10 at 13:36

1 Answers1

1

Your desktop wouldn't be the parent process since it's not a process, I assume explorer or something would be if it's started from a shortcut.

The easiest way to get what you want would be to change the shortcuts to send in some parameter to your app when it starts it. So for example, the shortcut on the desktop could send in the string "desktop". Then you could just pick it up as a normal command line parameter.

If you've declared a Main function as:

Public Shared Sub Main(ByVal args As String())

Then it would appear as one of the strings in the args parameter.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • Much simpler, then you don't have to change your exe when you add a new shortcut to the system. – Greg B Jun 02 '10 at 08:11