script to replace a file on users desktop

chasmant
chasmant used Ask the Experts™
on
Looking to find a way to go through the the users profiles in C:\users
and change a file on their desktop and replace it with a new file
example
c$\Users\*username*\Desktop\Watertown Chipline - Production Reporting.mdb
replace this file on all the profiles on this pc with a new file
located on a server
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kent DyerIT Security Analyst Senior

Commented:
Probably the best way to do this is at login.  Login script..

Something like:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")

If Not oFSO.FileExists(strDesktop & "\Watertown Chipline - Production Reporting.mdb") Then
	Copy System.Environment.GetEnvironmentVariable("LOGONSERVER") & "\Path\Watertown Chipline - Production Reporting.mdb" strDesktop
End If

Open in new window


HTH,

Kent

Author

Commented:
What I would like to do is log into the server and have it go through each profile and replace the file so that I can make sure it is all done before they get here
Test your restores, not your backups...
Top Expert 2016
Commented:
I think this should be close to what you want.  It loops through all the folders under c:\users, skips over a few known ones that aren't real users, and then replaces the file if it exists.

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oUsers = oFSO.GetFolder("c:\users")
For Each oSubFolder In oUsers.SubFolders
    If oSubFolder.Name <> "All Users" And oSubFolder.Name <> "Default" And oSubFolder.Name <> "Default User" And oSubFolder.Name <> "Public" Then
        Wscript.Echo oSubFolder.Path
        If oFSO.FileExists(oSubFolder.Path & "\Desktop\" & "\Watertown Chipline - Production Reporting.mdb") Then
            oFSO.CopyFile "\\Path\Watertown Chipline - Production Reporting.mdb", oSubFolder.Path & "\Desktop\", True
        End If
    End If
Next

Open in new window

~bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial