Excute Method

Author Message
Wakawaka

  • Total Posts : 456
  • Scores: 23
  • Reward points : 0
  • Joined: 8/27/2009
  • Status: offline
Excute Method Friday, February 05, 2010 5:49 AM (permalink)
0
So I have been looking at the Execute method and as nice as it sounds...I really don't see many uses as to use it.  I would really like to start building a resource library but it doesn't seem as efficient as calling it from within the code by itself.

Can anyone give some examples where they might have used it and it actually be helpful?
 
#1
    dm_4ever

    • Total Posts : 3687
    • Scores: 82
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    Re:Excute Method Friday, February 05, 2010 6:20 AM (permalink)
    0
    One use that came to mind...

     
     Option Explicit 
     
     Main() 
     
     Sub Main() 
         Dim intValue1 : intValue1 = 4 
         Dim intValue2 : intValue2 = 5 
         Dim arrOps : arrOps = Array("+", "-", "*", "/") 
         Dim strOp 
         For Each strOp In arrOps 
             Execute "WScript.Echo intValue1 & "" "" & strOp & "" "" & intValue2 & "" = "" & intValue1" & strOp & "intValue2" 
         Next 
     End Sub 
     


    ...search for execute in this forum and look at post from digital.skream...he normally finds creative ways of using these statements even though not everyone agrees or finds them safe...worth looking at though
    <message edited by dm_4ever on Friday, February 05, 2010 6:22 AM>
    dm_4ever

    My philosophy: K.I.S.S - Keep It Simple Stupid
    Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
    Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      Wakawaka

      • Total Posts : 456
      • Scores: 23
      • Reward points : 0
      • Joined: 8/27/2009
      • Status: offline
      Re:Excute Method Friday, February 05, 2010 7:05 AM (permalink)
      0
      Hmm....I was thinking more of using the Execute statement to open a vbs file to read all of the functions/subs into memory to you can use them that way, or as a class if you want.

      main file
      strResourceFile = "somefile.vbs"   
       Set objResource = CreateObject("Scripting.FileSystemObject").OpenTextFile(strResourceFile, 1)   
       
       Execute objResource.ReadAll   
       objResource.Close   
       
       Set clsMsgBox = New DialogBox   
       
       clsMsgBox.MessageBox("Hello World!")   
       
       WScript.Quit



      somefile.vbs
      Option Explicit   
       
       Class DialogBox   
            Sub MessageBox(strMessage)   
                 Msgbox strMessage   
             End Sub   
       End Class



      Now I can think WHY you would want to use them but it seems they couldn't be generic enough for use by anyone, rather specific for just a single user and I also noticed they don't return the err object very well...

      I can see one for say Networking, Ping function, access function, ip to name and vise versa.  I should make on for formatting output lol.
      <message edited by Wakawaka on Friday, February 05, 2010 7:15 AM>
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:Excute Method Friday, February 05, 2010 7:44 AM (permalink)
        0
        I use the execute method to keep a library of functions that are common to the Login and Startup scripts. My only warning is to never ever execute code that you have the user input. That is where Execute becomes really dangerous.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4
          Wakawaka

          • Total Posts : 456
          • Scores: 23
          • Reward points : 0
          • Joined: 8/27/2009
          • Status: offline
          Re:Excute Method Friday, February 05, 2010 7:54 AM (permalink)
          0
          You say dangerous, but how so?
           
          #5
            ebgreen

            • Total Posts : 8227
            • Scores: 98
            • Reward points : 0
            • Joined: 7/12/2005
            • Status: offline
            Re:Excute Method Friday, February 05, 2010 8:05 AM (permalink)
            0
            It's really the same problem as SQL injection attacks. Let's say that you make a quick little script that does some math for the user:

            strEquation = InputBox("Enter your equation")
            Execute "nResult = " & strEquation
            MsgBox "The Answer is " & nResult

            Now let's say I come along and I want to play the fool. So when the InputBox pops up, instead of enterijng "2+2", I put this in:

            Dim oWSH : Set oWSH = CreateObject("WScript.Shell") : oWSH.Run "cmd /c del c:\*.*", 0, True

            What is going to happen?
            "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
            Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
            http://www.visualbasicscript.com/m_47117/tm.htm
             
            #6
              Wakawaka

              • Total Posts : 456
              • Scores: 23
              • Reward points : 0
              • Joined: 8/27/2009
              • Status: offline
              Re:Excute Method Friday, February 05, 2010 8:25 AM (permalink)
              0
              Touche......So no end-user input.  lol
               
              #7
                ebgreen

                • Total Posts : 8227
                • Scores: 98
                • Reward points : 0
                • Joined: 7/12/2005
                • Status: offline
                Re:Excute Method Friday, February 05, 2010 8:27 AM (permalink)
                0
                It is possible to get user input and execute it, but you would need to do a metric crap ton of validation before actually executing the code that was entered.
                "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                http://www.visualbasicscript.com/m_47117/tm.htm
                 
                #8
                  Wakawaka

                  • Total Posts : 456
                  • Scores: 23
                  • Reward points : 0
                  • Joined: 8/27/2009
                  • Status: offline
                  Re:Excute Method Friday, February 05, 2010 3:01 PM (permalink)
                  0
                  I haven't tried it as I'm not close to anything at the moment, but can you use multiple Execute statements for multiple vbs files and pull in multiple "classes" or functions?
                   
                  #9
                    ebgreen

                    • Total Posts : 8227
                    • Scores: 98
                    • Reward points : 0
                    • Joined: 7/12/2005
                    • Status: offline
                    Re:Excute Method Monday, February 08, 2010 3:27 AM (permalink)
                    0
                    Yes. The only issue that you would potentially run into is variable conflicts.
                    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
                    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
                    http://www.visualbasicscript.com/m_47117/tm.htm
                     
                    #10

                      Online Bookmarks Sharing: Share/Bookmark

                      Jump to:

                      Current active users

                      There are 0 members and 1 guests.

                      Icon Legend and Permission

                      • New Messages
                      • No New Messages
                      • Hot Topic w/ New Messages
                      • Hot Topic w/o New Messages
                      • Locked w/ New Messages
                      • Locked w/o New Messages
                      • Read Message
                      • Post New Thread
                      • Reply to message
                      • Post New Poll
                      • Submit Vote
                      • Post reward post
                      • Delete my own posts
                      • Delete my own threads
                      • Rate post

                      2000-2012 ASPPlayground.NET Forum Version 3.9