Batch file copy using VBscripting…

One of my jobs long ago was to maintain the process for deploying splash pages to MS terminal server users when planned maintenance would be performed. The creation of the splash HTML page was simply a white page with red and black text informing the user when the service would be down. Pretty basic right? The opportunity I saw was to automatically deploy it, rather than remoting in or remotely copying each splash file to each Terminal Server. I wrote the following script to copy the splash page to a list of servers identified in a txt file.“

1. VBscripting skills
2. splash.html (HTML file that will be deployed)
3. servers.txt (txt file listing each server to push the splash.html file to)
4. Assumes you have appropriate user privileges.

'Created by thejimmahknows'
dim  netStr, filename, path
On Error Resume Next

'destination path'
path = "c$\Documents and Settings\All Users\Start Menu\ProgramsStartup"
filename = InputBox("Please enter the name of the file to copy?","File Name?","generic.htm")
If filename = "" Then
End If

'source path/filename'
toBeFilename = InputBox("Please enter destination file name?","Server Farm Name?","farm name")
If toBeFilename = "" Then
	toBeFilename = "generic-patches.htm"
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network") 
Set logfile = objFSO.CreateTextFile("logfile.txt",True)

ForReading = 1
	Set objTextFile = objFSO.OpenTextFile("servers.txt", ForReading)
	Do Until objTextFile.AtEndOfStream
		strComputer = objTextFile.ReadLine
		strComputer = UCASE(strComputer)
		logfile.WriteLine(Now & "| Current Server: " & strComputer)

		netStr = "\" & strComputer & path
		logfile.WriteLine(Now & "| Mapping Q drive to : " & netStr)

		objNetwork.MapNetworkDrive "Q:", netStr
		objFSO.CopyFile filename, "Q:patches-" & toBeFilename & ".htm"
		objNetwork.RemoveNetworkDrive "Q:"	
       Loop ' main loop'

Take a look at my script to remove the splash file, here.

Leave a Reply