locked
Creating Network Locations RRS feed

  • Question

  • I am new to powershell scripting, and am exploring its utility for maintaining a home network with five computers.  I find that I upgrade my computers frequently, and would like to have scripts to automate portions, if not all, of the process.  I have setup powershell scirpts for much of the process, but am stuck on one part. 

    I use a NAS as part of my network for obvious functions, including file sharing, and typically use the Windows network locations function (i.e., open This PC, right click in the space under "Network Locations", and create a link) to provide easy access to certain folders on my NAS.  I would like to create a powershell script to do this, and have been partially successful with the code below.  The problem that I have is that the network location icon that displays also show the word "shortcut" and a size designation (e.g.,"1.73KB"), while the icons generated by the OS do not.  Is there an easy way to set up these links?

    I have also tried using mklink but ran into a different set of challenges with using CMD commands.

    Thanks.

    #Use shortcut to create network locations.
    function CreateShortcut ($SourceName,$TargetName)
    {
    # Create shell object
      $WshShell = New-Object -ComObject WScript.Shell
    
    # Create shortcut
      $Shortcut = $WshShell.CreateShortcut($TargetName)
      $Shortcut.Description ="Network Location Shortcut"
      $Shortcut.IconLocation = "shell32.dll,275"
      $Shortcut.TargetPath = $SourceName
      $Shortcut.Save()
    }
    
    $NetworkLocation = "\Windows 8.1 Installation"
    $ShortcutDestinationFolder = $Env:APPDATA + "\Microsoft\Windows\Network Shortcuts\"
    $TargetName = $ShortcutDestination + $NetworkLocation + ".lnk"
    $SourceName = "\\DiskStation" + "\Windows 8.1 Installation"
    CreateShortcut -SourceName $SourceName -TargetName $TargetName
    


    • Edited by xxxxxxx1 Wednesday, September 16, 2015 3:39 AM
    Wednesday, September 16, 2015 12:56 AM

Answers

  • A Network Location in Windows actually looks like this:

       SH      <NetHood folder>\test\Desktop.ini
    A          <NetHood folder>\test\target.lnk
         R     <NetHood folder>\test

    The desktop.ini file contains:
    [.ShellClassInfo]
    CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}
    Flags=2

    You can use either the PowerShell or VBscript options listed at https://social.technet.microsoft.com/Forums/scriptcenter/en-US/bd00d576-6096-4c8d-bd82-3c5853eb6675/create-shortcut-in-my-network-places-using-powershell to help you with this. 

    Hello xxxxxxx1!  Did the script at the link above help?  The script at the link above will help you create a Network Location the same way Windows creates one if you go to My PC | Add A Network Location.  Although it appears like it is just a shortcut, it is actually a folder with a desktop.ini and target.lnk file inside it with special attributes (more details at the link above).  If this worked for you, please mark this as the answer so others can locate this more easily too.
    • Marked as answer by Bill_Stewart Monday, November 23, 2015 9:16 PM
    Wednesday, September 16, 2015 4:30 PM

All replies

  • Can you please try to post you script so that it is readable.  We run a bit of a technology evaluation here.  If you cannot post a scrip correctly then we flag you post as "technically challenged".  If you are not technically challenged then please look at you post and make it readable.  There are tools on the forum toolbar that are for posting various kinds of things.  Please choose an appropriate tool.

    The answer to you issue is - yes. You can name a shortcut whatever you want.

    $sh=New-Object -comObject WScript.Shell
    $Shortcut=$sh.CreateShortcut("$env:USERPROFILE\desktop\ColorPix.lnk")
    $shortcut.TargetPath='C:\Program Files (x86)\Grumpies Parlor\Grumpy.exe'
    $shortcut.Save()
    Shortcut will display "Grumpy".


    \_(ツ)_/


    • Edited by jrv Wednesday, September 16, 2015 1:23 AM
    Wednesday, September 16, 2015 1:22 AM
  • A Network Location in Windows actually looks like this:

       SH      <NetHood folder>\test\Desktop.ini
    A          <NetHood folder>\test\target.lnk
         R     <NetHood folder>\test

    The desktop.ini file contains:
    [.ShellClassInfo]
    CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}
    Flags=2

    You can use either the PowerShell or VBscript options listed at https://social.technet.microsoft.com/Forums/scriptcenter/en-US/bd00d576-6096-4c8d-bd82-3c5853eb6675/create-shortcut-in-my-network-places-using-powershell to help you with this. 

    • Proposed as answer by Aakash Shah Thursday, September 17, 2015 2:05 AM
    • Unproposed as answer by Aakash Shah Thursday, September 17, 2015 2:05 AM
    • Proposed as answer by Aakash Shah Thursday, September 17, 2015 2:06 AM
    Wednesday, September 16, 2015 1:34 AM
  • A Network Location in Windows actually looks like this:

       SH      <NetHood folder>\test\Desktop.ini
    A          <NetHood folder>\test\target.lnk
         R     <NetHood folder>\test

    The desktop.ini file contains:
    [.ShellClassInfo]
    CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}
    Flags=2

    You can use either the PowerShell or VBscript options listed at https://social.technet.microsoft.com/Forums/scriptcenter/en-US/bd00d576-6096-4c8d-bd82-3c5853eb6675/create-shortcut-in-my-network-places-using-powershell to help you with this. 

    I think you misunderstood the question.


    \_(ツ)_/

    Wednesday, September 16, 2015 1:42 AM
  • Thanks for the tip on formatting code.

    The question was not related to naming shortcuts, but thanks for the input.  The question was how to create shortcuts to network locations that appear in the "This PC" folder under Windows 8.1 and Windows 10.

    Wednesday, September 16, 2015 3:41 AM
  • Thank you for the reply.  I have not tracked down the links, but will tomorrow.  Best regards, John
    Wednesday, September 16, 2015 3:42 AM
  • They are not shortcuts but they are links.  You originally posted code that place a shortcut on the desktop.  You need to be more accurate with your questions.

    \_(ツ)_/

    Wednesday, September 16, 2015 4:37 AM
  • Here is where the libraries are kept:

    notepad $env:AppData\Microsoft\Windows\Libraries\Documents.library-ms


    \_(ツ)_/

    Wednesday, September 16, 2015 4:43 AM
  • Network shortcuts go here: "$env:APPDATA\Microsoft\Windows\Network Shortcuts"


    \_(ツ)_/

    • Proposed as answer by jrv Wednesday, September 16, 2015 12:23 PM
    • Unproposed as answer by Bill_Stewart Monday, November 23, 2015 9:15 PM
    Wednesday, September 16, 2015 4:47 AM
  • My question was clear:  "... typically use the Windows network locations function (i.e., open This PC, right click in the space under "Network Locations". "

    If I knew that I needed links instead of shortcuts, I likely would not have had the problem nor the question. 

    Wednesday, September 16, 2015 10:37 AM
  • Thank you.
    Wednesday, September 16, 2015 10:37 AM
  • A Network Location in Windows actually looks like this:

       SH      <NetHood folder>\test\Desktop.ini
    A          <NetHood folder>\test\target.lnk
         R     <NetHood folder>\test

    The desktop.ini file contains:
    [.ShellClassInfo]
    CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}
    Flags=2

    You can use either the PowerShell or VBscript options listed at https://social.technet.microsoft.com/Forums/scriptcenter/en-US/bd00d576-6096-4c8d-bd82-3c5853eb6675/create-shortcut-in-my-network-places-using-powershell to help you with this. 

    Hello xxxxxxx1!  Did the script at the link above help?  The script at the link above will help you create a Network Location the same way Windows creates one if you go to My PC | Add A Network Location.  Although it appears like it is just a shortcut, it is actually a folder with a desktop.ini and target.lnk file inside it with special attributes (more details at the link above).  If this worked for you, please mark this as the answer so others can locate this more easily too.
    • Marked as answer by Bill_Stewart Monday, November 23, 2015 9:16 PM
    Wednesday, September 16, 2015 4:30 PM
  • Aakash - I just ran a simple test, and it looks like it does exactly what I was trying to accomplish.  Thanks for pointing me in the right direction!  John
    Thursday, September 17, 2015 1:26 AM
  • Happy to help! I'm glad that worked for you.
    Thursday, September 17, 2015 2:49 AM