Silverlight 4 COM issue

FileNotFoundException

Page 1 of 1

6 Replies - 5366 Views - Last Post: 15 June 2010 - 02:53 AM

#1 megglz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

Silverlight 4 COM issue

Posted 31 May 2010 - 05:51 AM

Currently following an OOB tutorial, for some reason it does not find the file to open even though the path is correct? Maybe I'm missing something.

My code is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.InteropServices.Automation;

namespace ClientTest
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnInstall_Click(object sender, RoutedEventArgs e)
        {
            if (Application.Current.InstallState == InstallState.NotInstalled)

                Application.Current.Install();
        }

        private void txtOpenProgram_Click(object sender, RoutedEventArgs e)
        {

            using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
            {
                 
                shell.Run(@"C:\Program Files\Notepad++\notepad++.exe");
                shell.SendKeys(txtTextToSend.Text);

            }

        }

    }



I am using VS 2010, Silverlight 4 and .NET 4

Is This A Good Question/Topic? 0
  • +

Replies To: Silverlight 4 COM issue

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Silverlight 4 COM issue

Posted 01 June 2010 - 04:36 AM

shouldn't that use the ComAutomationFactory

using (dynamic shell = ComAutomationFactory.CreateObject("WScript.Shell"))
{            
   shell.Run(@"C:\Program Files\Notepad++\notepad++.exe");
   shell.SendKeys(txtTextToSend.Text);
}


Was This Post Helpful? 0
  • +
  • -

#3 megglz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

Re: Silverlight 4 COM issue

Posted 01 June 2010 - 05:26 AM

View Posteclipsed4utoo, on 01 June 2010 - 11:36 AM, said:

shouldn't that use the ComAutomationFactory

using (dynamic shell = ComAutomationFactory.CreateObject("WScript.Shell"))
{            
   shell.Run(@"C:\Program Files\Notepad++\notepad++.exe");
   shell.SendKeys(txtTextToSend.Text);
}



I thought that too, but apparently it's been changed to AutomationFactory?

Quote

http://timheuer.com/...4-rc-mix10.aspx

API changes in the naming of the native integration (COM interop) feature for trusted applications.

Was This Post Helpful? 0
  • +
  • -

#4 megglz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

Re: Silverlight 4 COM issue

Posted 08 June 2010 - 08:25 AM

It seems the path “C:\windows\notepad.exe” is system-protected. Although the Silverlight application is given Elevated Trust, it still cannot open the system protected executables. I changed the path to “notepad.exe” and it now works (because WScript.Shell is run in system environment, the full path of notepad is contained in PATH Environment variable).

However, I want to try opening another application in Program Files. This won't open again no matter what way I give the path :/ Anyone know why?
Was This Post Helpful? 0
  • +
  • -

#5 megglz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

Re: Silverlight 4 COM issue

Posted 08 June 2010 - 08:52 AM

Solved, I needed extra quotation marks!
Was This Post Helpful? 2
  • +
  • -

#6 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Silverlight 4 COM issue

Posted 09 June 2010 - 08:54 AM

Can you post the code that now works?
Was This Post Helpful? 0
  • +
  • -

#7 megglz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

Re: Silverlight 4 COM issue

Posted 15 June 2010 - 02:53 AM

Mainpage.xaml

<UserControl x:Class="ClientTest.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel>
            <Button x:Name="OpenProgram" Content="Open Program" Click="OpenProgram_Click"  />
        </StackPanel>


    </Grid>
</UserControl>



Mainpage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.InteropServices.Automation;
using System.IO;

namespace ClientTest
{
    /*Note: ComAutomationFactory has been renamed to 
    AutomationFactory in Silverlight4
*/
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnInstall_Click(object sender, RoutedEventArgs e)
        {
            if (Application.Current.InstallState == InstallState.NotInstalled)

                Application.Current.Install();
        }

        private void OpenProgram_Click(object sender, RoutedEventArgs e)
        {
            
            using (dynamic shell = AutomationFactory.CreateObject("WScript.Shell"))
            {
                shell.Run(@"""C:\Program Files\UltraVNC\vncviewer.exe """);
            }
        }

    }
}


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1