Javascript调用MsRdpClient 完成Web调用远程桌面(CSDN手动迁移)

最近工作用到Web连接远程桌面,查找资料发现MsRdpClient都是vbscript写的。由于不太熟悉vbscript ,只能一点点改成js。。 下面是具体代码,希望给需要的人一些帮助~~

  1 <!DOCTYPE html>
  2 <html>
  3 <head>
  4     <meta name="viewport" content="width=device-width" />
  5     <meta http-equiv="x-ua-compatible" content="IE=8">
  6     <title>RDP</title>
  7     <style type="text/css">
  8         body {
  9             padding: 0;
 10             margin: 0;
 11         }
 12     </style>
 13 </head>
 14 <body>
 15     <script type="text/javascript">
 16   //if ("条件") { 
 17          //   if (window.opener.SetRDPID) { //调用打开此页的父页面中的方法
 18         //        window.opener.SetRDPID("123");
 19         //    };
 20 // 连接远程桌面的方法
 21             function RdpConnect() {
 22                 var userName, Pwd, server, domain, port;
 23                 userName = "administrator"; //用户名
 24                 server = "192.168.1.117"; //IP
 25                 port = 3389; //端口
 26 domain = "myDomain";  //
 27                 if (!MsRdpClient.Connected) {
 28                     try {
 29                         document.getElementById("connectArea").style.display = "block"; //显示远程桌面div
 30                         MsRdpClient.Server = server; //设置远程桌面IP地址
 31                         try {
 32                             MsRdpClient.AdvancedSettings2.RedirectDrives = false;
 33                             MsRdpClient.AdvancedSettings2.RedirectPrinters = false;
 34                             MsRdpClient.AdvancedSettings2.RedirectPrinters = false;
 35                             MsRdpClient.AdvancedSettings2.RedirectClipboard = true;
 36                             MsRdpClient.AdvancedSettings2.RedirectSmartCards = false;
 37                         } catch (ex) {
 38                         };
 39 
 40 
 41                         MsRdpClient.Domain = domain;//
 42                         MsRdpClient.UserName = userName;
 43                         //MsRdpClient.AdvancedSettings2.ClearTextpassword = Pwd; //密码
 44                         MsRdpClient.AdvancedSettings2.RDPPort = port; //端口
 45                         if (document.getElementById("ColorDepth").value == 1) {
 46                             ColorDepth16();
 47                         } else {
 48                             ColorDepthDefault();
 49                         };
 50                         MsRdpClient.FullScreen = 1;  //是否全屏 0否 1是
 51                         if (document.getElementById("Screen").value == 1) {
 52                             Screen1();
 53                         } else {
 54                             ScreenDefault();
 55                         };
 56                         try {
 57                             //如果不支持,继续下面操作
 58                             MsRdpClient.AdvancedSettings7.EnableCredSspSupport = true;
 59                             MsRdpClient.AdvancedSettings5.AuthenticationLevel = 2;
 60                         } catch (ex) {
 61                         } finally {                
 62                             MsRdpClient.Connect();  //连接远程桌面
 63                         }
 64                     } catch (ex) {
 65                         alert("发生错误:" + ex.message + "请尝试刷新页面重新连接。");
 66                     };
 67                 } else {
 68                     alert("已连接!");
 69                 };
 70             };
 71             //var logoff = false; //存储是否正常注销
 72             //全屏
 73             function FullScreen() {
 74                 if (MsRdpClient.Connected) {
 75                     MsRdpClient.FullScreen = 1;
 76                 };
 77             };
 78             //1024*768
 79             function ScreenDefault() {
 80                 MsRdpClient.Width = 1024; //设置远程桌面 显示区域的宽和高
 81                 MsRdpClient.Height = 768;
 82                 MsRdpClient.DesktopWidth = 1024;  //设置 远程桌面的宽和高
 83                 MsRdpClient.DesktopHeight = 768;
 84             };
 85             //800*600
 86             function Screen1() {
 87                 MsRdpClient.Width = 800; //设置远程桌面 显示区域的宽和高
 88                 MsRdpClient.Height = 600;
 89                 MsRdpClient.DesktopWidth = 800;  //设置 远程桌面的宽和高
 90                 MsRdpClient.DesktopHeight = 600;
 91             };
 92             //色彩度,默认32位
 93             function ColorDepthDefault() {
 94                 MsRdpClient.ColorDepth = 32;
 95             };
 96             //色彩度16位
 97             function ColorDepth16() {
 98                 MsRdpClient.ColorDepth = 16;
 99             };
100             function reSet() {
101                 document.getElementById("Screen").selectedIndex = 1;
102                 document.getElementById("ColorDepth").selectedIndex = 1;
103             };
104 
105 //关闭当前页面
106         function closeWindow() {
107             window.opener = null;
108             window.open("", "_self");
109             window.close();
110         };
111 </script>
112     <!--远程桌面参数设置start-->
113     <div style="display:none"><fieldset>
114         分辨率:<select id="Screen">
115             <option value="1">800*600</option>
116             <option value="2" selected="selected">1024*768</option>
117         </select>
118         色彩度:<select id="ColorDepth">
119             <option value="1">16位</option>
120             <option value="2" selected="selected">32位</option>
121         </select>
122         <input type="button" value="重置" onclick="reSet()" />
123     </fieldset>
124     <input type="button" id="connectbutton" value="连接" onclick="RdpConnect();" /></div>
125      <!--远程桌面参数设置end-->
126     <input type="button" class="btn btn-warning" style="80px;" value="全屏" onclick="FullScreen()" />
127     <div id="connectArea" style="display: none;">
128         <table>
129             <tr>
130                 <td>
131                     <object id="MsRdpClient"
132                         classid="CLSID:7584c670-2274-4efb-b00b-d6aaba6d3850"
133                         codebase="msrdp.cab#version=5,2,3790,0" width="1024px" height="768px">
134                     </object>
135                 </td>
136             </tr>
137             <script type="text/javascript">
138                 function MsRdpClient::OnDisconnected(disconnectCode) {
139                     document.getElementById("connectArea").style.display = "none";
140                     //正常注销,代码为2
141                     //if (disconnectCode != 2) {
142                     //    if (logoff == false) {
143                     //        alert("计算机处于断开状态,请根据提示完成后续步骤:
(1)如果您操作已完成,请刷新页面重新连接并注销;
(2)如果仍需操作,请刷新页面后继续,完毕后请注销。
谢谢您的配合!");
144                     //    } else {
145                     //        alert("计算机已注销,如需使用,请刷新此页面。");
146                     //    }
147                     //} else {
148                     //    logoff = true; //记录注销状态
149                     //    //关闭当前页面
150                     //};
151                     closeWindow();
152                 }
153             </script>
154         </table>
155     </div>
156 </body>
157 </html>
原文地址:https://www.cnblogs.com/hetring/p/4611218.html