phpwindowsshortcutnetwork-shares

Is this possible to get a SHARE .lnk target?


I'm working on a php project in an entreprise with some Windows WebServers. My problem is that I don't know how to read a target of a SHARE .lnk shortcut with PHP.

I can read a target of a .lnk shotcut like this one: 'C:\Users\LoL'.

But I can't get a target of a .lnk shotcut like this: '\\server\share\dir'.

Do you know any php function that allow me to read this target?

Thank you in advance!


Solution

  • I found a solution to my own problem.

    The best solution that I found to read a share .lnk shortcut with a target like this ''\server\share'' is the COM object.

    From PHP 5.4.5, COM and DOTNET is no longer built into the php core. You have to add COM support in php.ini:

    [COM_DOT_NET]
    extension=php_com_dotnet.dll
    

    To read the target of a share .lnk shortcut in PHP, you have to use the follow instructions:

    <?php
    
        // create the object
        $wsh = new COM('WScript.Shell');
    
        // $wsh->CreateShortcut method READS, if the file already exists. 
        $lnk=$wsh->CreateShortcut('ShortcutPath.lnk');
    
        // show the target
        echo $lnk->TargetPath,"\n";
    ?>
    

    I hope this will help you.

    I let you some sources that helped me: