UPDATE: Please note that this post has been replaced by an updated post (here) that contains a newer version of the script.
With SharePoint sometimes it is necessary to create Network Location shortcuts on the client workstation. For Solid Edge Insight this is not only necessary but also a requirement.
With SharePoint sometimes it is necessary to create Network Location shortcuts on the client workstation. For Solid Edge Insight this is not only necessary but also a requirement.
Sure creating three or four Network Locations is no big
deal. But what if you need to standardize
those Network Locations across all workstations and user logons? Do you really want to be manually creating
the same Network Location shortcuts for 20 user ids across 20 different workstations? Having the ability to automate the creation
of these Network Location shortcuts could certainly be a time saver.
If you’ve ever created the SharePoint Network Location
shortcut and then tried to copy and paste the shortcut across user ids or workstations you’ve
discovered that the process is not that simple and typically will not work as
expected.
Below is a script I put together for automating the creation
of SharePoint Network Location shortcuts.
I’m not a programmer by trade and I’m definitely not VBS proficient but
the script works (for me) and serves the purpose.
The script is designed to be used with Windows 7 clients. I have not tested it but would not expect this script to work with XP. XP network location shortcuts behave differently from Windows 7 against SharePoint URLs.
This is a simple script and does minimal error checking. It
is provided merely as a barebones example of how to accomplish this task. The script definitely should be fleshed out
to best suit your specific needs and environment i.e. incorporated into a user logon script etc.
Simply copy and paste the code below into a text file and
save it with a .vbs file extension. Or
you can download the script directly from here.
' CreateSharePointNetworkLocations
' Copyright (C) 2011, David C. Merritt, http://david-merritt.blogspot.com
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
'
'
'---------------------------------------------------------------------
' edit, add and remove your SharePoint URL network locations below here
' ---------------------------------------------------------------------
dim ShortcutNames(5), ShortcutPaths(5)
ShortcutNames(0) = "hsvnt422b - PreReleased"
ShortcutPaths(0) = "http://hsvnt422b/PreRelease/PreDL"
ShortcutNames(1) = "hsvnt422b - Released"
ShortcutPaths(1) = "http://hsvnt422b/Release/RelDL"
ShortcutNames(2) = "hsvnt422b - Obsolete"
ShortcutPaths(2) = "http://hsvnt422b/Obsolete/ObsDL"
ShortcutNames(3) = "hsvnt416z01 - PreReleased"
ShortcutPaths(3) = "http://hsvnt416z01:16133/Pre"
ShortcutNames(4) = "hsvnt416z01 - Released"
ShortcutPaths(4) = "http://hsvnt416z01:16133/Rel"
ShortcutNames(5) = "hsvnt416z01 - Obsolete"
ShortcutPaths(5) = "http://hsvnt416z01:16133/Obs"
' ---------------------------------------------------------------------
' edit, add and remove your SharePoint URL network locations above here
' ---------------------------------------------------------------------
' create network place shortcut for each location specified
intCounter = 0
For Each strShortcutName In ShortcutNames
CreateNetworkPlace strShortcutName, ShortcutPaths(intCounter)
intCounter = intCounter + 1
Next
wscript.echo "Network place shortcuts created"
WScript.Quit
' the subroutine that does all the work
Sub CreateNetworkPlace(strShortcutName, strShortcutPath)
' change our shortcut path to the Win 7 webdav format
strShortcutMod = Replace(strShortcutPath, "http://", "\\")
strShortcutMod = Replace(strShortcutMod, ":", "@")
strShortcutMod = Replace(strShortcutMod, "/", "\DavWWWRoot\", 1, 1)
strShortcutMod = Replace(strShortcutMod, "/", "\")
' determine on the OS where to create the network place shortcut
Const NETHOOD = &H13&
Set objWSHShell = CreateObject("Wscript.Shell")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETHOOD)
Set objFolderItem = objFolder.Self
strNetHood = objFolderItem.Path
' create the network place shortcut folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
strShortcutFolder = strNetHood & "\" & strShortcutName
If objFSO.FolderExists(strShortcutFolder) Then
wscript.echo strShortcutFolder & " already exists"
Else
Set objFolder = objFSO.CreateFolder(strShortcutFolder)
' create the Desktop.ini file under the network place shortcut folder
strDesktopIni = strShortcutFolder & "\Desktop.ini"
If Not objFSO.FileExists(strDesktopIni) Then
set fText = objFSO.OpenTextFile(strDesktopIni, 2, True)
fText.WriteLine "[.ShellClassInfo]"
fText.WriteLine "CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}"
fText.WriteLine "Flags=2"
fText.Close
End If
' set Desktop.ini with file attributes system & hidden
Set fFile = objFSO.GetFile(strDesktopIni)
fFile.Attributes = 6
' set network place shortcut folder as read-only
Set fFolder = objFSO.GetFolder(strShortcutFolder)
fFolder.Attributes = 1
' create the shortcut file target.lnk under the network place shortcut folder
Set objShortcut = objWSHShell.CreateShortcut(strShortcutFolder & "\target.lnk")
objShortcut.TargetPath = strShortcutMod
objShortcut.Description = strShortcutPath
objShortcut.Save
End If
End Sub
Once you have the code, locate the section where indicated
and change, add and remove your SharePoint URL network locations and the names for the shortcuts
as necessary.
I can’t guarantee I’ll be able to incorporate any requests
but if you would like to see certain functionality incorporated into this script
it never hurts to ask :-)
Feel free to take the code and improve upon it. I would certainly appreciate seeing any improvements
that you make to the code so I can update and tweak the original.
And although it goes without saying, as always, YMMV.
And although it goes without saying, as always, YMMV.
Doesn't work for me (Win7 64bit). Needs to modified for https://site@SSL/folder/folder
ReplyDeleteThanks for the feedback.
DeleteUnfortunately I currently do not have an SSL system available to test against. However I’m making a broad assumption I can simply replace the “https://” with “\\”. If this is case then try this modded version of the script:
http://db.tt/ALFSJWqP
Please let me know if this works. If not please provide the string that the network place is aliased to when you manually create the network folder and I will adjust accordingly.
Thanks again.
Wow! Did I totally guess wrong on how the SSL address gets implemented. I finally got an https server in place and was able to modify the script to work with both http and https addresses. Give the updated script a try and let me know. http://db.tt/1suD1MfH
DeleteDavid, thanks for your work.
ReplyDeleteBut your script never seems to work on my Windows 7 64 system.
It looks like it's creating all the files correctly, but when I click on the new folder shortcut, nothing happens.
This is an https address, so that may be the issue. Do you know whether your script works for anyone in that case?
Oh, and I forgot to mention, it sort of works on Win XP, but when I click the folder shortcut, it shows the folder in IE, not Windows Explorer.
DeleteWhen I do Add Network Place manually on either system, everything works as expected.
The target.lnk files that work seem to have extra content that the ones created by the script do not.
Have you run across these issues before or have a clue for a cure?
Thanks!
Thanks for stopping by and your feedback.
DeleteLast question first, running on XP. This script will not work for XP as the format for network place shortcuts is different between XP and Windows 7. Sorry!
Now to the first question. At the top of this post is an update indicating that this is an outdated version of the script. The newest post with the latest version of this script can be found at http://david-merritt.blogspot.co.uk/2013/01/new-automate-creating-sharepoint.html
P.S. In regards to 64-bit, 64-bit is the only thing I have available, so the script was developed and tested on Win7 64-bit w/o any issues -- on my system ;-)
Delete