|
Author |
Message
|
Wakawaka
-
Total Posts
:
214
- Scores: 4
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Excute Method
-
Friday, February 05, 2010 5:49 AM
( #1 )
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?
|
|
|
dm_4ever
-
Total Posts
:
3613
- Scores: 78
-
Reward points
:
0
- Joined: 6/29/2006
- Location: Orange County, California
-
Status: offline
|
Re:Excute Method
-
Friday, February 05, 2010 6:20 AM
( #2 )
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>
|
|
|
Wakawaka
-
Total Posts
:
214
- Scores: 4
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Re:Excute Method
-
Friday, February 05, 2010 7:05 AM
( #3 )
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>
|
|
|
ebgreen
-
Total Posts
:
7236
- Scores: 72
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Excute Method
-
Friday, February 05, 2010 7:44 AM
( #4 )
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.
|
|
|
Wakawaka
-
Total Posts
:
214
- Scores: 4
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Re:Excute Method
-
Friday, February 05, 2010 7:54 AM
( #5 )
You say dangerous, but how so?
|
|
|
ebgreen
-
Total Posts
:
7236
- Scores: 72
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Excute Method
-
Friday, February 05, 2010 8:05 AM
( #6 )
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?
|
|
|
Wakawaka
-
Total Posts
:
214
- Scores: 4
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Re:Excute Method
-
Friday, February 05, 2010 8:25 AM
( #7 )
Touche......So no end-user input. lol
|
|
|
ebgreen
-
Total Posts
:
7236
- Scores: 72
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Excute Method
-
Friday, February 05, 2010 8:27 AM
( #8 )
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.
|
|
|
Wakawaka
-
Total Posts
:
214
- Scores: 4
-
Reward points
:
0
- Joined: 8/27/2009
-
Status: offline
|
Re:Excute Method
-
Friday, February 05, 2010 3:01 PM
( #9 )
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?
|
|
|
ebgreen
-
Total Posts
:
7236
- Scores: 72
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
Re:Excute Method
-
Monday, February 08, 2010 3:27 AM
( #10 )
Yes. The only issue that you would potentially run into is variable conflicts.
|
|
|
After experiencing a lot of down time, We decided to move this site to
CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.