ObjectClrOption

Sets CLR configuration options before the CLR is loaded and loads an assembly into the current WinBatch process.

Syntax:

ObjectClrOption (option-name, option-value )

Parameters

(s) option-name: available options are "version", "appbase", "use", or "useany".  See below for details.

(s) option-value: CLR version string, file system path, or assembly name depending on the option-name.

Returns:

(i) @TRUE on success.

 

The Option-name parameter values meaning and usage:

Option-name

Option-value

Version

Use this option to instruct WinBatch to load a specific version of the CLR. The option-value parameter string must start with the character "v" followed by the first three parts of the version number. Currently, Microsoft provides the following CLR versions "v1.0.3705", "v1.1.4322","v2.0.50727" and "v4.0.30319".  The option must be set before the first call to this function with the "use" or "useany" option or before the first call to the ObjectClrNew function.  If the "version" option is not used before the CLR is loaded, WinBatch will attempt to load the current system's latest installed version of the CLR.

Note: Be careful when using this Version option while debugging in WinBatch Studio. Once you load a specific version of the CLR while in debug mode the CLR stays loaded until you shutdown WinBatch Studio. Any further requests to load a specific version of the CLR are just ignored.  

ObjectClrOption('version','v4.0.30319')

 

Appbase

The option-value parameter for this option is used to indicate the full file system path that presents the location of assemblies you plan on using in your script that are not installed into the global assembly cache (GAC) of the system running the script. This option must be set before the first call to this function setting a "use" or "useany" option or before the first call to the ObjectClrNew function.

You DO NOT use the name of the file containing the assemblies with the 'Appbase' option. You Do specify the full (not partial) path to the location of the assemblies you are going to use in your script that are not in the GAC.   Logically this means that all non GAC assemblies need to be placed in the same directory for a given script.

ObjectClrOption('appbase','c:\DotNet\ThirdParty\MailSystem\ActiveUp.MailSystem_May2013_Binaries\Release\')

Use

This option is used to load assemblies into the WinBatch process. Assemblies must be loaded before the types the assembly implements can be used.  The option-value parameter for this option must be a string variable or literal containing an assembly name.  If an assembly is stored in the GAC, it is generally necessary to use the fully qualified assembly name.  The fully qualified assembly name has the format "assembly's name, version=x.x.x.x, culture=xxxx, PublickeyToken=xxxxxxxxxxxxxxxx".  For example, the fully qualified name of the "System.Data" assembly is "System.Data, version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". Full assembly names can be found by using the Mscorcfg.msc tool, by view the Global Assembly Cache (GAC) directory directly, or by using the Gacutil.exe tool.

ObjectClrOption ("use","System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")

 

UseAny

This option is similar to the function's "use" option for loading assemblies except that it does not require a strong assembly name.   Instead the option attempts to load an assembly using the assembly's weak name. An assembly's weak name is an assembly name without the Version, Culture, PublicLeyToken and optional processorArchitecture values. The function performs the "useany" task by searching the Global Assembly Cache (GAC) for the latest version of the named assembly.  It is not necessary to use the option to load non-GAC assemblies because the CLR does not require that non-GAC assemblies have strong assembly names.  Setting the CLR version using this function's "version" option limits "useany" to search for GAC assemblies associated with the specified version and older versions of the CLR..

ObjectClrOption ("useany","System")

 

Example:
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ObjectClrOption - Version
; Instruct WinBatch to load a specific version of the CLR
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ObjectClrOption("version","v1.0.3705")
;ObjectClrOption("version","v1.1.4322")
;ObjectClrOption("version","v2.0.50727")
ObjectClrOption("version","v4.0.30319")

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Create a class implemented by a managed assembly. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ objEnviron = ObjectClrNew("System.Environment" )
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Version Method - Gets CLR Version ; major,minor,build and revision numbers ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ result = objEnviron.Version.ToString()
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Display results ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Pause("System.Environment", result ) Exit

 

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ObjectClrOption - Use
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
process = 'C:\Windows\Notepad.exe'
friendlyname = 'Notepad'
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Version - Instruct WinBatch to load a specific version of the CLR
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;ObjectClrOption ("version","v1.0.3705")
;ObjectClrOption ("version","v1.1.4322")
;ObjectClrOption ("version","v2.0.50727")
ObjectClrOption ("version","v4.0.30319")

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Use - Load assembly into the WinBatch process ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ObjectClrOption ("use","System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Create a class implemented by a managed assembly. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ objnetProcess = ObjectClrNew("System.Diagnostics.Process" )
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Start a process ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ objnetProcess.Start(process) TimeDelay(1)
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; GetProcessesByName method ; Creates an array of new Process components and associates them with all the ; process resources on the local computer that share the specified process name. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ arrProcesses = objnetProcess.GetProcessesByName(friendlyname) If ArrInfo(arrProcesses, 1 ) >= 1 ; Get first matching process myProcess = arrProcesses[0] myProcess = ObjectClrType("System.Diagnostics.Process",myProcess) ; Tests the Responding property for a @True return value. action = 'No Op ' If myProcess.Responding myProcess.CloseMainWindow() action = 'Closed ' Else ;Forces the process to close if the Responding value is @False. myProcess.Kill() action = 'Killed ' EndIf EndIf ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; Display results ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Pause(friendlyname, action : friendlyname ) Exit

 

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Load non GAC assemblies into the WinBatch process.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; AppBase: You DO NOT use the names of files containing assemblies (i.e. ActiveUp.Net.Imap4.dll)  with the 'AppBase' option.
; You Do specify the full (not partial) path to the location of the assemblies you are going to use in your script that are not in the GAC.
; Logically this means that all non GAC assemblies need to be placed in the same directory for a given script.
assemblydir = 'C:\SCRIPT LIBRARY\DotNet\Third Party\MailSystem\ActiveUp.MailSystem_May2013_Binaries\Release\'
ObjectClrOption('appbase',assemblydir)
ObjectClrOption ('use','ActiveUp.Net.Imap4, Version=5.0.3454.364, Culture=neutral, PublicKeyToken=9d424b1770e92b68')
Exit
See Also:

ObjectClrNew, ObjectClrType, ObjectType, ObjectTypeGet