Jamey McElveen
Jamey McElveen

Reputation: 18305

Can Silverlight (SLOOB) start a process even with full trust?

I have been tasked with writing an installer with a silverlight out of browser application. I need to.

  1. get the version off a local EXE
  2. check a web service to see that it is the most recent version
  3. download a zip if not
  4. unpack the zip
  5. overwrite the old EXE
  6. start the EXE

This installer app is written in .NET WinForms now but the .NET framework is an obstacle for people to download.

The recommended solution is to use a SLOOB however i am not sure how to assign full trust. If i assign full trust can I start a process.

Thanks

Upvotes: 1

Views: 1990

Answers (2)

Cine
Cine

Reputation: 4402

Silverlight 4 will have support for something like this: http://timheuer.com/blog/archive/2010/03/15/whats-new-in-silverlight-4-rc-mix10.aspx#sllauncher

Upvotes: 1

Ben Von Handorf
Ben Von Handorf

Reputation: 2336

Looking into this, I suspect you're going to have to create the process using WMI through the COM interface. At the end of the day, that makes this a very difficult option and very subject to failure due to a host of reasons (WMI being disabled or secured, user won't give full trust, etc.) I suspect you would be much better off creating a .msi deployment package or something similar that was able to go out and download the framework, if necessary. There are a lot of deployment models available, almost all of which feel superior to this one.

That said, if you're going to do this:

To get the COM object, you're going to want to use the AutomationFactory.CreateObject(...) API. Tim Heuer provides a sample here.

To actually do the WMI scripting, you're going to want to create the WbemScripting.SWbemLocator object as the root. From there, use the ConnectServer method to get a wmi service on the named machine. You can then interrogate the Win32_Process module to create new processes.

Edit: I spent a little time working on this and, even on my local machine as Admin I'm running into security problems. The correct code would be something similar to:

        dynamic locatorService = AutomationFactory.CreateObject("WbemScripting.SWbemLocator");
        dynamic wmiService = locatorService.ConnectServer("winmgmts:{impersonationLevel=impersonate,authentationLevel=Pkt}//./root/cimv2");

        dynamic process = wmiService.Get("Win32_Process");

        dynamic createParameters = process.Methods_["Create"].InParameters.SpawnInstance_;

        createParameters.CommandLine = "cmd.exe";

        wmiService.ExecMethod("Win32_Process", "Create", createParameters);

Upvotes: 1

Related Questions