Download and execute a file hosted on a remote server?











up vote
0
down vote

favorite












Is it possible to download and execute a file hosted on a remote server using a .vbs script? My below attempt doesn't seem to work.



Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""\12.345.67.789filename.exe""")
Set objShell = Nothing









share|improve this question






















  • You say you’re downloading the file, but, as far as I can see, you aren’t — you’re just trying to execute it from its remote location.
    – G-Man
    May 17 at 2:43















up vote
0
down vote

favorite












Is it possible to download and execute a file hosted on a remote server using a .vbs script? My below attempt doesn't seem to work.



Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""\12.345.67.789filename.exe""")
Set objShell = Nothing









share|improve this question






















  • You say you’re downloading the file, but, as far as I can see, you aren’t — you’re just trying to execute it from its remote location.
    – G-Man
    May 17 at 2:43













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Is it possible to download and execute a file hosted on a remote server using a .vbs script? My below attempt doesn't seem to work.



Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""\12.345.67.789filename.exe""")
Set objShell = Nothing









share|improve this question













Is it possible to download and execute a file hosted on a remote server using a .vbs script? My below attempt doesn't seem to work.



Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""\12.345.67.789filename.exe""")
Set objShell = Nothing






windows windows-10 remote vbscript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 16 at 19:38









user905798

1




1












  • You say you’re downloading the file, but, as far as I can see, you aren’t — you’re just trying to execute it from its remote location.
    – G-Man
    May 17 at 2:43


















  • You say you’re downloading the file, but, as far as I can see, you aren’t — you’re just trying to execute it from its remote location.
    – G-Man
    May 17 at 2:43
















You say you’re downloading the file, but, as far as I can see, you aren’t — you’re just trying to execute it from its remote location.
– G-Man
May 17 at 2:43




You say you’re downloading the file, but, as far as I can see, you aren’t — you’re just trying to execute it from its remote location.
– G-Man
May 17 at 2:43










1 Answer
1






active

oldest

votes

















up vote
0
down vote













The following will get you what you want. Be sure to set the local file name (sLocalFile) to a path that your user has rights to write to or it will fail. Further, most antivirus apps will treat this as malware.



' variables
Dim xHttp, oStream, oShell, sRemoteURI, sLocalFile

' constants
Const klBinary = 1
Const klOverwrite = 2

' defined values
sRemoteURI = "https://example.com/filename.exe"
sLocalFile = """%appdata%filename.exe"""

' create the web request
Set xHttp = CreateObject("Microsoft.XMLHTTP")
xHttp.Open "GET", sRemoteURI, False
xHttp.Send

' save the file locally
Set oStream = CreateObject("Adodb.Stream")
oStream.Type = klBinary
oStream.Open
oStream.Write xHttp.responseBody
oStream.SaveToFile sLocalFile, klOverwrite
Set oStream = Nothing
Set xHttp = Nothing

' run the file
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run(sLocalFile)
Set oShell = Nothing





share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1323328%2fdownload-and-execute-a-file-hosted-on-a-remote-server%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    The following will get you what you want. Be sure to set the local file name (sLocalFile) to a path that your user has rights to write to or it will fail. Further, most antivirus apps will treat this as malware.



    ' variables
    Dim xHttp, oStream, oShell, sRemoteURI, sLocalFile

    ' constants
    Const klBinary = 1
    Const klOverwrite = 2

    ' defined values
    sRemoteURI = "https://example.com/filename.exe"
    sLocalFile = """%appdata%filename.exe"""

    ' create the web request
    Set xHttp = CreateObject("Microsoft.XMLHTTP")
    xHttp.Open "GET", sRemoteURI, False
    xHttp.Send

    ' save the file locally
    Set oStream = CreateObject("Adodb.Stream")
    oStream.Type = klBinary
    oStream.Open
    oStream.Write xHttp.responseBody
    oStream.SaveToFile sLocalFile, klOverwrite
    Set oStream = Nothing
    Set xHttp = Nothing

    ' run the file
    Set oShell = WScript.CreateObject("WScript.Shell")
    oShell.Run(sLocalFile)
    Set oShell = Nothing





    share|improve this answer

























      up vote
      0
      down vote













      The following will get you what you want. Be sure to set the local file name (sLocalFile) to a path that your user has rights to write to or it will fail. Further, most antivirus apps will treat this as malware.



      ' variables
      Dim xHttp, oStream, oShell, sRemoteURI, sLocalFile

      ' constants
      Const klBinary = 1
      Const klOverwrite = 2

      ' defined values
      sRemoteURI = "https://example.com/filename.exe"
      sLocalFile = """%appdata%filename.exe"""

      ' create the web request
      Set xHttp = CreateObject("Microsoft.XMLHTTP")
      xHttp.Open "GET", sRemoteURI, False
      xHttp.Send

      ' save the file locally
      Set oStream = CreateObject("Adodb.Stream")
      oStream.Type = klBinary
      oStream.Open
      oStream.Write xHttp.responseBody
      oStream.SaveToFile sLocalFile, klOverwrite
      Set oStream = Nothing
      Set xHttp = Nothing

      ' run the file
      Set oShell = WScript.CreateObject("WScript.Shell")
      oShell.Run(sLocalFile)
      Set oShell = Nothing





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        The following will get you what you want. Be sure to set the local file name (sLocalFile) to a path that your user has rights to write to or it will fail. Further, most antivirus apps will treat this as malware.



        ' variables
        Dim xHttp, oStream, oShell, sRemoteURI, sLocalFile

        ' constants
        Const klBinary = 1
        Const klOverwrite = 2

        ' defined values
        sRemoteURI = "https://example.com/filename.exe"
        sLocalFile = """%appdata%filename.exe"""

        ' create the web request
        Set xHttp = CreateObject("Microsoft.XMLHTTP")
        xHttp.Open "GET", sRemoteURI, False
        xHttp.Send

        ' save the file locally
        Set oStream = CreateObject("Adodb.Stream")
        oStream.Type = klBinary
        oStream.Open
        oStream.Write xHttp.responseBody
        oStream.SaveToFile sLocalFile, klOverwrite
        Set oStream = Nothing
        Set xHttp = Nothing

        ' run the file
        Set oShell = WScript.CreateObject("WScript.Shell")
        oShell.Run(sLocalFile)
        Set oShell = Nothing





        share|improve this answer












        The following will get you what you want. Be sure to set the local file name (sLocalFile) to a path that your user has rights to write to or it will fail. Further, most antivirus apps will treat this as malware.



        ' variables
        Dim xHttp, oStream, oShell, sRemoteURI, sLocalFile

        ' constants
        Const klBinary = 1
        Const klOverwrite = 2

        ' defined values
        sRemoteURI = "https://example.com/filename.exe"
        sLocalFile = """%appdata%filename.exe"""

        ' create the web request
        Set xHttp = CreateObject("Microsoft.XMLHTTP")
        xHttp.Open "GET", sRemoteURI, False
        xHttp.Send

        ' save the file locally
        Set oStream = CreateObject("Adodb.Stream")
        oStream.Type = klBinary
        oStream.Open
        oStream.Write xHttp.responseBody
        oStream.SaveToFile sLocalFile, klOverwrite
        Set oStream = Nothing
        Set xHttp = Nothing

        ' run the file
        Set oShell = WScript.CreateObject("WScript.Shell")
        oShell.Run(sLocalFile)
        Set oShell = Nothing






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 at 8:32









        shawn

        865




        865






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1323328%2fdownload-and-execute-a-file-hosted-on-a-remote-server%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            QoS: MAC-Priority for clients behind a repeater

            Ивакино (Тотемский район)

            Can't locate Autom4te/ChannelDefs.pm in @INC (when it definitely is there)