Author Topic: Finding an absolute path to a file via a shortcut.  (Read 3093 times)

0 Members and 1 Guest are viewing this topic.

mr_nick

  • Guest
Finding an absolute path to a file via a shortcut.
« on: September 22, 2008, 07:56:38 AM »
In the AutoCAD plotter manager, it is possible to drop a shortcut to a folder on a network drive containing additional pc3s, ctbs etc. AutoCAD then disregards the fact that the files aren't directly the plotter manager folder and deals with them as if they were. I have a little utility which I have used succesfully for extracting info related to the pc3s etc but it has always been used on my standalone setup where my files were directly in the folders and not via a shortccut which all worked perfectly as I need to an absolute path to the pc3 file for my utility to work. Now if I select a pc3 via my dialog box (a list populated using GetPlotDeviceNames) then it will give me the actual pc3 name but not the absolute path as it would be assumed it is directly in the plotter folder. This then means I can't put any files in a network folder without re-mapping the support folders. I know a lot of offices who prefer to add shortcuts to the plotter manager rather than remapping the support directory elsewhere so if at all possible I don't want to have to re-map anything. Instead I wonder if there is any way of getting an absolute path to a pc3 or ctb file that is located via a shortcut?

Can anybody offer a solution or a nudge in the right direction?

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Finding an absolute path to a file via a shortcut.
« Reply #1 on: September 22, 2008, 10:42:29 AM »
I have used a shortcut pointing to a network drive on local machines.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

mr_nick

  • Guest
Re: Finding an absolute path to a file via a shortcut.
« Reply #2 on: September 22, 2008, 10:49:23 AM »
Not sure what you're telling me here  :?

I think I may have now managed to crack it though by extracting the 'target' property from the .lnk in the plotter folder. This is then enough data for me to know the absolute path to the network pc3.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Finding an absolute path to a file via a shortcut.
« Reply #3 on: September 22, 2008, 10:56:55 AM »
Food for thought (if I'm on the right track) ...

Code: [Select]
Sub Test(path As String)

    Dim shellObj  As Shell32.Shell, _
        folderObj As Shell32.Folder, _
        itemObj   As Shell32.FolderItem, _
        linkObj   As Shell32.ShellLinkObject
   
    Set shellObj = New Shell32.Shell
    Set folderObj = shellObj.NameSpace(path)
   
    For Each itemObj In folderObj.Items
        If itemObj.IsFolder Then
            Call Test(itemObj.path)
        ElseIf itemObj.IsLink Then
            Set linkObj = itemObj.GetLink
            Debug.Print itemObj.path & vbCrLf
            With linkObj
                Debug.Print _
                    vbTab & "Arguments        =" & .Arguments & vbCrLf & _
                    vbTab & "Description      =" & .Description & vbCrLf & _
                    vbTab & "Hotkey           =" & .Hotkey & vbCrLf & _
                    vbTab & "Path             =" & .path & vbCrLf & _
                    vbTab & "ShowCommand      =" & .ShowCommand & vbCrLf & _
                    vbTab & "WorkingDirectory =" & .WorkingDirectory & vbCrLf
            End With
        End If
       
    Next

End Sub

Sub Main( )

    Call Test("C:\Program Files\AutoCAD 2008")

End Sub

Might print out --

Code: [Select]
C:\Program Files\AutoCAD 2008\Data Links\Where are my Data Files.lnk

    Arguments        =C:\Program Files\AutoCAD 2008\Help\acad171.chm::/move_datalinks.htm
    Description      =Where are my Data Files
    Hotkey           =0
    Path             =C:\WINDOWS\hh.exe
    ShowCommand      =1
    WorkingDirectory =C:\Program Files\AutoCAD 2008\Help\

C:\Program Files\AutoCAD 2008\Drv\Where are my PMP files.lnk

    Arguments        =C:\Program Files\AutoCAD 2008\Help\acad171.chm::/move_pmp.htm
    Description      =Where are my PMP Files
    Hotkey           =0
    Path             =C:\WINDOWS\hh.exe
    ShowCommand      =1
    WorkingDirectory =C:\Program Files\AutoCAD 2008\Help\

C:\Program Files\AutoCAD 2008\Plot Styles\Where are my Plot Styles.lnk

    Arguments        =C:\Program Files\AutoCAD 2008\Help\acad171.chm::/move_plotstyles.htm
    Description      =Where are my Plot Styles
    Hotkey           =0
    Path             =C:\WINDOWS\hh.exe
    ShowCommand      =1
    WorkingDirectory =C:\Program Files\AutoCAD 2008\Help\

C:\Program Files\AutoCAD 2008\Plotters\Where are my Plot Configurations.lnk

    Arguments        =C:\Program Files\AutoCAD 2008\Help\acad171.chm::/move_plotters.htm
    Description      =Where are my Plot Configurations
    Hotkey           =0
    Path             =C:\WINDOWS\hh.exe
    ShowCommand      =1
    WorkingDirectory =C:\Program Files\AutoCAD 2008\Help\

C:\Program Files\AutoCAD 2008\Support\Where are my Support Files.lnk

    Arguments        =C:\Program Files\AutoCAD 2008\Help\acad171.chm::/move_support.htm
    Description      =Where are my Support Files
    Hotkey           =0
    Path             =C:\WINDOWS\hh.exe
    ShowCommand      =1
    WorkingDirectory =C:\Program Files\AutoCAD 2008\Help\

C:\Program Files\AutoCAD 2008\Template\Where are my Template Files.lnk

    Arguments        =C:\Program Files\AutoCAD 2008\Help\acad171.chm::/move_template.htm
    Description      =Where are my Template Files
    Hotkey           =0
    Path             =C:\WINDOWS\hh.exe
    ShowCommand      =1
    WorkingDirectory =C:\Program Files\AutoCAD 2008\Help\

C:\Program Files\AutoCAD 2008\Textures\Where are my Textures Files.lnk

    Arguments        =C:\Program Files\AutoCAD 2008\Help\acad171.chm::/move_textures.htm
    Description      =Where are my Textures Files
    Hotkey           =0
    Path             =C:\WINDOWS\hh.exe
    ShowCommand      =1
    WorkingDirectory =C:\Program Files\AutoCAD 2008\Help\
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Finding an absolute path to a file via a shortcut.
« Reply #4 on: September 22, 2008, 10:57:13 AM »
Sub GetPrintfile()

    Dim Preferences As AcadPreferences
    Set Preferences = ThisDrawing.Application.Preferences
    Dim sPrintfile As String
   
    sPrintfile = Preferences.files.PrintFile
   
    'If the string is a dot you will need to work out the full path
    ' sPrintfile = "C:\Documents and Settings\yadayada\Application Data\Autodesk\AutoCAD Mechanical 2008\R17.1\enu\Plotters"
    Dim Fs, folder, file
    'http://www.tutorialized.com/view/tutorial/Extract-the-target-file-from-a-shortcut-file-.lnk/18349
    Dim wshShell As Object, oShellLink As Object
    Dim Shortcut As String, sTarget As String
    Set wshShell = CreateObject("WScript.Shell")

    Set Fs = CreateObject("Scripting.FileSystemObject")
    Set folder = Fs.GetFolder(sPrintfile)
    For Each file In folder.files
        If file.Type = "Shortcut" Then
            Shortcut = file.Path
            Set oShellLink = wshShell.CreateShortcut(Shortcut)
            sTarget = oShellLink.TargetPath
            Debug.Print sTarget
        End If
    Next
   
End Sub

mr_nick

  • Guest
Re: Finding an absolute path to a file via a shortcut.
« Reply #5 on: September 22, 2008, 11:20:17 AM »
Thanks for the last couple of responses.

I has already fudged together a solution but Bryco's 'GetPrintFile' is a much tidier solution to get me the same info, so thanks for this.  :-D

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Finding an absolute path to a file via a shortcut.
« Reply #6 on: September 22, 2008, 12:43:49 PM »
Not sure what you're telling me here  :?
I guess I should get my coffee before i answer.  I mis-understood what you wanted.  Bryco and MP will get you going for sure
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)