Command-Line Status Updates in VBScript

I use subversion on all the applications I work on, which comes out to be about 41 different trunks.  I wrote a VBS that checks my network adapters' ip addresses to see if I'm on one of my company's ips, and if I'm not to automatically VPN me in, checks my repositories, updates all of them, checks out any new applications that I don't have, and writes out a log that auto truncates anything that's over a week old.  This all works fine.

What I'm looking to do is open a command prompt at the start of the script and write status updates in this command prompt as the script finishes certain tasks, i.e. after each update, it writes a line to the command prompt saying Application - Updated or Application - Checked Out.

This script runs on start up, so it's not being run from there.

I can open a command prompt with a single command using WshShell.Run "%comspec% /k echo Hello World", but I want to be able to have it hold that prompt and add new echos to it as the script progresses.

Any help is appreciated.
LVL 2
mmaxwell43534Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmaxwell43534Author Commented:
Here's the code for the file.

I prompt for a VPN password because I gave this to the other two programmers on my team, and I don't like hard-coding passwords.

Hopefully this gives you a better idea of how I'm looking to incorporate the echos.
Dim fso, objFolder, wshShell, objCmd, textFile, folder, message, prerun, msging, objNACs, objWM, objNAs, needVPN, vdirObj, webroot, objNetwork, username, pwd, thisLine, alltext, alltext2, i
prerun = msgBox("Would you like to check the SVN repositories for updates?",VBYesNo,"SVN Pre-Run")
If Int(prerun)=6 Then
	needVPN = 1
	Set objWM = GetObject("winmgmts:\\.\root\cimv2")
	Set objNAs = objWM.InstancesOf("Win32_NetworkAdapter")
	For Each objNA in objNAs
		Set objNACs = objWM.ExecQuery(" SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " & objNA.Index)
		 For Each objNAC in objNACs
			If IsArray(objNAC.IPAddress) Then
				For Each ipAddress in objNAC.IPAddress
					If UBound(Split(ipAddress,"xx.xx"))>0 OR UBound(Split(ipAddress,"xx.xx"))>0 OR UBound(Split(ipAddress,"xx.xx"))>0 Then
						needVPN = 0
					End If
				Next
			End If
		Next
	Next
	Set objWM = Nothing
	Set objNAs = Nothing
	Set objNACs = Nothing
	Set WshShell = WScript.CreateObject("WScript.Shell")
	If needVPN = 1 Then
		pwd = InputBox("Please Enter your VPN Password")
		WshShell.Run """C:\Program Files\Cisco Systems\VPN Client\vpngui.exe"" -c -sd -user " & username & " -pwd " & pwd
		Dim thedate
		thedate = Now
		do
		loop while DateAdd("n",2,thedate)>Now
	End If
	Set objNetwork = WScript.CreateObject("WScript.Network")
	username = objNetwork.UserName
	Set objNetwork = Nothing
	Set vdirObj=GetObject("IIS://localhost/W3svc/1/Root")
	webroot = vdirObj.Path
	Set vdirObj = Nothing
	Set fso = CreateObject("Scripting.FileSystemObject")
	If fso.FileExists("svnupdate_log.txt") Then
		Set textFile = fso.OpenTextFile("svnupdate_log.txt")
		alltext2 = Split(textFile.ReadAll(),"_________________________________________________" & vbCrLf)
		textFile.Close
		i=1
		do
			If DateAdd("d",-7,Now)<CDate(Split(alltext2(i),vbCrLf)(0)) Then
				alltext = alltext & "_________________________________________________" & vbCrLf & alltext2(i)
			End If
			i=i+1
		loop while i<=UBound(alltext2)
	End If
	Set objFolder = fso.GetFolder("\\myserver\mydrive\svn")
	message = "_________________________________________________" & vbCrLf & Now & vbCrLf
	For each folder in objFolder.Subfolders
		If folder.Name<>"repos-structure" Then
			If fso.FolderExists(webroot & "\" & folder.Name) Then
				WshShell.Run "%comspec% /c svn update """ & webroot & "\" & folder.Name & """>svnupdate_log.txt", 0, True
				Set textFile = fso.OpenTextFile("svnupdate_log.txt",1)
				thisLine = Split(textFile.ReadAll(), vbCrLf)
				textFile.Close
				i = 0
				message = message & folder.Name & " - Updated " & thisLine(UBound(thisLine)-1) & vbCrLf
				do while i<UBound(thisLine)-1
					message = message & vbTab & thisLine(i) & vbCrLf
					i=i+1
				loop
			Else
				fso.CreateFolder folder.Name
				WshShell.Run "%comspec% /c svn checkout http://myserver:myport/svn/" & folder.Name & "/trunk """ & webroot & "\" & folder.Name & """>svnupdate_log.txt", 0, True
				Set textFile = fso.OpenTextFile("svnupdate_log.txt",1)
				thisLine = Split(textFile.ReadAll(), vbCrLf)
				textFile.Close
				i = 0
				message = message & folder.Name & " - Checked Out " & thisLine(UBound(thisLine)-1) & vbCrLf
				do while i<UBound(thisLine)-1
					message = message & vbTab & thisLine(i) & vbCrLf
					i=i+1
				loop
			End If
		End If
	Next
	Set textFile = fso.CreateTextFile("svnupdate_log.txt", true)
	textFile.Write(message & alltext)
	textFile.Close
	Set textFile = Nothing
	Set fso = Nothing
	Set objCmd = Nothing
	Set objFolder = Nothing
	Set WshShell = Nothing
	msgBox("SVN Update Has Completed!")
End If

Open in new window

0
RobSampsonCommented:
Hi, you could either launch your script with
cscript c:\MyScript.vbs

and then use
WScript.Echo "Some Text"

statements throughout your code.

Or, you can add the code block below to the start of your script to have it automatically launch in CScript if you haven't done than to start with.

Regards,

Rob.
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /c cscript  """ & strPath & """"
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmaxwell43534Author Commented:
This worked beautifully.  I knew there was something small I was missing.

Thanks.
0
mmaxwell43534Author Commented:
Quick and to the point, and exactly what I needed.
Thanks.
0
RobSampsonCommented:
No problem. Thanks for the grade.

Regards,

Rob.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.