ImageGear for Silverlight
Launching the ImageGear for Silverlight 20 TWAIN Component Installer at Runtime
Send Feedback
ImageGear for Silverlight User Guide > Using ImageGear for Silverlight > Using ImageGear.TWAIN Namespace > Using the ImageGear for Silverlight TWAIN Component Installer > Launching the ImageGear for Silverlight 20 TWAIN Component Installer at Runtime

Glossary Item Box

While the decision regarding how the TWAIN components will be installed is ultimately left to the application developer, there is at least one way to build an application that handles installation in a pseudo-automated fashion. Determination on whether or not installation is required can be determined via the ImGearTWAIN.IsAvailable property. 

Windows Vista and Windows 7

For Windows Vista and Windows 7, one method to accomplish installation at runtime is as follows:

  1. Host the ImageGear for Silverlight 20 TWAIN Component Installer at a location addressable by a URI, typically on a web server with the XAP package.
  2. Using the System.Net.WebClient type, download the installer using the OpenReadAsync method, and save the stream data to a local file.  Note that local file saves in Silverlight 4 are limited to the "My" folder locations, and require the application to be trusted, out-of-browser.
  3. Instantiate an instance of the Windows Scripting Host and launch the installer.
    C# Copy Code
    private void OnGoClick(object sender, RoutedEventArgs e)
    {
        Uri installAddress = new Uri(@"http://localhost/MyApplication/IGSLTwainSetupV6.exe");
        WebClient webClient = new WebClient();
        webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(OnWebClientOpenReadCompleted);
        webClient.OpenReadAsync(installAddress);
    }
    void OnWebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        Stream resultStream = null;
        try
        {
            resultStream = e.Result;
            if (AutomationFactory.IsAvailable)
            {
                //
                // Write installation to disk
                // 
                string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "IGSlTwainSetupV6.exe");
                using (FileStream fileStream = File.OpenWrite(path))
                {
                    byte[] buffer = new byte[1024];
                    int length;
                    while ((length = resultStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        fileStream.Write(buffer, 0, length);
                    }
                }
                //
                // Using COM automation, launch the install
                // 
                dynamic command = AutomationFactory.CreateObject("WScript.Shell");
                command.run(path, 1, true);
            }
        }
        finally
        {
            if (null != resultStream)
            {
                resultStream.Close();
            }
        }
    }
    This method can only be utilized by out-of-browser, trusted applications.

Windows XP

For Windows XP, the procedure described in the previous section cannot be used. For installation on a Windows XP machine, prompt the user to manually download and install the ImageGear for Silverlight TWAIN Component Installer.

©2013. Accusoft Corporation. All Rights Reserved.