經過console能夠實現相似遠程桌面的功能,但它的實現方式和遠程桌面不一樣,通常來講遠程桌面必需要有網絡支持,在機器關閉或者啓動過程當中沒法鏈接。而console是經過esx的虛擬化組件實現遠程桌面。在其sample代碼中有一個用html+js編寫ActiveX插件的示例。html
下方是一個用winform寫的console遠程截圖。網絡
在vmware的developer center中https://developercenter.vmware.com/sdks,下載vmrc sdk,它會以com組件的形式安裝,你能夠在vs工具箱中找到。session
下面上一段sample代碼app
1 using System; 2 using System.Linq; 3 using System.Windows.Forms; 4 5 using Vim25Api; 6 using AppUtil; 7 8 namespace WindowsFormsApplication1 9 { 10 public partial class Form1 : Form 11 { 12 public AppUtil.AppUtil util = null; 13 14 public Form1() 15 { 16 InitializeComponent(); 17 } 18 19 private void button1_Click(object sender, EventArgs e) 20 { 21 String[] arguments = new string[] { 22 "--url", "https://192.168.0.161/sdk", 23 "--username","root", 24 "--password","P@ssw0rd", 25 "--disablesso", "true", 26 "--ignorecert", "true"}; 27 try 28 { 29 this.axVMwareEmbeddedRemoteConsole1.startup(2, VMwareRemoteConsoleTypeLib.VMRC_MessageMode.VMRC_DIALOG_MESSAGES, null); 30 31 util = AppUtil.AppUtil.initialize("Connect", constructOptions(), arguments.ToArray()); 32 util.connect(); 33 34 ManagedObjectReference mor = util.getConnection().ServiceRef; 35 ManagedObjectReference sessionMor = util._connection.Service.RetrieveServiceContent(mor).sessionManager; 36 string ticket = util._connection.Service.AcquireCloneTicket(sessionMor); 37 ManagedObjectReference vmMor = util.getServiceUtil().GetDecendentMoRef(null, "VirtualMachine", "test"); 38 39 axVMwareEmbeddedRemoteConsole1.connect("192.168.0.161", null, true, ticket, null, null, vmMor.Value, null, null); 40 } 41 catch(Exception ex) 42 { 43 MessageBox.Show(ex.ToString()); 44 45 this.axVMwareEmbeddedRemoteConsole1.disconnect(); 46 util.disConnect(); 47 } 48 } 49 private static OptionSpec[] constructOptions() 50 { 51 OptionSpec[] useroptions = new OptionSpec[5]; 52 useroptions[0] = new OptionSpec("url", "String", 1, "ser url", null); 53 useroptions[1] = new OptionSpec("username", "String", 1, "user name", null); 54 useroptions[2] = new OptionSpec("password", "String", 1, "password", null); 55 useroptions[3] = new OptionSpec("disablesso", "bool", 0, "disablesso", null); 56 useroptions[4] = new OptionSpec("ignorecert", "bool", 1, "ignorecert", null); 57 return useroptions; 58 } 59 60 private void button2_Click(object sender, EventArgs e) 61 { 62 axVMwareEmbeddedRemoteConsole1.disconnect(); 63 util.disConnect(); 64 } 65 } 66 }
在創建connect鏈接時,有幾個重要的參數less
url爲https://主機ip/sdk,登陸賬號也是主機esx的賬號。工具
disablesso表示禁用sso單點登陸驗證,這個要加上,由於在咱們遠程登陸驗證不會使用sso。ui
ignorecert這個參數也要加上,否則會證書驗證致使The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.this
這些參數如何運做能夠到vsphere sdk中的apputil項目下找到。url