VMware
 

Knowledge Base

Search the Knowledge Base:

Products:
Search In:
 

Embedding Virtual Machines in Web Browsers

Details

How do I embed the MKS console in both an ASP.NET Web page and a .NET WinForm? I am concerned about detecting the browser (Internet Explorer or Firefox), instancing the ActiveX control for IE, instancing the XPI for Firefox, passing the ManagedObjectRef value and other data to the control to enable embedding the control in two targets, proper destruction, and referencing the DLL.

Solution

 
The following are sample scripts for performing the following tasks using VMware Infrastructure SDK Web services.

Prerequisites

  • A cabinet file (CAB) to install VMware's MKS plug-in into Internet Explorer. Refer to
    <hostname>/usr/lib/vmware/webAccess/tomcat/apache-tomcat-5.5.17/webapps/ui/plugin/msie/vmware-mks.cab
  • Cross-platform installer (XPI) to install VMware's MKS plug-in into Firefox (Windows and Linux).
    • For Linux, refer to
      <hostname>/usr/lib/vmware/webAccess/tomcat/apache-tomcat-5.5.17/webapps/ui/plugin/mozilla/linux/vmware-mks.xpi
    • For Windows, refer to
      <hostname>/usr/lib/vmware/webAccess/tomcat/apache-tomcat-5.5.17/webapps/ui/plugin/mozilla/win32/vmware-mks.xpi

Embedding the Plug-In

The plug-ins can be embedded, in an HTML page, using the OBJECT tag as shown below.

Internet Explorer

<object id="mks" classid="CLSID:DC7D77DA-E1AC-4D40-930B-B87B2954E034" codebase="vmware-mks.cab#version=2,0,1,0" width="100%" height="100%"></object>

The <codebase > attribute specifies the location of the CAB file that may be downloaded to install the control.

Use the VBScript to check whether or not the plug-in is installed.

function isPluginInstalled() {
  var MKS_PLUGIN_INSTALLED = false;
  document.write('<scr' + 'ipt language="VBScript"
  type="text/vbscript">
  option explicit
  on error resume
  next
    if(IsObject(CreateObject("QuickMksAx.QuickMksAxCtl.1"))
      = false) then
      MKS_PLUGIN_INSTALLED = false
      else
      MKS_PLUGIN_INSTALLED = true
    end if
  </scr' + 'ipt>');
  return MKS_PLUGIN_INSTALLED;
}

Firefox

<object id="mks" type="application/x-vmware-mks;version=2.0.1.0" width="100%" height="100%"></object>

Use the navigator.mimeTypes object to check whether or not the plug-in is installed.

varisPluginInstalled = navigator.mimeTypes["application/x-vmware-mks;version=2.0.0.0"];

The plug-in can be easily installed by calling the install() function:

function install() {
  var os = window.navigator.platform;
  if (os.match(/Win32/)) {
    window.frames["pluginDownload"].location.href =
    'vmware-mks-windows-FF.xpi';
    } else if (os.match(/Linux/)) {
    window.frames["pluginDownload"].location.href =
    'vmware-mks-linux-FF.xpi';
    }
  }

Note: Point location.href to a valid XPI location. Unlike Internet Explorer, Firefox uses the XPI to install the plug-in.

Scripting the Plug-In

Use the connect() function, on the control, to establish the MKS connection to a virtual machine.
 
Note: Ensure the virtual machine is in the powered-on state.
Internet Explorer

< script language="Javascript" type="text/javascript"
  // hostAddress -> ESX host name (fqdn) or the IP address.
  // authdPort -> 902 (please make sure port 902 and 903 are open).
  // vmCfgPath -> The VMX location (for the VM in question).
  // uname -> A valid user name.
  // password -> A valid password.
  mks.connect(hostAddress, authdPort, vmCfgPath, uname, password);
</script>

Firefox
<script language="Javascript" type="text/javascript">
var mks = document.getElementById('mks'); // assuming the OBJECT tag ID is mks.

// hostAddress -> ESX host name (fqdn) or the IP address.
// authdPort -> 902 (please make sure port 902 and 903 are open).
// vmCfgPath -> The VMX location (for the VM in question).
// uname -> A valid user name.
// password -> A valid password.
mks.connect(hostAddress, authdPort, vmCfgPath, uname, password);
</script>

Note: If you are using the VMware Infrastructure SDK then make all the connectionarguments available in the MksTicket object. Use same user name and password in the ticket field, in the MksTicket, and in the MKS connection.

Use the disconnect() function, on the control, to terminate the MKS connection to the virtual machine.
 
Note: Disconnecting the MKS does not power off a virtual machine.

Note: Refer to the IDL for a list of all the operations that can be performed on the control.

Capturing Events

Events fired by the control can be captured as follows.

Internet Explorer
  • Capture the connection state change event:

<script type="text/javascript" id="connState" for="mks"
  event="OnConnectionStateChange(connected)">
  // @ param connected = Type Boolean.
</script>

  • Capture the window grab event:

<script type="text/javascript" id="grabState" for="mks"
  event="OnGrabStateChange(grabState)">
  // @ param grabState = Type Integer (1 => Grabbed,
  2 =>Ungrabbed Hard, 3 => Ungrabbed Soft)
</script>

  • Capture the message event:

<script type="text/javascript" id="message" for="mks" event=
  "OnMessage(type, message)">
  // @ param type – Type Integer (0 => Hint, 1 => Info, 2 => Warn, 3 => Error)
  // @ param message – Type String (The actual message from the control)
</script>

  • Capture the Ctrl+Alt+Enter (to enter fullscreen mode) event:

<script type="text/javascript" id="grabState" for="mks" event="OnWindowStateChange(windowState)">
  // @ paramwindowState – Type Integer (1 => Fullscreen, 2 =>Windowed, 3 => Enter Fullscreen)
  // Note: With windowState == 1 the MKS will enter fullscreen automatically.
  if (windowState == 3) {
  mks.setFullscreen(true);
  }
</script>

Firefox
<script language="JavaScript" type="text/javascript">

const IMessageListener = Components.interfaces.xpcomIMessageListener;
const IGrabStateListener =
  Components.interfaces.xpcomIGrabStateListener;
const IWindowStateListener =
  Components.interfaces.xpcomIWindowStateListener;
const IConnectionStateListener =
  Components.interfaces.xpcomIConnectionStateListener;
  • Capture the connection state change event:

function ConnectionStateListener() {}
  ConnectionStateListener.prototype = {
    onConnectionStateChange : function (connected) {
    ...
    }
  },
};

  • Capture the window grab event:

function GrabStateListener() {}
GrabStateListener.prototype =
{
  onGrabStateChange : function (grabState) {
  if (grabState == IGrabStateListener.GS_GRABBED) {
    ...
  }
};

  • Capture the message event:

function MessageListener() {}
MessageListener.prototype =
{
  onMessage : function (msgType, message) {
    if (msgType == IMessageListener.MT_HINT) {
      alert(“Hey this is just a hint: “ + message);
    }
  }
};

  • Capture the Ctrl+Alt+Enter (to enter fullscreen mode) event:

function WindowStateListener() {}
WindowStateListener.prototype =
{
  onWindowStateChange : function (windowState) {
    if (windowState == IWindowStateListener.WS_ENTER_FULLSCREEN) {
    mks.setFullScreen(true);
    }
  }
};
</script>

Note: Refer to the IDL3 for all the events fired by the control.
 

Related Files

  • The CAB file for Intenet Explorer is available at
    <hostname>/usr/lib/vmware/webAccess/tomcat/apache-tomcat-5.5.17/webapps/ui/plugin/msie/vmware-mks.cab
  • The XPIfile for Firefox (Windows) is available at
    <hostname>/usr/lib/vmware/webAccess/tomcat/apache-tomcat-5.5.17/webapps/ui/plugin/mozilla/win32/vmware-mks.xpi
  • The XPI file for Firefox (Linux) is available at
    <hostname>/usr/lib/vmware/webAccess/tomcat/apache-tomcat-5.5.17/webapps/ui/plugin/mozilla/linux/vmware-mks.xpi
  • The ActiveX control IDL, quickMksAx.dll , is included in the cab file.
  • The Firefox plug-in IDL,  xpcomIVMControl.xpt is included in vmware-mks.xpi .
  • The ActiveX sample page, mkswinIE.txt , is attached to this article.
Additionally, samples are available in a zipped file attached to the Forum thread at https://www.vmware.com/community/thread.jspa?threadID=98422&tstart=0 .
To view, log on to the community forum and select thread 98422.
  • The Firefox sample page, mkswinFF.txt , is attached to this article.
Additionally, samples are available in a zipped file at https://www.vmware.com/community/thread.jspa?threadID=98422&tstart=0 .
To view, log on to the community forum and select thread 98422.
 

Keywords

URLZ, SDK, MKS, .NET, IE

Attachments

Feedback

Rating: 1 - Lowest 2 3 4 5 - Highest (0 Ratings)   

Did this article help you?
This article resolved my issue.
This article did not resolve my issue.
This article helped but additional information was required to resolve my issue.
What can we do to improve this information? (2000 or fewer characters)
Submit
Rating: 1 - Lowest 2 3 4 5 - Highest (0 Ratings)   
Actions