Jump to content
luca123

Poate sa imi zica cineva ce ce gresesc aici ca nu imi merge

Recommended Posts

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.EXAMPLE.COM/EXECUTE.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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...