Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WSH script to add to My Network Places 1

Status
Not open for further replies.

lengoo

IS-IT--Management
Jan 15, 2002
381
0
0
GH
Dear All,
Does anyone know how to write a script that automatically add entries into the My Network Places on a user login.

I've found the shortcuts to be in c:\documents and settings\USER\NetHood

but you can't run a 'copyfile' command on these folders as they are deemed special by Windows. The folders is actually two files, desktop.ini and target.lnk

I tried to do this manually but it doesn't quite work.. anyone shed any light on this?
 
Well, not sure really what you are trying to do here. What are you trying to accomplish by copying these files to this directory. Looks like you might be trying to set the default desktop environmet, if so there are better ways to accomplish this. If not explain further please.

Z
 
Hi guys

I've found a way to do it but there is a prob with it

Set objShell = Wscript.CreateObject("Wscript.shell")
strpath = objShell.SpecialFolders("Nethood")
strpathname = objShell.ExpandEnvironmentStrings ("\\server\corporate")
Set objShortcut = objShell.Createshortcut(strpath+"\Corporate.lnk")
objShortcut.TargetPath = strpathname
objShortcut.Save

What this does is to install an icon in the Nethood location.. however, it puts it in as a Corporate.lnk file (the syntax only allows .lnk or .url) but when you actually manually create a network place entry, the file format is different...
The sole purpose of this is so that my users using MS Word, can insert a hyperlink and go to Network places when the directory box appears. With my above script, if you select the created folder from Network places when you are inserting a hyperlink, you don't see the underlying folders and/or files.

Regards
Lengoo
 
I have created a logon script that I use to add a network place for different drive mappings, here is a subportion of that script that will just add the network places.

Dim fs,Shell,DomainADSPath
Set Shell = WScript.CreateObject("WScript.Shell")
Set fs = Createobject("Scripting.FilesystemObject")

CreateNetworkLink "My Home Directory","\\servername\share\folder","My Home directory"

Sub CreateNetworkLink(LinkName,LinkTargetPath,LinkDescription)
'> Get the path to the Network Neighborhood special folder.
Set NetHoodfolder = fs.getfolder(Shell.SpecialFolders("NetHood"))
Folder=NetHoodFolder &"\" &LinkName
If Fs.FolderExists(Folder)=False Then
Fs.CreateFolder(Folder)
set LinkFolder=fs.getfolder(Folder)
Linkfolder.attributes=1
End If
CreateLink Folder,"target.lnk",LinkTargetPath,LinkDescription,"",""
WriteFile Folder &"\Desktop.ini","[.ShellClassInfo]",2
WriteFile Folder &"\Desktop.ini","CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}",8
WriteFile Folder &"\Desktop.ini","Flags=2",8
WriteFile Folder &"\Desktop.ini","ConfirmFileOp=0",8
End Sub

'Create Network Links here. The format is CreateNetworkLink LinkName,LinkTargetPath,Linkdescription

CreateNetworkLink "My New Link","\\servername\share\subfolder","My new network place"


Sub CreateNetworkLink(LinkName,LinkTargetPath,LinkDescription)
'> Get the path to the Network Neighborhood special folder.
Set NetHoodfolder = fs.getfolder(Shell.SpecialFolders("NetHood"))
Folder=NetHoodFolder &"\" &LinkName
If Fs.FolderExists(Folder)=False Then
Fs.CreateFolder(Folder)
set LinkFolder=fs.getfolder(Folder)
Linkfolder.attributes=1
End If
CreateLink Folder,"target.lnk",LinkTargetPath,LinkDescription,"",""
WriteFile Folder &"\Desktop.ini","[.ShellClassInfo]",2
WriteFile Folder &"\Desktop.ini","CLSID2={0AFACED1-E828-11D1-9187-B532F1E9575D}",8
WriteFile Folder &"\Desktop.ini","Flags=2",8
WriteFile Folder &"\Desktop.ini","ConfirmFileOp=0",8
End Sub

'>This Subroutine Creates the Shortcut Based on the parameters sent to it.
Sub CreateLink(LinkLocation,LinkName,LinkTargetPath,LinkDescription,LinkWorkingDirectory,LinkIconLocation)
Set ShellLink = Shell.CreateShortcut(LinkLocation &"\" & LinkName)
ShellLink.TargetPath = LinkTargetPath
ShellLink.WindowStyle = 1
ShellLink.Description = LinkDescription
ShellLink.WorkingDirectory = LinkWorkingDirectory
shelllink.IconLocation = LinkIconLocation
ShellLink.Save
End Sub

'> This function writes to a file
Function WriteFile(Filename,Text,AccessType)
'Const ForWriting = 2, ForAppending=8
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(FileName, AccessType, true)
f.WriteLine Text
f.Close
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top