Announcement

Collapse
No announcement yet.

Newcom, ishelllink

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newcom, ishelllink

    NEWCOM works fairly well with ISHELLLINK; however the .getpath fails when the link is a .URL and .getarguments seems to fail completely.

    I have tried to figure out a way to use NEWCOM retrieve the target path for a .URL but have failed to do so.

    Here is an excerpt of the code I am using:

    Code:
    LET LnkPtr = NEWCOM CLSID $CLSID_ShellLink
    
    IF ISNOTHING(LnkPtr) THEN
    ? "newcom failed"
    END
    END IF
    
    LET PrstPtr = LnkPtr
    
    FOR I = NumFiles TO N
    
    Wstr = tLnk(I).LnkPath
    
    Ok = INSTR(-1, UCASE$(Wstr), ".URL")
    
    IF Ok THEN
    LOCAL CLSID_UrlLink AS GUID
    CLSID_UrlLink = GUID$("{FBF23B40-E3F0-101B-8488-00AA003E56F8}")
    
    CLSID_UrlLink = $CLSID_InternetShortcut            '
    LET UrlLnkPtr = NEWCOM CLSID CLSID_UrlLink    '<-- ERROR HERE
    
    IF ISNOTHING(UrlLnkPtr) THEN                                '<---- passes through
    ? "Internet ptr failed"
    END
    END IF
    
    Ok = UrlPrstPtr.Load(Wstr, %STGM_READ)              '<--- GPF HERE
    Ok = UrlLnkPtr.Resolve(0, %SLR_ANY_MATCH OR %SLR_NO_UI)
    Ok = UrlLnkPtr.GetPath(WstrZ, %MAX_PATH, tFndDta, %SLGP_UNCPRIORITY)
    tLnk(I).ExePath = WstrZ
    Ok = UrlLnkPtr.GetDescription(WstrZ, %MAX_PATH)
    tLnk(I).Describe = WstrZ
    Ok = UrlLnkPtr.GetArguments(WstrZ, 1024)
    tLnk(I).Cmd = Wstrz
    A$ = A$ + RTRIM$(tLnk(I).ExePath, ANY ($NUL + $SPC)) + " | " + _
    RTRIM$(tLnk(I).Cmd, ANY ($NUL + $SPC)) + $CR
    
    UrlPrstPtr = NOTHING
    UrlLnkPtr = NOTHING
    ITERATE FOR
    END IF
    
    Ok = PrstPtr.Load(Wstr, %STGM_READ)
    
    IF Ok <> %S_OK THEN
    ? "link load failed " + STR$(I) + $CR + Wstr
    ITERATE FOR
    EXIT FUNCTION
    END IF
    
    Ok = LnkPtr.Resolve(0, %SLR_ANY_MATCH OR %SLR_NO_UI)
    
    IF Ok <> %S_OK THEN
    ? "link resolve failed"
    
    EXIT FUNCTION
    END IF
    
    Ok = LnkPtr.GetPath(WstrZ, %MAX_PATH, tFndDta, %SLGP_UNCPRIORITY)
    
    IF Ok <> %S_OK THEN
    ? "link getpath failed"
    EXIT FUNCTION
    END IF
    
    Wstr = WstrZ
    tLnk(I).ExePath = WstrZ
    
    Ok = LnkPtr.GetDescription(WstrZ, %MAX_PATH)
    
    IF Ok <> %S_OK THEN
    ? "link describe failed"
    EXIT FUNCTION
    END IF
    
    tLnk(I).Describe = WstrZ
    
    Ok = LnkPtr.GetArguments(WstrZ, 1024)
    
    IF Ok <> %S_OK THEN
    ? "link Argumens failed"
    EXIT FUNCTION
    END IF
    
    tLnk(I).Cmd = Wstrz
    
    Ok = LnkPtr.GetWorkingDirectory(WstrZ, %MAX_PATH)
    IF Ok <> %S_OK THEN
    ? "link workdir failed"
    EXIT FUNCTION
    END IF
    
    tLnk(I).WrkPath = WstrZ
    
    A$ = A$ + RTRIM$(tLnk(I).ExePath, ANY ($NUL + $SPC)) + " | " + _
    RTRIM$(tLnk(I).Cmd, ANY ($NUL + $SPC)) + $CR
    NEXT I
    
    ? A$
    EXIT FUNCTION

    I can do all of the above using cocreateinstance.

    PS:
    Code tags do not seem to work with cut and paste
    Walt Decker

  • #2
    What a mess.

    If you use my include files, the easiest way is to use the Windows Script Host object.

    Code:
    ...
    #INCLUDE ONCE "Wshom.inc"
    ...
    
    ' // Create an instance of the Windows Script Host
    LOCAL pWsh AS IWshShell
    pWsh = NEWCOM "WScript.Shell"
    
    ....
    
    ' // If it is a shortcut...
    
    LOCAL pLnk AS IWshShortcut
    pLnk = pWsh.CreateShortcut(<path of the shortcut>)
    IF IS OBJECT(pLnk) THEN
       ? "Shortcut description: " & pLnk.Description
       ? "Shortcut working directory: " & pLnk.WorkingDirectory
       ? "Shortcut arguments: " & pLnk.Arguments
       ? "Shortcut hot key: " & pLnk.HotKey
       ? "Shortcut icon location: " & pLnk.IconLocation
       ? "Shortcut target path: " & pLnk.TargetPath
       ? "Shortcut window style: " & FORMAT$(pLnk.WindowStyle)
       pLnk = NOTHING
    END IF
    
    ...
    
    ' // If it is an url shortcut...
    
    LOCAL pUrlLnk AS IWshUrlShortcut
    pUrlLnk = pWsh.CreateShortcut(<path of the url shortcut>)
    IF IS OBJECT(pUrlLnk) THEN
       ? "Shortcut full name: " & pUrlLnk.FullName
       ? "Shortcut target path: " & pUrlLnk.TargetPath
       pUrlLnk = NOTHING
    END IF
    Last edited by José Roca; 30 Sep 2020, 11:24 AM. Reason: typo correction
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Mr. Roca,

      I agree, it is a mess. I am just trying to figure out how newcom works in relation to api calls.
      However, I think I have found where I went wrong in using newcom a second time to get the .url path.

      I do not have your headers. I am attempting to build my own from the ms docs.
      Walt Decker

      Comment


      • #4
        Good luck.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Code tags do not seem to work with cut and paste
          Code:
          Type both open and end code tags into the text
          Add blank line between tags and place cursor there
          Paste "text to go between code tags"
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X