Although many of us are now looking towards .NET technologies there is still worth in Classic ASP and Classic based VB applications. Moving forward in the industry using .NET technologies makes sense but unfortunately it hasn't been around forever and there is still allot of CLassic ASP applications out there and Classic VB applications. The worth of VB script for simple server side manipulation of file structures and Application manipulation are still apparent and in use today.
Over the years in Senior developer positions and Network Operations often working within architecture planning and implementations i have often hit walls that i have managed to overcome using VB script and good old Command line hooks. Working for companies that were modeled around SAAS (Software as a service) the need for hardware and cluster management was apparent. Using VB script to manipulate permissions to lock down possible exploits came in very handy, also using VB script for provisioning of services and automated tasks simplified allot of the hard manual labor, even virus scanning and network packet monitoring using VB had its uses.
Still it all sounds good but it sounds old hat and why would you want to do that?
Well..... still some of the largest suppliers within the UK of e-commerce use the legacy VB script automation written by our systems staff and its proven as easy to maintain and easy to upgrade. Server provisioning is done completely within scheduled VB hooks using CLI shells to automate tasks. Of course we cant mention names but its safe to say that one example is the largest UK based hosted e-commerce provider and before you think it its not Actinic its bigger! Another being logistics management systems and payment gateways.
So give me some examples if its so good i hear you cry....
Ok... lets take a hypothetical situation. Lets say i have 2 servers, i want to mirror the entire file structure by mapping a drive copying the entire contents, oh and lets not forget i don't want to set the permissions manually as its used for a web service, But to be more secure i want to map the drive, copy, then drop the connection. Lets look at an example and then i will explain.
-------------------------------------------------------------------------------------------------------------------------------------------
' Section A
strDriveLetter = "Z:"
strRemotePath = "\\SLAVESERVER\d$"
strUser = "atempadmin"
strPassword = "password"
strProfile = "false"
' Section B
set objShell = wscript.createObject("wscript.shell")
Set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
strProfile, strUser, strPassword
path1 = "D:\"
path2 = "Z:\"
' Section C
set fso = CreateObject("Scripting.FileSystemObject")
set tfile = fso.CreateTextFile(path1 & "\lastdone.txt")
tfile.WriteLine(now())
' Section D
iReturn = objShell.Run("cmd.exe /C xcopy " & path1 & " " & path2 & " /e /Y /F /O /EXCLUDE:D:\web\server side\MyExcludes.txt", 1, TRUE)
iReturn = objShell.Run("cmd.exe /C xcopy " & path2 & " " & path1 & " /e /Y /F /O /EXCLUDE:D:\web\server side\MyExcludes.txt", 1, FALSE)
-------------------------------------------------------------------------------------------------------------------------------------------
Okay so what does it do?
The above script would be run on the server to be mirrored. I have split the script into sections A through D and i will explain each section and what is does. IN this eaxmple xcopy was used as its a stock tools supplied by any version of DOS, its a powerful tool and has the ability to copy ACL information saving the use of other CMD tools such as CACLS. So section A this holds the authentication information required to open a mapped drive using the WScript.Network method.
Section B, well this actually maps the drive using the details in section A. Also it sets up the shell object to run the CLI for the xcopy coming later in the script. When the script executes it will execute using a user that is the member of the system group, this will allow pretty much any CLI command to execute without permission issues. Also i have used this section to define the two paths, in this case the two drive letters.
Section C, I wanted to be able to create a simple 1 line log saying when the last sync occurred so this section basically creates a filesystem object and writes a line with a date/time. I can then recall this later if i wanted with an ASP file etc to pull back the value contained.
Finally Section D, this copies everything, however you will see 2 xcopy commands, this copies everything from the master to the slave, then it copies back incase there's anything new on the slave so that it is held on the master. As the initial copy goes master to slave then anything that has been updated on the slave that should not have been will simply be overwritten. Xcopy is a great command and well worth looking up. There's also an excludes files that tells xcopy to ignore certain files.
So there's one example, when we develop an application its not just about writing a system that does a job. We write systems that you can move from one system to another but also systems that get the most out of the environment. that they are hosted or managed on. Why have a system and a systems administrator. It makes more sense to have a system that manages itself as much as possible. Information on systems development can be found at www.angel-media.net