如何使用 VBScript 运行 RDP 文件?

发布于 2024-08-12 03:56:54 字数 197 浏览 12 评论 0原文

到目前为止我已经:

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

但是当我运行它时,什么也没有发生。是否可以使用 VBScript 运行 RDP 文件?如果是这样,那我做错了什么?

So far I have:

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

But when I run it, nothing happens. Is it even possible to run an RDP file with VBScript? If so, then what am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷了相思 2024-08-19 03:56:54

尝试使用传入的 .rdp 文件名调用 mstsc.exe:

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

try calling mstsc.exe with the .rdp file name passed in:

objShell.Run(""mstsc C:\server01.rdp"")
万劫不复 2024-08-19 03:56:54

我认为您需要运行 mstsc.exe 并将 rdp 文件作为参数传递。

http://technet.microsoft.com/en-我们/库/cc753907%28WS.10%29.aspx

I think you need to run mstsc.exe and pass the rdp file in as an argument.

http://technet.microsoft.com/en-us/library/cc753907%28WS.10%29.aspx

岁月静好 2024-08-19 03:56:54

这将起作用:(在带有 VBSCRIPT 的 PHP 中):

<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) < 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...运气好吗?

This will work: (In PHP with 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) < 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>

The problem is, that only works in IE, still looking for Firefox / Safari... any luck??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文