Link to home
Start Free TrialLog in
Avatar of meznehemia
meznehemia

asked on

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" " ?
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of meznehemia
meznehemia

ASKER

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