Script for populating specific \\server\shares under 'My Network Places"

Hi,

I am sick of emails asking I need access to A,B, C,D...Z drive when I have no idea to what server\share each user may map their local drive lettlers. My company has about 2000 very mobile users and 15 US sites with one main data center in somewhereville. For exapmple each site has a local file server and users by convention map their drive letter P to the  \\citylocalserver\public. I want to get away from drive letters as much as possible and just recomend to my network adding each server\share available on users desktop 'My Network Places' for all users logging into our US Domain. Is it possible to write a VBS script the same way you can add for example a drive letter  "objNetwork.MapNetworkDrive "P:", "\\filesvr1\public","False" " ?
meznehemiaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grayeCommented:
Here is an example that I found on the Internet long ago...

Call AddNetworkPlace ("\\company.com\companydata","Networked Folders")
wscript.quit

Sub AddNetworkPlace (strUNCPath,strDescription)
'
'Create a shortcut to a UNC path in My Network Places
'
'strUNCPath: UNC path to the network resource
'strDescription: Description of the shortcut that will
' appear in My Network Places
'
on error resume next
Set shell=CreateObject("Wscript.Shell")
Set objShortcut=Shell.CreateShortcut(Shell.SpecialFolders("Nethood") _
& "\" & strDescription & ".lnk")
With objShortcut
..TargetPath=strUNCPath
..Description=strDescription
..Save()
End With
'
strLocation = Shell.SpecialFolders("Nethood") & "\" & strDescription &
".lnk"
Wscript.Echo "Networked Folders path is " & strLocation & vbCr
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(strLocation)) Then
Wscript.Echo "Networked Places exists."
Else
Wscript.Echo "Networked Places does not exist."
End If
'
set Shell=nothing
set objShortcut=nothing
set fso=nothing
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
meznehemiaAuthor Commented:
Thanks Grey. Your exapmple was very helpful though there is no AddNetworkPlace method to call in WScript.




'************************Script to Mount Certain Network Shares in My Network Places**************************************
Option Explicit

dim strNethoodNameLdrive '= "First L drive"
dim strNethoodNameATLPdrive '= "2nd Public"
dim strNethoodNamePRNPdrive '= "3rd Public"
dim strNethoodNameCLVPdrive '= "4th Public"
dim strNethoodNameCHIPdrive '= "fifth Public"

dim strNetAddressLdrive '= "\\firstsvr1\public"
dim strNetAddressATLPdrive '= "\\2ndsvr1\Public"
dim strNetAddressPRNPdrive '= "\\3rdsvr1\public"
dim strNetAddressCLVPdrive '= "\\4rgsvr1\public"
dim strNetAddressCHIPdrive '= "\\5thsvr1\public"


dim strNethoodPath
dim strNetPlaceDir


dim FILEIni
dim F 'desktop.ini
dim objWshScript
dim objFilesys
dim objNethood


strNethoodNameLdrive = "Location 1 L drive"
strNetAddressLdrive = "\\firstsvr1\public"

strNethoodNameATLPdrive = "Location 2 Public"
strNetAddressATLPdrive = "\\2ndvr1\Public"
strNethoodNamePRNPdrive = "Location 3 Public"
strNetAddressPRNPdrive = "\\3rdsvr1\public"

strNethoodNameCLVPdrive = "Location 4 Public"
strNetAddressCLVPdrive = "\\4thsvr1\public"

strNethoodNameCHIPdrive = "Location 5 Public"
strNetAddressCHIPdrive = "\\5thsvr1\public"

set objWshScript = WScript.CreateObject("WScript.Shell")
set objFilesys = CreateObject("Scripting.FileSystemObject")



'*********************First Public (L) Share************************************************


strNethoodPath = objWshScript.SpecialFolders("Nethood")

strNetPlaceDir = strNethoodPath + "\" + strNethoodNameLdrive
If objFilesys.FolderExists (strNetPlaceDir) Then
msgbox("folder exists")
WScript.quit
End If


objFilesys.CreateFolder (strNetPlaceDir)

' 1 = ReadOnly, 16 = Folder
 Set F = objFilesys.GetFolder(strNetPlaceDir)
 F.Attributes = 17

'target.lnk
set objNethood = objWshScript.CreateShortcut(strNetPlaceDir + "\target.lnk")
objNethood.TargetPath = strNetAddressLdrive
objNethood.Save
'target.lnk
'32 = Archive
'Set F = objFilesys.GetFile(strNetPlaceDir + "\target.lnk")
'F.Attributes = 32

'desktop.ini
Set FILEIni = objFilesys.CreateTextFile(strNetPlaceDir & "\desktop.ini", True)
FILEIni.WriteLine("[.ShellClassInfo]") & vbcrlf _
& ("ComfirmFileOp=0") & vbcrlf _
& ("CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}") & vbcrlf _
& ("Flags=2")
FILEIni.Close
'desktop.ini
' 2 = Hidden, 4 = System
Set F = objFilesys.GetFile(strNetPlaceDir & "\desktop.ini")
F.Attributes = 6






'******************** 2nd Public Share **************************************************



strNetPlaceDir = strNethoodPath + "\" + strNethoodNameATLPdrive
If objFilesys.FolderExists (strNetPlaceDir) Then
msgbox("folder exists")
WScript.quit
End If


objFilesys.CreateFolder (strNetPlaceDir)

' 1 = ReadOnly, 16 = Folder
 Set F = objFilesys.GetFolder(strNetPlaceDir)
 F.Attributes = 17

'target.lnk
set objNethood = objWshScript.CreateShortcut(strNetPlaceDir + "\target.lnk")
objNethood.TargetPath = strNetAddressATLPdrive
objNethood.Save
'target.lnk
'32 = Archive
'Set F = objFilesys.GetFile(strNetPlaceDir + "\target.lnk")
'F.Attributes = 32

'desktop.ini
Set FILEIni = objFilesys.CreateTextFile(strNetPlaceDir & "\desktop.ini", True)
FILEIni.WriteLine("[.ShellClassInfo]") & vbcrlf _
& ("ComfirmFileOp=0") & vbcrlf _
& ("CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}") & vbcrlf _
& ("Flags=2")
FILEIni.Close
'desktop.ini
' 2 = Hidden, 4 = System
Set F = objFilesys.GetFile(strNetPlaceDir & "\desktop.ini")
F.Attributes = 6





'********************* 3rd Public Share **********************************************




strNetPlaceDir = strNethoodPath + "\" + strNethoodNamePRNPdrive
If objFilesys.FolderExists (strNetPlaceDir) Then
msgbox("folder exists")
WScript.quit
End If


objFilesys.CreateFolder (strNetPlaceDir)

' 1 = ReadOnly, 16 = Folder
 Set F = objFilesys.GetFolder(strNetPlaceDir)
 F.Attributes = 17

'target.lnk
set objNethood = objWshScript.CreateShortcut(strNetPlaceDir + "\target.lnk")
objNethood.TargetPath = strNetAddressPRNPdrive
objNethood.Save
'target.lnk
'32 = Archive
'Set F = objFilesys.GetFile(strNetPlaceDir + "\target.lnk")
'F.Attributes = 32

'desktop.ini
Set FILEIni = objFilesys.CreateTextFile(strNetPlaceDir & "\desktop.ini", True)
FILEIni.WriteLine("[.ShellClassInfo]") & vbcrlf _
& ("ComfirmFileOp=0") & vbcrlf _
& ("CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}") & vbcrlf _
& ("Flags=2")
FILEIni.Close
'desktop.ini
' 2 = Hidden, 4 = System
Set F = objFilesys.GetFile(strNetPlaceDir & "\desktop.ini")

F.Attributes = 6







'***********************************4th Public Share***************************




strNetPlaceDir = strNethoodPath + "\" + strNethoodNameCLVPdrive
If objFilesys.FolderExists (strNetPlaceDir) Then
msgbox("folder exists")
WScript.quit
End If


objFilesys.CreateFolder (strNetPlaceDir)

' 1 = ReadOnly, 16 = Folder
 Set F = objFilesys.GetFolder(strNetPlaceDir)
 F.Attributes = 17

'target.lnk
set objNethood = objWshScript.CreateShortcut(strNetPlaceDir + "\target.lnk")
objNethood.TargetPath = strNetAddressCLVPdrive
objNethood.Save
'target.lnk
'32 = Archive
'Set F = objFilesys.GetFile(strNetPlaceDir + "\target.lnk")
'F.Attributes = 32

'desktop.ini
Set FILEIni = objFilesys.CreateTextFile(strNetPlaceDir & "\desktop.ini", True)
FILEIni.WriteLine("[.ShellClassInfo]") & vbcrlf _
& ("ComfirmFileOp=0") & vbcrlf _
& ("CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}") & vbcrlf _
& ("Flags=2")
FILEIni.Close
'desktop.ini
' 2 = Hidden, 4 = System
Set F = objFilesys.GetFile(strNetPlaceDir & "\desktop.ini")
F.Attributes = 6




'*********************************Fifth Public Share*******************************



strNetPlaceDir = strNethoodPath + "\" + strNethoodNameCHIPdrive
If objFilesys.FolderExists (strNetPlaceDir) Then
msgbox("folder exists")
WScript.quit
End If


objFilesys.CreateFolder (strNetPlaceDir)

' 1 = ReadOnly, 16 = Folder
 Set F = objFilesys.GetFolder(strNetPlaceDir)
 F.Attributes = 17

'target.lnk
set objNethood = objWshScript.CreateShortcut(strNetPlaceDir + "\target.lnk")
objNethood.TargetPath = strNetAddressCHIPdrive
objNethood.Save
'target.lnk
'32 = Archive
'Set F = objFilesys.GetFile(strNetPlaceDir + "\target.lnk")
'F.Attributes = 32

'desktop.ini
Set FILEIni = objFilesys.CreateTextFile(strNetPlaceDir & "\desktop.ini", True)
FILEIni.WriteLine("[.ShellClassInfo]") & vbcrlf _
& ("ComfirmFileOp=0") & vbcrlf _
& ("CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}") & vbcrlf _
& ("Flags=2")
FILEIni.Close
'desktop.ini
' 2 = Hidden, 4 = System
Set F = objFilesys.GetFile(strNetPlaceDir & "\desktop.ini")
F.Attributes = 6
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Networking

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.