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="width: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("計算機處於斷開狀態,請根據提示完成后續步驟:\r\n(1)如果您操作已完成,請刷新頁面重新連接並注銷;\r\n(2)如果仍需操作,請刷新頁面后繼續,完畢后請注銷。\r\n謝謝您的配合!");
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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM