hackoo

Download_Silently_Install_PDFCreator.vbs

Aug 5th, 2021
788
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. Const LOG_FILE_PATH = "LogInstall.txt"
  3. Dim Title,WaitingBar,oExec,fso,ws,Temp,PathScript,Question,MaCmd
  4. Title = "Downloading and Installing PDFCreator by " & chr(169) & " Hackoo 2021"
  5. Set ws = CreateObject("wscript.Shell")
  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7. If fso.FileExists(LOG_FILE_PATH) Then fso.DeleteFile(LOG_FILE_PATH)
  8. Temp = ws.ExpandEnvironmentStrings("%Temp%")
  9. Call DownloadingFile("http://download.pdfforge.org/download/pdfcreator/PDFCreator-stable?download")
  10. Title = "Installation of "& DblQuote("PDFCreator") &" by " & chr(169) & " Hackoo 2021"
  11. WaitingBar = "Please wait ... Installing "& DblQuote("PDFCreator") &" is in progress..."
  12. Call CreateProgressBar(Title,WaitingBar)'Creation de barre de progression
  13. Call LancerProgressBar() 'Launch of the progress bar
  14. Log LOG_FILE_PATH, String(10,"-") & Now & String(10,"-") & vbCrLf & "PDFCreator Silent installation" & vbCrLf & String(70,"-")
  15. MaCmd = "Start /Wait /Min PDFCreator.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-"
  16. If Executer(MaCmd,0) <> 0 Then
  17.     Log LOG_FILE_PATH, "Failed to install"
  18. Else
  19.     Log LOG_FILE_PATH, "Successful installation of PDFCreator"
  20. End If
  21. Log LOG_FILE_PATH, String(10,"-") & Now & String(10,"-") & vbCrLf & "End of silent installation of PDFCreator " & vbCrLf & String(70,"-")
  22. Call FermerProgressBar() 'Closing progress bar
  23. ws.Run LOG_FILE_PATH
  24. '--------------------------------------------------------------------------------------------------------------------
  25. Sub DownloadingFile(URL)
  26.     Dim Title,objFSO,Ws,objXMLHTTP,PathScript,Tab,strHDLocation,objADOStream,Command,Start,File
  27.     Dim MsgTitle,WaitingBar,StartTime,DurationTime,ProtocoleHTTP
  28.     Set objFSO = Createobject("Scripting.FileSystemObject")
  29.     Set Ws = CreateObject("wscript.Shell")
  30.     PathScript = fso.GetParentFolderName(wscript.ScriptFullName) 'Path of this Vbscript
  31.     ProtocoleHTTP = "http://"
  32.     If URL = "" Then WScript.Quit
  33.     If Left(URL,7) <> ProtocoleHTTP Then
  34.         URL = ProtocoleHTTP & URL
  35.     End if
  36.     File = "PDFCreator.exe"
  37.     Title = "Downloading File : " & Dblquote(File) & " " & chr(169) & " Hackoo 2021"
  38.     Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
  39.     strHDLocation = PathScript & "\" & File
  40.     WaitingBar = "Please wait. Downloading "& DblQuote("PDFCreator") &" is in progress..."
  41.     Call CreateProgressBar(Title,WaitingBar)'Creation de barre de progression
  42.     Call LancerProgressBar() 'Launch of the progress bar
  43.     StartTime = Timer 'Start the Timer Counter
  44.     On Error Resume Next
  45.     objXMLHTTP.open "GET",URL,false
  46.     objXMLHTTP.send()
  47.     If Err.number <> 0 Then
  48.         Call FermerProgressBar()'Closing progress bar
  49.         MsgBox err.description,16,err.description
  50.         Exit Sub
  51.     Else
  52.         If objXMLHTTP.Status = 200 Then
  53.             strHDLocation = PathScript & "\" & File
  54.             Set objADOStream = CreateObject("ADODB.Stream")
  55.             objADOStream.Open
  56.             objADOStream.Type = 1 'adTypeBinary
  57.             objADOStream.Write objXMLHTTP.ResponseBody
  58.             objADOStream.Position = 0    'Set the stream position to the start
  59.             If objFSO.FileExists(strHDLocation) Then objFSO.DeleteFile strHDLocation
  60.             objADOStream.SaveToFile strHDLocation
  61.             objADOStream.Close
  62.             Set objADOStream = Nothing
  63.         End If
  64.     End if
  65.     Set objXMLHTTP = Nothing
  66.     DurationTime = FormatNumber(Timer - StartTime, 0) & " seconds." 'The duration of the script
  67.     Call FermerProgressBar() 'Closing progress bar
  68.     ws.Popup "The Download of " & Dblquote(File) & " is finished in " & DurationTime &" !","5",_
  69.     "The Download of " & Dblquote(File) & " is finished in " & DurationTime &" !",vbInformation+vbSystemModal
  70. End Sub
  71. '----------------------------------------------------------------------------------------------------
  72. Sub CreateProgressBar(Title,WaitingBar)
  73.     Dim ws,fso,f,f2,ts,ts2,Ligne,i,fread,LireTout,NbLigneTotal,Temp,PathOutPutHTML,fhta,oExec
  74.     Set ws = CreateObject("wscript.Shell")
  75.     Set fso = CreateObject("Scripting.FileSystemObject")
  76.     Temp = WS.ExpandEnvironmentStrings("%Temp%")
  77.     PathOutPutHTML = Temp & "\Barre.hta"
  78.     Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
  79.     fhta.WriteLine "<HTML>"
  80.     fhta.WriteLine "<HEAD>"
  81.     fhta.WriteLine "<Title>  " & Title & "</Title>"
  82.     fhta.WriteLine "<HTA:APPLICATION"
  83.     fhta.WriteLine "ICON = ""magnify.exe"" "
  84.     fhta.WriteLine "BORDER=""THIN"" "
  85.     fhta.WriteLine "INNERBORDER=""NO"" "
  86.     fhta.WriteLine "MAXIMIZEBUTTON=""NO"" "
  87.     fhta.WriteLine "MINIMIZEBUTTON=""NO"" "
  88.     fhta.WriteLine "SCROLL=""NO"" "
  89.     fhta.WriteLine "SYSMENU=""NO"" "
  90.     fhta.WriteLine "SELECTION=""NO"" "
  91.     fhta.WriteLine "SINGLEINSTANCE=""YES"">"
  92.     fhta.WriteLine "</HEAD>"
  93.     fhta.WriteLine "<BODY text=""white""><CENTER><DIV><SPAN ID=""ProgressBar""></SPAN>"
  94.     fhta.WriteLine "<span><marquee DIRECTION=""LEFT"" SCROLLAMOUNT=""3"" BEHAVIOR=ALTERNATE><font face=""Comic sans MS"">" & WaitingBar &_
  95.     "</font></marquee></span></DIV></CENTER></BODY></HTML>"
  96.     fhta.WriteLine "<SCRIPT LANGUAGE=""VBScript""> "
  97.     fhta.WriteLine "Set ws = CreateObject(""wscript.Shell"")"
  98.     fhta.WriteLine "Temp = WS.ExpandEnvironmentStrings(""%Temp%"")"
  99.     fhta.WriteLine "Sub window_onload()"
  100.     fhta.WriteLine "    CenterWindow 430,90"
  101.     fhta.WriteLine "    Self.document.bgColor = ""Orange"" "
  102.     fhta.WriteLine " End Sub"
  103.     fhta.WriteLine " Sub CenterWindow(x,y)"
  104.     fhta.WriteLine "    Dim iLeft,itop"
  105.     fhta.WriteLine "    window.resizeTo x,y"
  106.     fhta.WriteLine "    iLeft = window.screen.availWidth/2 - x/2"
  107.     fhta.WriteLine "    itop = window.screen.availHeight/2 - y/2"
  108.     fhta.WriteLine "    window.moveTo ileft,itop"
  109.     fhta.WriteLine "End Sub"
  110.     fhta.WriteLine "</script>"
  111.     fhta.close
  112. End Sub
  113. '----------------------------------------------------------------------------------------------
  114. Sub LancerProgressBar()
  115.     Set oExec = Ws.Exec("mshta.exe " & Temp & "\Barre.hta")
  116. End Sub
  117. '----------------------------------------------------------------------------------------------
  118. Sub FermerProgressBar()
  119.     oExec.Terminate
  120. End Sub
  121. '----------------------------------------------------------------------------------------------
  122. Function DblQuote(Str)
  123.     DblQuote = Chr(34) & Str & Chr(34)
  124. End Function
  125. '----------------------------------------------------------------------------------------------
  126. Function Executer(StrCmd,Console)
  127.     Dim ws,MyCmd,Resultat
  128.     Set ws = CreateObject("wscript.Shell")
  129.     MyCmd = "CMD /C " & StrCmd & ""
  130.     Log LOG_FILE_PATH, "Launching of the command ==> " & DblQuote(MyCmd)
  131.     Resultat = ws.run(MyCmd,Console,True)
  132.     Log LOG_FILE_PATH, "Return code  ==> " & DblQuote(Resultat)
  133.     Executer = Resultat
  134. End Function
  135. '----------------------------------------------------------------------------------------------
  136. Sub Log(strLogFilePath,strLogContent)
  137.     Const APPEND = 8
  138.     Dim objFso, objLogFile
  139.     Set objFso = CreateObject("Scripting.FileSystemObject")
  140.     If Not objFso.FileExists(strLogFilePath) Then objFso.CreateTextFile(strLogFilePath, True).Close
  141.     Set objLogFile = objFso.OpenTextFile(strLogFilePath, APPEND)
  142.     objLogFile.WriteLine strLogContent
  143.     objLogFile.Close
  144. End Sub
  145. '----------------------------------------------------------------------------------------------
RAW Paste Data