Problems encountered when trying to use the Silverlight OOB Mode

Source: Internet
Author: User
Tags pfx file

1. automatically update OOB mode and how to avoid Digital Signatures

You need to implement the following code for online update of OOB mode:

1 private void oncheckanddownloadupdatecompleted (Object sender, checkanddownloadupdatecompletedeventargs E)

2 {

3 if (E. updateavailable & E. Error = NULL)

4 {

5. MessageBox. Show ("the new version of the application has been successfully downloaded and will take effect at next startup. ");

6}

7 else if (E. Error! = NULL)

8 {

9 MessageBox. Show ("the following error message appears when detecting application updates :"

10 + environment. newline

11 + environment. newline

12 + E. Error. Message );

13}

14}

Then, add the declaration in the app constructor to check the version update during installation:

1 Public app ()

2 {

3 if (App. Current. installstate = installstate. installed)

4 {

5 App. Current. checkanddownloadupdatecompleted + = oncheckanddownloadupdatecompleted;

6 app. Current. checkanddownloadupdateasync ();

7}

8

9 This. startup + = This. application_startup;

10 This. Exit + = This. application_exit;

11 This. unhandledexception + = This. application_unhandledexception;

12

13 initializecomponent ();

14}

 

If you run the code on the local machine, the above Code is enough. However, once published, an exception will occur during the update check, the reason is that your Silverlight program is not a fully trusted program for users. If you want to solve this problem, you need to digitally sign the xap to publish a certificate to the Silverlight program, prove that it is safe and reliable and can be fully trusted. For more information, see

Http://msdn.microsoft.com/library/dd550721 (vs.95 ). the Check Application in aspx updates the Section, but how to sign it, you can refer to the http://www.cnblogs.com/chuifeng/archive/2010/08/20/1804294.html, but I follow the above method has never been able to get the pfx Digital Certificate file, if any of you have done this, let me know.

 

I finally got it through a function provided by vs: Right-click the properties option of the Silverlight project, and there is a signing option on the left of the properties option. Select the sign the xap file, click Create test certificate, follow the prompts, and generate a file in your Silverlight project. pfx file, and then click the second button select Form file to select the file.

 

However, this generates only a test certificate, and the official version is expensive. To avoid spending money, someone on the Internet provides this method

 

Here I think it can be implemented through MEF dynamic loading. At first, only one default page that never needs to be updated will be loaded, and all other modules that may need to be updated will adopt dynamic loading.

 

2. OOB mode silent install method

First, let's take a look at the specific Silent Installation command format:

"C: \ Program Files \ microsoft Silverlight \ sllauncher.exe"

/Install: "C: \ silverlightoobdemo. xap"

/Origin: http: // localhost: 29162/clientbin/silverlightoobdemo. xap

/Shortcut cut: desktop + startmenu

/Overwrite

 

From the preceding command, we can see that sllauncher implements different function operations after adding some parameters, such

/Install: "xap file destination path". This parameter allows developers to customize the xap File Installation path, which can be a local disk or a network path. This parameter is required for silent installation mode.

/Origin: "xap File Source Path". This parameter is used to set the xap file source URL for automatic update. Set this parameter as an official recommendation to ensure that its application is automatically updated.

/Shortcut cut: desktop + startmenu. It can be seen from the literal meaning that this parameter is used to create an application shortcut. Desktop + startmenu creates a shortcut for the application on both the desktop and the Start Menu, if you only want to create a desktop shortcut, use/shortcut cut: desktop. The same applies to creating a Start Menu shortcut.

/Overwrite. This option is used to check whether the xap file currently installed overwrites the installed xap file. In general, overwrite is set to keep the application to the latest version.

 

In addition, we will introduce two common sllauncher command parameters:

/Emulate: "xap file destination path". This command parameter allows you to automatically run the OOB application after installing it, similar to the autorun function provided by many software.

Usage:

 

"C: \ Program Files \ microsoft Silverlight \ sllauncher.exe"

/Emulate: "C: \ silverlightoobdemo. xap"

/Origin: http: // localhost: 29162/clientbin/silverlightoobdemo. xap

/Overwrite

 

 

/Uninstall. This command parameter allows developers to uninstall the Silverlight OOB application by using commands. Usage:

 

"C: \ Program Files \ microsoft Silverlight \ sllauncher.exe"

/Uninstall

/Origin: http: // localhost: 29162/clientbin/silverlightoobdemo. xap

 

Link: http://kevinfan.blog.51cto.com/1037293/370788

 

Note: I tried silent install. I thought it would automatically install xap to the local path specified by/install Based on the remote address indicated by/origin, later, it was found that the xap package had to be downloaded by itself, and then put it in the local path, and then use this local path as the path parameter of/install, silent install only installs the local xap without any prompts.

Then there will be such a problem, whether it is to write the above command code in a separate. in the BAT file, you still need to write it directly in the C # code, which must be called through COM interaction in OOB mode, but this is to install OOB mode, therefore, it may only be executed in the browser state, which certainly does not have this permission. Therefore, the silent install execution method is as follows: Write the command code in. BAT file, and then let the user execute it. BAT file, the problem is that the meaning of silent install is lost. In addition. bat is placed on the server side, allowing the user to automatically download to the local device when opening the webpage. However, in the browser status, Silverlight does not have the permission to directly access the local path, except for the savefiledialog pop-up, however, there is another operation that allows users to select a path, which is not more complicated than making it right-click by default.

 

3. Permission issues in OOB Mode

Access Local files in OOB mode: by default, only folders starting with "my" can be accessed, such as "My Documents" and "my music". If you want to access other local paths, you need to use Com, as shown below:

3 using (Dynamic fsocom = automationfactory. Createobject ("scripting. FileSystemObject "))

4 {

5 dynamic file = fsocom. createtextfile (@ "C: \ test.txt", true );

6 file. writeline ("Hello Silverlight 4 .");

7 file. writeline ("Silverlight writes a file to C :\\");

8 file. Close ();

9}

In addition, you can run other programs and read and write the Registry through COM in OOB mode. For example:

(1) directly run the doscommand:

3 using (Dynamic shell = automationfactory. Createobject ("wscript. Shell "))

4 {

5 shell. Run (@ "CMD/K Ping www.cnblogs.com-T ");

6}

 

(2) run other programs: Use the wshell API to simulate user input instances. You can use sendkeys of wshell to simulate the effects of user input into applications and simulate some special key functions, such as enter, tab, and CTRL.

3 using (Dynamic shell = automationfactory. Createobject ("wscript. Shell "))

4 {

5 shell. Run (@ "C: \ WINDOWS \ notepad.exe ");

6 shell. sendkeys ("My blog: {enter} jv9.cnblogs.com ");

7}

 

(3) read the Registry: Read the "HKLM \ Software \ Microsoft \ ASP. NET \ rootver" And. NET Framework version.

3 using (Dynamic wshell = automationfactory. Createobject ("wscript. Shell "))

4 {

5 string Reg = wshell. regread (@ "HKLM \ Software \ Microsoft \ ASP. NET \ rootver ");

6 MessageBox. Show (". NET Framework root version:" + REG );

7}

 

(4) write to the Registry: add the Silverlight out of browser application to the Windows Startup item.

 

3 using (Dynamic shellapplication = automationfactory. Createobject ("Shell. Application "))

4 {

5 dynamic commonprograms = shellapplication. namespace (11 );

6 string alluserspath = commonprograms. Self. path;

7

8 dynamic directory = shellapplication. namespace (alluserspath + @ "\ Programs ");

9 Dynamic Link = directory. parsename (

10 deployment. Current. outofbrowsersettings. shortname + ". lnk ");

11 string ooblink = link. path;

12

13 using (Dynamic wshell = automationfactory. Createobject ("wscript. Shell "))

14 {

15 wshell. regwrite (@ "HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Run \"

16 + deployment. Current. outofbrowsersettings. shortname, ooblink );

17 MessageBox. Show ("Please restart your machine and your application will be automatically loaded into the startup list .");

18}

19}

 

However, the OOB mode does not have the permission to modify any registry. The most typical is to modify the registry of the Task Manager (hkcu \ Software \ Microsoft \ Windows \ CurrentVersion \ Policies \ System \ disabletaskmgr, if the Silverlight project is used as the START project, you can run OOB mode directly through debug to modify the task manager. However, if the web project is used as the START project, you can run the browser at the beginning, this operation will be rejected. The two running modes have different permissions, Which is uncomfortable because OOB cannot be debugged when running the WEB Project, you can only start with a Silverlight project to debug OOB. However, in this case, you often execute an operation with a high permission and pass the debugging, but it will not work if it has been released, therefore, do not fully trust the debug results ).

In addition, I want to write a trick. bat program, through. BAT to modify the Task Manager registry, if you run directly. BAT can achieve the effect, so I want to use OOB's com to call this. bat program, according to the normal idea, this is always enough. However, the result is: call this. the bat program is fine,. the execution result of the bat program is still rejected. According to my ideas, it seems like this. the permissions of the bat program are lowered by Silverlight, even if the administrator is granted permissions.

 

Note: The code here is from the blog jv9 blog

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.