• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 745
  • Last Modified:

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" " ?
0
meznehemia
Asked:
meznehemia
1 Solution
 
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
 
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

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now