'VEE starter VBS script.
'Use to launch .vee files by different veerev tags.
'here, veerev "5.0" opens with 6.2 and "7.0......" opens with 7.03.
'Clone below to paste new releases; add / remove vars between outlined areas.
'
' Mr.Antti Suhonen,         Senior Test System Designer
' Extrabit Ltd.,            'Production Laboratory'
' Automaatiotie 1,          FIN-90460 Oulunsalo
' FINLAND
'
' Phone:                    +358 40 3444054
' E-mail:                   Antti.Suhonen at elektrobit.com
'
' http://www.extrabit.fi,   Your partner in high-end production
' Extrabit ltd. is a member of Elektrobit Group.
'
'Use at free will as long as you include this header.
'DISCLAIMER:
'Extrabit ltd. will not give any warranty whatsoever for this script,
'including or excluding anything it does or doesn't do. 
'By using this script, you will use it at own risk.
'...and other yada yada.
'
'OK. Code section below, 'editable' sections outlined.

'editor to be used in changes:
	editor = "notepad.exe"									'what to use to edit script?

'add here paths to VEE executables
'_____________________________________________________________________________________________________________

	path_4_0 = "C:\Program Files\Hewlett-Packard\VEE 4.0\vee.exe"
	path_5_0 = "C:\Program Files\Hewlett-Packard\VEE 5.0\vee.exe"
	path_6_0 = "C:\Program files\Agilent\VEE Pro 6.0\vee.exe"
	path_7_0 = "C:\Program files\Agilent\VEE Pro 7.0\vee.exe"
	path_7_5 = "C:\Program files\Agilent\VEE Pro 7.5\vee.exe"
'_____________________________________________________________________________________________________________

sub decide()
	select case veeRev
'_____________________________________________________________________________________________________________

 	case "3.2"		Launch(path_6_0)
 	case "4.0"		Launch(path_4_0)
 	case "5.0"		Launch(path_5_0)
	case "6.0"		Launch(path_6_0)
	case "6.1"		Launch(path_6_0)
 	case "6.2"		Launch(path_6_0)
	case "7.0"		Launch(path_7_0)
	case "7.5"		Launch(path_7_5)
	case "8.0"		Launch(path_7_5)
'_____________________________________________________________________________________________________________
	
	case Else   edit()
			msgBox ("Don't know what do do with veeRev '" & veeRev & "'. Edit '" &_
				 Wscript.ScriptFullName & "', look for two outlined areas."), vbExclamation, "Hep!"
	End Select
	Wscript.quit 1
end sub


'program start...
'set vars, get cmd line args, create objects...
	on Error Resume Next
	dim args, shell, FSO, f, fn
	set args = WScript.Arguments
	Set FSO = CreateObject("Scripting.FileSystemObject")
	Set Shell = CreateObject("WScript.Shell")
	key =  "HKEY_CLASSES_ROOT\VEE.Program\shell\"
			
'check if this file is associated with .vee files, offer to associate...

	if checkLauncherAssociation() Then
		BtnCode = Shell.Popup	("Seems that '" & Wscript.ScriptFullName & "' is NOT associated with VEE files. " &_
						 "Associate?", 0, "Register, eh?", vbYesNo + vbQuestion)
		Select Case BtnCode
   			case 6      createLauncherAssociation()
 			case 7      msgBox "Launcher not associated."
		End Select
		wscript.quit 1
	end if

'check if correct use, one argument at a time, has to contain '.vee'
	
	if (args.Count) <> 1 OR Right(LCase(args(0)),4) <> ".vee" Then
		BtnCode = Shell.Popup	("'" & Wscript.scriptFullName & "' is already registered to launch .vee files. " &_
						"Revert back to last used?", 0, "Unregister, eh?", vbYesNo + vbQuestion + vbDefaultButton2)
		Select Case BtnCode
   			case 6      removeLauncherAssociation()
		End Select
		WScript.Quit 1
	end if
		
'create FSO & open file (if args), read 1st line, split with '"' char...
	
	Set f = FSO.OpenTextFile(args(0), 1)
	format = f.readLine
	format = f.readLine
	format = f.readLine
	f.close
	
	format = Split(format, Chr(34), -1, 1)						'split splat...

'Chr(34) is '"'
'now veeRev string is split as follows:
'(0) (veerev 
'(1) 7.5.7714.0
'(2) )

	veeRev = left(format(1), 3)								'we need only 3 first chars to make a decision...
	decide()											'Case decision here...

'End of execution, if program reached this far...





'few functions below...

Function checkLauncherAssociation
	checkLauncherAssociation = -1
'check whether shell default action and shell command are in place...
	if Shell.RegRead(key) = "open_with_launcher" AND InStr(Shell.RegRead(key &_
					"open_with_launcher\command\"), Wscript.ScriptFullName) <> 0 Then
		checkLauncherAssociation = 0
	end if
end Function

Function createLauncherAssociation
	Shell.Regwrite 	key, "open_with_launcher", "REG_SZ"
	Shell.Regwrite 	key & "\open_with_launcher\command\", "wscript.exe " & chr(34) & Wscript.ScriptFullName &_
				" " & chr(34) & " " &chr(34) & "%1" & chr(34), "REG_SZ"
	if checkLauncherAssociation() Then
 		msgBox 	"Launcher association with .vee files failed in HKCR\VEE.Program\shell! " &_
				"Check your registry access rights!", vbCritical, "ATTENTION!" 
		wscript.quit 1
	end if
	msgBox 		"Launcher association with .vee files succesful! Double-click VEE file " &_
				"to launch it w/defined VEE version.", vbInformation, "SUCCESS!"
end Function

Function removeLauncherAssociation
	Shell.Regwrite key, "open", "REG_SZ"
	if Shell.RegRead(key) = "open" Then
		msgBox 	"Launcher association with .vee files removed.", 0+64, "SUCCESS!"
	else 	msgBox 	"Launcher association removing failed at HKCR\VEE.Program\shell! " &_
				"Check your registry access rights!", vbCritical, "ATTENTION!"
	end if
end Function


Function Launch(VEEPath)
'time for some VEE magic...
	if FSO.FileExists(VEEPath) Then
		Shell.Run(Chr(34) & VEEPath & Chr(34) & " " & Chr(34) & parseLongName() & Chr(34))
	Else 	edit()
		msgBox "Vee program file '" & VEEPath & "' Missing!!! Edit '" &_
			 Wscript.ScriptFullName & "'!!!", vbCritical, "ATTENTION!"
	end if
end Function	

Function parseLongName 
	Dim sc
	Set sc = Shell.CreateShortcut("sc.lnk") 
	sc.TargetPath = args(0) 
	parseLongName = sc.TargetPath 
End Function 

public function edit
	shell.run editor & " " & chr(34) & Wscript.ScriptFullName & chr(34)	'splash script to be edited
end function