Monday, July 7, 2008

TrainSignal Training Screwup.

My company recently purchased a $19,000 complete training set from TrainSignal with a full site license.

While the material is good, it only works when launched from a locally attached drive or local copy.

If you try to run the software from a UNC path \\server\trainsignal all items give an error.

Turned out that they were using a file called proxy.exe made by northwind renamed to whatever the media html file that needed to be executed. Under each media cd folder there was an fscommand folder with batch files and exe files of the same name(exe files were renamed proxy.exe files). The batch files contained the following command:

start ../4b/4b.html

Batch files cannot be executed properly from unc paths as they assume c:\windows as the working folder. So instead of launching \\server\share\4b\4b.html it executes c:\4b\4b.html which does not exist.

Some of the material used ftoolapp.exe to launch things with the same result.

This is all due to using Flash based menus instead of something that actually works properly outside of the browser world.

We were also able to integrate this into IIS by creating a link to the UNC path. Making a virtual directory will not help as when the menu.exe files are executed in IE, they execute from %username%\temporary internet files instead of the intended location.

Lesson to be learned: write your application for the intended platform to be used. Not just make it look nice using Flash. Testing different scenarios is not a bad idea either.

The script has a few different functions:

/change

runs through all subfolders of the execution location, so you would place the exe into the root of all the training material. Renames the existing .exe files that have a corresponding .bat name to .old

Also finds any ftoolapp.exe files, renames them to .old and makes a copy of itself instead.

/undo

Performs the same function as /change, except backwards. Deletes the new .exe files and renames the .old files to .exe

no switch

This is the intended mode for the batch file problem.

Checks its own name and finds the corresponding batch file. Reads the contents of the batch file and strips start ../ from the command. Executes the command as stated using the current unc or local path.

filename.xxx as a switch

This switch was made after i discovered another problem with some of the newer training material. It was launched using ftoolapp.exe filename.xxx, which exhibited the same problem with UNC.

If the operating system is Vista, checks for the presense of the TechSmith codec in the registry and checks the file extension for .wmv or .avi and Starts Windows Media Player %programfiles%\Windows Media Player\wmplayer.exe with the corresponding media file name. Other extensions launch using the associated application.

If the OS is Windows XP, executes whatever the associated media player file is.

I ran into problems on Vista trying to launch associated WMP files, WMP comes up empty and does not play. XP did not exhibit this problem.

Please dont use the old script i posted earlier. I found yet another glitch that needed changing. Here is the new one.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=UltraProxy.ico
#AutoIt3Wrapper_outfile=UltraProxy.exe
#AutoIt3Wrapper_compression=4
#AutoIt3Wrapper_useansi=y
#AutoIt3Wrapper_run_tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs
    ;    ----------------------------------------------------------------------------
    ;    Functions:
    ;        No switch execution
    ;            This is the intended use of the script.
    ;            Checks its own name and finds a corresponding batch file.
    ;            Reads the contents of the batch file and strips “start ../” from the command.
    ;            Executes the command without using the Windows command interpreter.
    ;        filename.xxx
    ;            This mode will start a Windows Media file that is specified.
    ;
    ;        /change
    ;            Will check current folder and all subfolders for presence of batch files.
    ;            If a batch file is found and it is not autorun.bat, the corresponding .exe file will be renamed to .old and the script will make a copy of itself in place of the .exe file.
    ;
    ;        /undo
    ;            Will check the current folder and all subfolders for the presence of batch files.
    ;            If a batch file is found and it has a corresponding .old file, the .exe will be deleted and the .old renamed to .exe.
    ;
    ;    ----------------------------------------------------------------------------
    ;    This script was made with a specific purpose of replacing the proxy.exe files used by TrainSignal training material
    ;    The renamed proxy.exe files would launch name.bat files which would not work over a UNC path.(\\blah\...)
    ;    This script will check it's name at startup, check the corresponding .bat file for the content,
    ;    strip the bat command and use the left over command to do a clean launch. Example: "start ../intro/intro.html will become \\ProperUNCPath/intro/intro.html
    ;    It is written with the specific spacing used in the TrainSignal application. Do not use it for anything else.
    ;
    ;    Feel free to modify at will.
    ;    Alex Belenkiy © ab@nyitsupport.com
    ;    07/07/2008
    ;
    ;    RecursiveFileSearch function was modified from http://www.autoitscript.com/forum/index.php?showtopic=58558&st=0
#ce
 
AutoItSetOption("TrayIconHide", 1)
AutoItSetOption("WinTitleMatchMode", 2)
AutoItSetOption("RunErrorsFatal", 0)
 
#include <array.au3>
 
If $CmdLine[0] = 0 Then
    Call("UltraProxy")
Else
    Select
        Case $CmdLine[1] = "/undo"
            $Undo = "1"
            Call("Change")
            
        Case $CmdLine[1] = "/change"
            $Undo = "0"
            Call("Change")
            
        Case Else
            Call("ftoolapp")
    EndSelect
EndIf
 
Func ftoolapp()
    If @OSVersion = "WIN_VISTA" Then
        If StringRight($CmdLineRaw, 4) = ".wmv" Or StringRight($CmdLineRaw, 4) = ".avi" Then
            If FileExists(@ScriptDir & "\Codec") Then
                $TSCC = RegEnumKey("HKEY_CURRENT_USER\Software\TechSmith", 1)
                If @error Then ShellExecuteWait(@ScriptDir & "\Codec\tscc.exe")
            EndIf
            ShellExecute(@ProgramFilesDir & "\Windows Media Player\wmplayer.exe", StringReplace(@ScriptDir & "\" & $CmdLineRaw, "/", "\", 0, 0))
        Else
            ShellExecute(StringReplace($CmdLineRaw, "/", "\", 0, 0), "", @ScriptDir)
        EndIf
    Else
        ShellExecute(StringReplace($CmdLineRaw, "/", "\", 0, 0), "", @ScriptDir)
    EndIf
EndFunc   ;==>ftoolapp
 
Func UltraProxy()
    $SP = StringTrimRight(@ScriptName, 4) & ".bat" ; Get launched name
    $BatchFile = FileOpen($SP, 0) ; Open corresponding batch file
    If $BatchFile = -1 Then Exit
    $SPL = FileReadLine($BatchFile, 1) ; Read the batch file command, first line only
    $new = StringReplace(StringTrimRight(@ScriptDir, 9) & StringTrimLeft($SPL, 9), "/", "\", 0, 0) ; trim off fscommand from the \\ProperUNCPath\ and 'start ../ from the batch command
    If @OSVersion = "WIN_VISTA" Then
        If StringRight($new, 4) = ".wmv" Or StringRight($new, 3) = ".avi" Then
            If FileExists(@ScriptDir & "\Codec") Then
                $TSCC = RegEnumKey("HKEY_CURRENT_USER\Software\TechSmith", 1)
                If @error Then ShellExecuteWait(@ScriptDir & "\Codec\tscc.exe")
            EndIf
            ShellExecute(@ProgramFilesDir & "\Windows Media Player\wmplayer.exe", $new)
        Else
            ShellExecute($new, "", @ScriptDir)
        EndIf
    Else
        Run(@ComSpec & " /c Start " & StringReplace($new, "/", "\", 0, 0), @ScriptDir, @SW_HIDE) ; Change all / to \ and run the necessary file.
    EndIf
EndFunc   ;==>UltraProxy
 
Func Change()
    MsgBox(64, "UltraProxy", "Converting Files. May take a few minutes." & @CRLF & @CRLF & "You will be notified upon completion" & @CRLF & @CRLF & "Please Wait...", 5)
    
    Dim $RFSarray[10240]
    Dim $Increment
    $Increment = 0
    $Array = RecursiveFileSearch(@ScriptDir)
    For $a = 1 To $Array[0]
        $ExeFile = StringTrimRight($Array[$a], 4) ;File name without extension
        Select
            Case $Undo = "0"
                ;if $ExeFile = "ftoolapp" then
 
                If Not FileExists($ExeFile & ".old") Then
                    If StringRight($ExeFile, 7) = "autorun" Then
                        ;do nothing
                    Else
                        FileMove($ExeFile & ".exe", $ExeFile & ".old")
                        FileCopy(@AutoItExe, $ExeFile & ".exe")
                        $Increment += 1
                    EndIf
                EndIf
            Case $Undo = "1"
                If FileExists($ExeFile & ".old") Then
                    FileDelete($ExeFile & ".exe")
                    FileMove($ExeFile & ".old", $ExeFile & ".exe")
                    $Increment += 1
                EndIf
        EndSelect
    Next
    MsgBox(64, "UltraProxy", "Finished." & @CRLF & @CRLF & $Increment & " out of " & $Array[0] & " files were processed.", 10)
EndFunc   ;==>Change
 
Func RecursiveFileSearch($startDir, $depth = 0)
    If $depth = 0 Then Global $RFSarray[1]
    $search = FileFindFirstFile($startDir & "\*.*")
    If @error Then Return
    ;Search through all files and folders in directory
    While 1
        $next = FileFindNextFile($search)
        If @error Then ExitLoop
        ;If folder, recurse
        If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then
            RecursiveFileSearch($startDir & "\" & $next, $depth + 1)
        Else
            If StringInStr($startDir & "\" & $next, ".bat") Then
                _ArrayAdd($RFSarray, $startDir & "\" & $next)
                $RFSarray[0] += 1
            ElseIf StringInStr($startDir & "\" & $next, "ftoolapp.exe") Then
                _ArrayAdd($RFSarray, $startDir & "\" & $next)
                $RFSarray[0] += 1
            EndIf
 
        EndIf
    WEnd
    FileClose($search)
    If $depth = 0 Then Return $RFSarray
EndFunc   ;==>RecursiveFileSearch

No comments: