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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login Script to copy shared folder to user desktops

Status
Not open for further replies.

trevstonbury

IS-IT--Management
Joined
May 24, 2010
Messages
3
Location
GB
Hi Guys.

This is probably a fairly simple one for but I am quite a novice with scripts.

Bascialy I want a script to be able to copy a directory in a share from a server to all user desktops when they login, so far I have the following;

If possible can it be set so that it only copies the directory if it see's is does not exist? Any help would be much appreciated :-)


Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "file://server/share/foldertocopy" , "%userprofile%\desktop" , OverWriteFiles
 
have a look at the FolderExists method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here's a start

Code:
Option Explicit
'On Error Resume Next

Dim WshShell, Desktop, FolderName, DestDir, oFSO, NewFolder

FolderName = "SomeFolder"

'Variables
Set WshShell = CreateObject( "WScript.Shell" )
Desktop = = WshShell.SpecialFolders("Desktop")
SDir = "\\server\share"
DDir = Desktop & "\" & FolderName

'Look for "Somefolder" Folder on user desktop - if not there then create it.
Set oFso = CreateObject("Scripting.FileSystemObject")

If Not oFso.FolderExists(DDir) Then
'Create New Folder
   oFso.CreateFolder(DDir)
End If

objFSO.CopyFile SDir, DDir, overwrite = True

MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
>objFSO.CopyFolder "file://server/share/foldertocopy" , "%userprofile%\desktop" , OverWriteFiles
[tt]objFSO.CopyFolder "\\server\share\foldertocopy" , createobject("wscript.shell").expandenvironmentstrings("%userprofile%\desktop"), OverWriteFiles [/tt]
 
I have managed to get the following working;

its pretty basic but at the moment the destination doesnt work; %userprofile%\desktop\destfolder

I get a 'path not found error'

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FolderExists("\\server\folder") Then
filesys.CopyFolder "\\storage-server\Support\Default Client Install\Desktop Shortcuts\", "%userprofile%\desktop\destfolder"
End If
 
tsuji showed you already.
Code:
Dim WshShell:Set WshShell = WScript.CreateObject("WScript.Shell")
Dim filesys:Set filesys=CreateObject("Scripting.FileSystemObject")
strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
If filesys.FolderExists("\\server\folder") Then
	filesys.CopyFolder "\\storage-server\Support\Default Client Install\Desktop Shortcuts\", strUserProfile &  "\Desktop\destfolder", overwrite = False
End If
you may want to wscript.echo the destination path to check it's correct.
e.g.
Code:
Dim WshShell:Set WshShell = WScript.CreateObject("WScript.Shell")
Dim filesys:Set filesys=CreateObject("Scripting.FileSystemObject")
	strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")

source = "\\storage-server\Support\Default Client Install\Desktop Shortcuts\"
dest =  strUserProfile &  "\Desktop\destfolder"

wscript.echo dest

If filesys.FolderExists("\\server\folder") Then
	filesys.CopyFolder source, dest, overwrite = False
End If

MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Thanks guys, sorry like I said im a total novice with these;

I have tried running the code you sent below GrimR but am getting an error. Line 3, char 5, error: object required: 'objShell'



Dim WshShell:Set WshShell = WScript.CreateObject("WScript.Shell")
Dim filesys:Set filesys=CreateObject("Scripting.FileSystemObject")
strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")

source = "\\storage-server\Support\Default Client Install\Desktop Shortcuts"
dest = strUserProfile & "\Desktop\destfolder"

wscript.echo dest

If filesys.FolderExists("\\storage-server\Support\Default Client Install\Desktop Shortcuts") Then
filesys.CopyFolder source, dest, overwrite = False
End If

 
Just change this
strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
To
strUserProfile = wshShell.ExpandEnvironmentStrings("%USERPROFILE%")



MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
also
>overwrite = False
at its place, should be simply
[tt]False[/tt]
or according to need
[tt]True[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top