The Ultimate Portable Build - Part 3 - Scripting

As you can gather by now, I don't like to edit delivered Bentley files and avoid using any installed directories when it comes to users files. To that end I've always used a custom area, something along the line of c:\Apps and had a series of batch files within the build do all the work for me. My aim has always to have CADmanage fill in the blanks and take the manual work out of setting up a lot of the build. To this end we set up the pathing to our admin area using relative pathing:

AdminPath = DRV_Root + "\_Admin\"
oEnv("hta_sAdminPath") = Replace(AdminPath, "/", "\")
AdminScriptsPath= AdminPath + "Scripts\"
'msgbox AdminScriptsPath
'msgbox AdminScriptsPath + "user_create_local.bat"

The scripts directory is where we run the batch files from. These batch files are loaded at certain times so the right directories are created and the user files are backed up.
To create the user area we have:
WshShell.Run AdminScriptsPath & "user_create_local.bat" ,0
Again, having ,0 at the ends means you don't have the dos window come up each time a batch file is run.

This batch file checks to see if the user area exists and if it doesn't, goes ahead and creates it (note the use of the process environment variables from the hta):
if not exist C:\Apps\Users\%username% goto USERCREATE rem pause
rem pause
mkdir C:\Apps\Users\%username%\Bentley
goto check
rem pause
I then look to see if the user area has been created and if the users has their files on the network. We'll go through how to do that soon. If the user has files backed up they are then copied down to the local user area. this way the users files are portable and the users doesn't have to lift a finger:
if exist %hta_sAdminPath%Users\%username% goto CopyR
xcopy %hta_sAdminPath%Users\%username%\Bentley\*.* C:\Apps\Users\%username%\Bentley\ /e /h /s /r /k /y

If the user is new and doesn't have any files, then the next batch file goes ahead and creates them as required. This comes from:
WshShell.Run AdminScriptsPath & "std_cad.bat" ,0
I won't copy the whole files, but some examples are below:
    if exist C:\Apps\Users\%username%\Bentley\ goto UCF85Check
if exist "C:\Apps\Users\%username%\Bentley\%USERNAME%_MS811.UCF" goto UCF811END
if not exist "C:\Apps\Users\%username%\Bentley\%USERNAME%_MS811.UCF" goto UCFV811ADD
goto UCF811END
xcopy %hta_sBentley%Standard\MS811\Standards\data\blank_MS811.ucf C:\Apps\Users\%username%\Bentley\
rename "C:\Apps\Users\%username%\Bentley\blank_MS811.ucf" %username%_MS811.ucf
rem pause

if exist "C:\Apps\Users\%username%\Bentley\%USERNAME%_MS811.UPF" goto UPF811END
if not exist "C:\Apps\Users\%username%\Bentley\%USERNAME%_MS811.UPF" goto UPFV811ADD
goto UPF811END
xcopy %hta_sBentley%Standard\MS811\Standards\data\blank_MS811.upf C:\Apps\Users\%username%\Bentley\
rename "C:\Apps\Users\%username%\Bentley\blank_MS811.upf" %username%_MS811.upf
rem pause

if exist "C:\Apps\Users\%username%\Bentley\accudraw_MS811.key" goto KEY811END
if not exist "C:\Apps\Users\%username%\Bentley\accudraw_MS811.key" goto KEY811ADD
goto UPF811END
xcopy %hta_sBentley%Standard\MS811\Standards\data\blank_MS811.key C:\Apps\Users\%username%\Bentley\
rename "C:\Apps\Users\%username%\Bentley\blank_MS811.key" accudraw_MS811.key
rem pause

if exist "C:\Apps\Users\%username%\Bentley\PERSONAL_MS811_SS3.MNU" goto FKEY811_SS3END
if not exist "C:\Apps\Users\%username%\Bentley\PERSONAL_MS811_SS3.MNU" goto FKEY811_SS3ADD
goto UPF811_SS3END
xcopy %hta_sBentley%Standard\MS811_SS3\Standards\data\PERSONAL_MS811_SS3.MNU C:\Apps\Users\%username%\Bentley\
rem pause

if exist "C:\Apps\Users\%username%\Bentley\%USERNAME%_MS811_SS3.UCF" goto UCF811_SS3END
if not exist "C:\Apps\Users\%username%\Bentley\%USERNAME%_MS811_SS3.UCF" goto UCFV811_SS3ADD
goto UCF811END
xcopy %hta_sBentley%Standard\MS811_SS3\Standards\data\blank_MS811_SS3.ucf C:\Apps\Users\%username%\Bentley\
rename "C:\Apps\Users\%username%\Bentley\blank_MS811_SS3.ucf" %username%_MS811_SS3.ucf
rem pause

if exist "C:\Apps\Users\%username%\Bentley\%USERNAME%_MS811_SS3.UPF" goto UPF811_SS3END
if not exist "C:\Apps\Users\%username%\Bentley\%USERNAME%_MS811_SS3.UPF" goto UPFV811_SS3ADD
goto UPF811END
xcopy %hta_sBentley%Standard\MS811\Standards\data\blank_MS811_SS3.upf C:\Apps\Users\%username%\Bentley\
rename "C:\Apps\Users\%username%\Bentley\blank_MS811_SS3.upf" %username%_MS811_SS3.upf
rem pause

if exist "C:\Apps\Users\%username%\Bentley\accudraw_MS811_SS3.key" goto KEY811_SS3END
if not exist "C:\Apps\Users\%username%\Bentley\accudraw_MS811_SS3.key" goto KEY811_SS3ADD
goto UPF811END
xcopy %hta_sBentley%Standard\MS811_SS3\Standards\data\blank_MS811_SS3.key C:\Apps\Users\%username%\Bentley\
rename "C:\Apps\Users\%username%\Bentley\blank_MS811_SS3.key" accudraw_MS811_SS3.key
rem pause

if exist "C:\Apps\Users\%username%\Bentley\PERSONAL_MS811_SS3.MNU" goto FKEY811_SS3END
if not exist "C:\Apps\Users\%username%\Bentley\PERSONAL_MS811_SS3.MNU" goto FKEY811_SS3ADD
goto UPF811END
xcopy %hta_sBentley%Standard\MS811\Standards\data\PERSONAL_MS811_SS3.MNU C:\Apps\Users\%username%\Bentley\
rem pause

if not exist C:\Apps\Users\%username%\Bentley\MS811\ GOTO VERCREATE

xcopy %hta_sBentley%Standard\MS811\Standards\data\blankuser\Bentley\*.* /E C:\Apps\Users\%username%\Bentley\


The VERCREATE at the end create the version files that store the different TriForma based preference files that are created by Structural Modeller, AECOsim etc. As each version needs it's own location I have a version directory for each. 
Now that the user files and area have been created. I like to keep a copy of the file on the network so users can have them copy down as they switch machines and so I can check them if the user has problems. to do this another batch files is called up in the hta as the hta is closed:
Sub Window_onBeforeUnLoad
WshShell.Run AdminScriptsPath & "user_copy_network.bat" , 0
end sub
This looks like:
if not exist %hta_sAdminPath%Users\%username% goto USERCREATE 

rem pause
mkdir %hta_sAdminPath%Users\%username%\Bentley
goto copy
rem pause

xcopy C:\Apps\Users\%username%\Bentley\*.* %hta_sAdminPath%Users\%username%\Bentley\ /e /h /s /r /k /y
So, for a new user the user area is created and then the files copied up to the build location. Very handy bit of work for admins here.
Basically, that's it. A few well thought through batch files that do a LOT of work and save a LOT of manual time and labour. A massive time saver for a CAD Admin.
There is one more things I have batch files do. You may have read before that I use chm help files for my users and builds. The thing with these is that they must be opened locally due to Microsoft permissions. To do that I have one more batch file run:
WshShell.Run AdminScriptsPath & "std_cad_Link.bat" ,0
Which looks like:
xcopy "%hta_sAdminPath%Docs\knowledgebase\*.*" "C:\Apps\Users\Docs\" /e /r /y
This could be used to copy any other files locally as well, but if a good way of getting them down to run quicker and easier.
OK, so there are other ways to do this with vbscript and more, but this is only a guide for you and when you have most of the work done for you as I have then why invent the wheel.
More soon.
  • Happy to have any and all comments Ivo. At least I know one person is getting some interest in this :-)

  • I hope I am not interfering with the chronology of your blogs. They make a good sequential array of tutorials.

    Perhaps you can use NET SEND to keep you informed of every time a user fires your batch files. Of course this only works when you are logged in and if IT did not disable NET SEND.

  • Beat me to it Ivo. Was going to cover that later, but you got me. I keep log files as checks, just to monitor all is working well, but usually get a call before I get any chance to find anything in a check. I keepmthe log files in the user area so they are backed up where I can view them.

  • CMD is stil very much alive.

    I use batch files alike to perform similar actions, although I always keep them visible to monitor progress. I often use some extra lines of code to produce log files and pass comments to screen. This way both I and the user can keep track what went right or wrong. Here's an example of a batch file that writes to a new text file (with the users name as a file name) in a folder called log. It adds the machine name, date and time plus the name and path of the batchfile that created it. After checking for a folder called "C:\Work\" it will copy a file there and report progress to the log. If it fails to find the folder called C:\Work\" it will show and log a warning. I thought I should share.

    Echo ############################### > log\%username%-build.txt

    Echo "%~f0" started by %username% on %computername% on %DATE% at %TIME% >> log\%username%-build.txt

    IF EXIST "C:\Work\" (

    Echo Folder Work does exist. >> log\%username%-build.txt

    COPY "template.UCF" "C:\Work\%username%.UCF" /v/y >> log\%username%-build.txt

    goto Knock

    ) ELSE (

    ECHO The folder called Work is absent on this machine.

    Echo The folder called Work is absent on this machine. >> log\%username%-build.txt

    start %comspec% /c "mode 45,7&Title WARNING&color 9F&echo.&echo.Folder 'Work' was not found!&echo.&echo.Contact your CADmanager!&echo.&echo.Press any key to exit!&pause>NUL"

    goto Knock


    goto Knock


    Echo Finished on %DATE% at %TIME% >> log\%username%-build.txt

    Echo ############################### >> log\%username%-build.txt