2009-11-20 67 views
1

到目前爲止,我有:如何使用VBScript運行RDP文件?

Set objShell = WScript.CreateObject("WScript.Shell") 
objShell.Run("""C:\Server01.rdp""") 

但是當我運行它,什麼都不會發生。是否可以使用VBScript運行RDP文件?如果是這樣,那麼我做錯了什麼?

+1

得到它的工作大家: objShell.Run 「的mstsc.exe server01.rdp」 感謝所有幫助! – wahle509 2009-11-20 19:13:54

回答

2

嘗試調用用的mstsc.exe傳入的.rdp文件名:

objShell.Run(""mstsc C:\server01.rdp"") 
+0

不,我得到「系統找不到指定的文件」。 – wahle509 2009-11-20 18:53:16

+0

您需要確保您的環境路徑變量指向正確(如果您可以執行start-> run-> mstsc c:\ server01.rdp,那麼您應該可以正常運行)。還請檢查我的答案中的引號 - 我沒有包含您原來的額外一個! – 2009-11-20 18:59:59

+0

作爲一個想法,如果需要,可以使用批處理文件而不是VBScript,因爲這是一個相對簡單的操作。 – 2009-11-20 19:00:52

0

這將工作:(在PHP中使用VBScript):

<script type="text/vbscript" language="vbscript"> 
<!-- 
const L_FullScreenWarn1_Text = "Your current security settings do not allow automatically switching to fullscreen mode." 
const L_FullScreenWarn2_Text = "You can use ctrl-alt-pause to toggle your remote desktop session to fullscreen mode" 
const L_FullScreenTitle_Text = "Remote Desktop Web Connection " 
const L_ErrMsg_Text   = "Error connecting to remote computer: " 
const L_ClientNotSupportedWarning_Text = "Remote Desktop 6.0 does not support CredSSP over TSWeb." 
const L_RemoteDesktopCaption_ErrorMessage = "Remote Desktop Connection" 
const L_InvalidServerName_ErrorMessage = "An invalid server name was specified." 

sub window_onload() 
    if not autoConnect() then 
     msgbox("VB") 
    end if 
end sub 

function autoConnect() 

    Dim sServer 
    Dim iFS, iAutoConnect 

    sServer = getQS ("Server") 
    iAutoConnect = getQS ("AutoConnect") 
    iFS = getQS ("FS") 

    if NOT IsNumeric (iFS) then 
     iFS = 0 
    else 
     iFS = CInt (iFS) 
    end if 

    if iAutoConnect <> 1 then 
     autoConnect = false 
     exit function 
    else 


     if IsNull (sServer) or sServer = "" then 
      sServer = window.location.hostname 
     end if 

     btnConnect() 
     autoConnect = true 
    end if 

end function 

function getQS (sKey) 
    Dim iKeyPos, iDelimPos, iEndPos 
    Dim sURL, sRetVal 
    iKeyPos = iDelimPos = iEndPos = 0 
    sURL = window.location.href 

    if sKey = "" Or Len(sKey) &lt; 1 then 
     getQS = "" 
     exit function 
    end if 

    iKeyPos = InStr (1, sURL, sKey) 

    if iKeyPos = 0 then 
     sRetVal = "" 
     exit function 
    end if 

    iDelimPos = InStr (iKeyPos, sURL, "=") 
    iEndPos = InStr (iDelimPos, sURL, "&") 

    if iEndPos = 0 then 
     sRetVal = Mid (sURL, iDelimPos + 1) 
    else 
     sRetVal = Mid (sURL, iDelimPos + 1, iEndPos - iDelimPos - 1) 
    end if 

    getQS = sRetVal 
end function 


sub OnControlLoadError 
    Msgbox("You wont be able to connect trough Remote Desktop") 
end sub 

sub OnControlLoad 
    set Control = Document.getElementById("MsRdpClient") 
    if Not Control is Nothing then 
     if Control.readyState = 4 then 
     BtnConnect() 
     else 
      Msgbox("You wont be able to connect trough Remote Desktop") 
     end if 
    else 
     Msgbox("You wont be able to connect trough Remote Desktop") 
    end if 
end sub 


sub BtnConnect 
Dim serverName 

serverName = "<?=$_POST["RDserver"]?>" 
serverName = trim(serverName) 

On Error Resume Next 
MsRdpClient.server = serverName 
If Err then 
msgbox 
L_InvalidServerName_ErrorMessage,0,L_RemoteDesktopCaption_ErrorMessage 
Err.Clear 
exit sub 
end if 
On Error Goto 0 

Dim ClientUserName 
ClientUserName = "<?=trim($_POST["RDuser"])?>" 
MsRdpClient.UserName = ClientUserName 
MsRdpClient.AdvancedSettings.ClearTextPassword = "<?=trim($_POST["RDpass"])?>" 
MsRdpClient.FullScreen = TRUE 
resWidth = screen.width 
resHeight = screen.height 
MsRdpClient.DesktopWidth = resWidth 
MsRdpClient.DesktopHeight = resHeight 
MsRdpClient.Width = resWidth 
MsRdpClient.Height = resHeight 
MsRdpClient.AdvancedSettings2.RedirectDrives = FALSE 
MsRdpClient.AdvancedSettings2.RedirectPrinters = FALSE 
MsRdpClient.AdvancedSettings2.RedirectPorts = FALSE 
MsRdpClient.AdvancedSettings2.RedirectSmartCards = FALSE 
MsRdpClient.FullScreenTitle = L_FullScreenTitle_Text & "-" & serverName & "-" 
MsRdpClient.Connect 
end sub 

--> 
    </script> 
    <object id="MsRdpClient" language="vbscript" onreadystatechange="OnControlLoad" onerror="OnControlLoadError" classid="CLSID:4eb89ff4-7f78-4a0f-8b8d-2bf02e94e4b2" width="800" height="600"></object> 

<script language="VBScript"> 
<!-- 
sub ReturnToConnectPage() 
me.close 
end sub 

sub MsRdpClient_OnConnected() 

end sub 

sub MsRdpClient_OnDisconnected(disconnectCode) 
    extendedDiscReason = MsRdpClient.ExtendedDisconnectReason 
    majorDiscReason = disconnectCode And &hFF 

    if (disconnectCode = &hB08 or majorDiscReason = 2 or majorDiscReason = 1) and not (extendedDiscReason = 5) then 
     ReturnToConnectPage 
     exit sub 
    end if 

    errMsgText = MsRdpClient.GetErrorDescription(disconnectCode, extendedDiscReason) 
    if not errMsgText = "" then 
     msgbox errMsgText,0,L_RemoteDesktopCaption_ErrorMessage 
    end if 

    ReturnToConnectPage 

end sub 
--> 
</script> 

問題是,只能在IE瀏覽器中工作,仍然在尋找Firefox/Safari ...任何運氣?