Simple Windows Script to Copy a File in Background??
August 19, 2006 11:10 AM   Subscribe

Anyone on MetaFilter any good at writing Windows Scripting Language (VBScript) scripts? I am a total nonprogrammer but need a simple task done, which is copying a file from one directory to another (on a Win XP) system either (a) every twenty minutes, or better still (b) after checking to see if the archive bit on the file has been reset, indicating that it has been changed since the last filecopy. This should run as a background script without any user intervention or evidence that it is happening, if possible.

Here's the problem in more detail, which relates to combining randomized desktop wallpaper and a dual-monitor setup.

. The program "Wallchanger" changes the desktop wallpaper at a preset interval (I have it set for every 20 minutes), choosing randomly from a collection of graphics, and writing the newly chosen file to "c:\windows\wallchanger wallpaper.bmp."

Several months ago I switched to a dual monitor setup. I use the fantastic utility Ultramon to control various aspects of the two-monitor setup. One of the things Ultramon can do is stretch a single wallpaper across the two desktops, but it has to be a static file in the location "c:\documents and settings\\my documents\my wallpapers." Since I have been unable to get Ultramon to recognize and use my wallchanger wallpapers, I currently have the same wallpaper, twice, side by side on the two monitors.

I know many of you purists willl probably answer that I should just ditch wallpapers and go with a plain desktop background, but I really love my collection of astronomical and aurora photographs, and I am dying to stretch my wallpapers across the two monitors...

The paths of the files are not configurable options in either wallchanger or ultramon, so I figure I have to take the file wallchanger creates in c:\windows every 20 min and copy it to the proper location for ultramon to find it. I figure that, for someone who knows scripting, this would be a trivial thing to bang out. Am I right? I have tried to read online tutorials/introductions to windows scripting but I cannot get further than the point where they show you how to write "Hello World!" to your screen. I would appreciate any help with this.
posted by emg to Computers & Internet (3 answers total)
 
I would do the following:
1. Open a DOS prompt. Experiment with the copy command until you get the parameters correct.
2. Open Notepad. Put the correct copy command in the text file. Save the file as a *.bat file, something like copy_wallpaper.bat.
3. Use the Windows Task Scheduler to schedule the program copy_wallpaper.bat to run every 20 minutes. When first prompted, say that you want the task to run daily. In the Advanced properties window, you can set the task to run every 20 minutes.
posted by crazycanuck at 11:20 AM on August 19, 2006


Best answer: This will check the archive bit on the file. I'm sure copy has the functionality to do, but I used this as a learning experience to find out if the FileSystemObject could do it as well.

Copy everything between the ** and save it as copy_wallpaper.vbs file. Create the .bat file that crazy canuck mentioned with the following commands:

wscript copy_wallpaper.vbs FILENAME_TO_COPY PATH_TO_COPY_TO

Change the FILENAME_TO_COPY with the filename created by wallchanger and the PATH_TO_COPY_TO to the path that Ultramon needs (the path should have a trailing slash).

**
On Error Resume Next
Dim strCopyFile, strCopyTo, FSO

strCopyFile = WScript.Arguments.Item(0)
strCopyTo = WScript.Arguments.Item(1)

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FileExists(strCopyFile) Then
Dim objCopyFile

Set objCopyFile = FSO.GetFile(strCopyFile)

If objCopyFile.Attributes AND 32 AND FSO.FolderExists(strCopyTo) Then
FSO.CopyFile strCopyFile, strCopyTo, True
End If

Set objCopyFile = Nothing
End If

Set FSO = Nothing

**
posted by purephase at 3:50 PM on August 19, 2006 [1 favorite]


Response by poster: Thank you, this works great!
posted by emg at 5:21 AM on August 23, 2006


« Older What are my options in dealing with an employer...   |   Help with daughter Newer »
This thread is closed to new comments.