Sinisterly
Do you understand this? - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework)
+--- Thread: Do you understand this? (/Thread-Do-you-understand-this)



Do you understand this? - curtis5000 - 09-27-2012

I have no idea how to use VB, but i think this is a download & execute code that works directly 4rm a url, if anyone here understands this, pls help solve it.

Original post here
http://gallery.technet.microsoft.com/scriptcenter/f9f23891-d8d1-470f-81ef-bc4205db73ea#content


Visual Basic


Code:
Dim args, num Dim var1, var2 Dim objFSO, objFolder Dim objStream Dim WshShell Dim strFolder, strURL, strFile, strFull Dim strUnat, strCmdLine, strDmdLine 'Sets and checks arguments set args = WScript.Arguments num = args.Count If num = 2 Then 'URL for the file strURL = args.Item(0) 'Folder for the file to be downloaded to strFolder = args.Item(1) ElseIf num = 3 Then strURL = args.Item(0) strFolder = args.item(1) strUnat = args.item(2) Else Wscript.Echo "Usage: \\servername\sharename\downrunsilent.vbe http://www.website.com/executable.exe C:\temp" Wscript.Echo "For unattended options add them after download folder with a space and quotes." WScript.Quit End If 'Converts URL to just filename var1 = Split(StrReverse(strURL), "/") var2 = StrReverse(var1(0)) 'Sets path for file download strFile = var2 strFull = strFolder & "\" & strFile 'wscript.echo "File download location is: " & strFull 'Verify local folder for file and creates it if doesn't exist Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists(strFolder) Then Set objFolder = objFSO.GetFolder(strFolder) Else 'Wcript.Echo "Download folder does not exist." 'Wscript.Echo "Creating download folder." Set objFolder = objFSO.CreateFolder(strFolder) End If ' Sets up an ADO Stream to download file Set objStream = CreateObject("ADODB.Stream") objStream.Type = 1 ' adTypeBinary ' The following starts the download objStream.Open ("URL=" & strURL) 'wscript.echo "File downloaded" ' This saves the file to the workstation in the folder specified objStream.SaveToFile strFolder & "\" & strFile, 2 ' adSaveCreateOverWrite objStream.Close Set objStream = Nothing ' Runs the downloaded file with or without unattended/silent options If strUnat = "" Then 'wscript.echo "Executing downloaded file" Set WshShell = CreateObject("WScript.Shell") WshShell.Run (chr(34) & strFull & chr(34)) Set WsShell = Nothing Else 'WScript.echo "Executing downloaded file" Set WshShell = CreateObject("WScript.Shell") strCmdLine = strFull & " " strDmdLine = strCmdLine & strUnat WshShell.Run (strDmdLine) Set WsShell = Nothing End If



RE: Do you understand this? - 1llusion - 09-27-2012

Moving to correct forum


RE: Do you understand this? - Frooxius - 09-27-2012

Please use Code tags next time, I realize that the buttons are not working at the moment, but you can type [ code ] and [ / code ] manually (without the spaces) and they will work too.

I'm not sure what exactly you want though. Do you want to run this code? The original post explains what it does pretty well and it's also commented throughout, so I don't think that's really the issue.

If you want to execute the code, download Visual Basic Express (I recommend 2010 at this moment) here: http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express Create a new empty project and paste this code and then compile it (Build), which will create an .exe file which you can execute.


RE: Do you understand this? - #Swag_mybb_import6403 - 09-27-2012

This is vbscript not Visual Basic so this really isn't in the right section at all still.

Anyways for help try learning a little and visit here to learn what it does: http://w3schools.com/vbscript/default.asp

You don't need VS to run this. All you need to do is save it as a .vbs and run it or just insert the code into an asp file and run it from internet explorer. You cannot compile vbscript into an exe.


RE: Do you understand this? - curtis5000 - 09-28-2012

Am sorry for the wrong section posting...& thank u guys for the responses..been helpful


RE: Do you understand this? - Frooxius - 09-30-2012

Ah sorry, yes this is VBscript, I missed that. They're kinda similar though.

#swag: Just a small addition: technically you can compile VBscript into an EXE file, there are some compilers out there and you could also write your own, it's just about converting the language into machine language, although you don't need to do that, since you can just use the interpreter.


RE: Do you understand this? - ArkPhaze - 09-30-2012

It's pretty simple, it's a command line script. Although the check for arguments is insufficient because it's only based on the count of arguments given. That's selfish to assume things like that. In my opinion this could have been improved on, I would have done things a bit differently.

Although this is still just vbscript, so some limitations are a factor in comparison to VB.net.