how do i make a fake progress bar in VBscript - vbscript

how do I make a fake progress bar in VBScript?
I want to make a program that pretends it is downloading things.
I want to make it realistic by adding a moving progress bar, how do I do it, if it is possible?

Here is an example that can create a HTA ProgressBar while you download a file from internet :
Option Explicit
If AppPrevInstance() Then
MsgBox "The script is already launching" & vbCrlf &_
CommandLineLike(WScript.ScriptName),VbExclamation,"The script is already launching"
WScript.Quit
Else
Const Copyright = " by Hackoo 2018"
Dim Title : Title = "Get Header Location and download file" & Copyright
Const WHR_EnableRedirects = 6
Dim Default_Link,Base_Link,Dynamic_Link,Flag,Question,DirectLink,Save2File
Dim fso,ws,Temp,WaitingMsg,oExec
Default_Link = "https://downloads.malwarebytes.com/file/mb3/"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("WScript.Shell")
Temp = ws.ExpandEnvironmentStrings("%Temp%")
' "https://downloads.malwarebytes.com/file/mb3/" 'Tested OK ==> Malwarebytes v3.5.1
' "https://download.toolslib.net/download/file/1/1511" 'Tested OK ==> Adwcleaner v7.1.1
' "https://www.google.tn/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" Tested OK ==> a direct link example
Base_Link = InputBox("Copy and paste your link here to get the response header",Title,Default_Link)
If CheckDirectLink(Base_Link) = True And Instr(Base_Link,"php") = 0 Then 'Check if it is a direct link
Save2File = GetFileNamefromDirectLink(Base_Link)
If Save2File = "" Then
MsgBox "An unknown error has occurred ! Quitting the script !",vbCritical,Title
Wscript.Quit()
End If
WaitingMsg = "Please wait ... The download of : <font color=Yellow>"& DblQuote(Save2File) & "</font> is in progress ..."
Call CreateProgressBar(Title,WaitingMsg)'Creation of Waiting Bar
Call LaunchProgressBar() 'Launch of the Waiting Bar
Call Download(Base_Link,Save2File)
pause(3)
Call CloseProgressBar()
MsgBox "The download of the file : "& Save2File & vbCrlf &_
"is Completed !",vbInformation,Title
wscript.Quit()
End If
Call GetHeaderLocation(Base_Link)
If Flag = True And CheckDirectLink(GetHeaderLocation(Base_Link)) = True Then 'Checking for a direct link of Malwarebytes
Save2File = GetFileNamefromDirectLink(GetHeaderLocation(Base_Link))
If Save2File = "" Then
MsgBox "An unknown error has occurred ! Quitting the script !",vbCritical,Title
Wscript.Quit()
End If
DirectLink = GetHeaderLocation(Base_Link)
'wscript.echo DirectLink & vbCrlf & Save2File
Question = MsgBox("Did you want to download this file ?" & vbCrlf &_
Save2File,vbQuestion+vbYesNo,Title)
If Question = vbYes Then
If Save2File <> "" Then
WaitingMsg = "Please wait ... The download of : <font color=Yellow>"& DblQuote(Save2File) & "</font> is in progress ..."
Call CreateProgressBar(Title,WaitingMsg)'Creation of Waiting Bar
Call LaunchProgressBar() 'Launch of the Waiting Bar
Call Download(DirectLink,Save2File)
Call CloseProgressBar()
MsgBox "The download of the file : "& Save2File & vbCrlf &_
"is Completed !",vbInformation,Title
Wscript.Quit()
End If
End If
ElseIf Instr(Base_Link,"toolslib") <> 0 And Flag = True Then 'for Adwcleaner
Dynamic_Link = Extract_Dynamic_Link(GetDataFromURL(Base_Link,"Get", ""))
Save2File = GetFileName(GetHeaderLocation(Dynamic_Link))
If Save2File = "" Then
MsgBox "An unknown error has occurred ! Quitting the script !",vbCritical,Title
Wscript.Quit()
End If
Question = MsgBox("The Dynamic Link is = "& Dynamic_Link & vbcrlf & vbcrlf &_
"Response of The Dynamic Link is : "& vbcrlf & GetHeaderLocation(Dynamic_Link) & vbCrlf & vbCrlf &_
"Extracted FileName is = " & Save2File,vbYesNo+vbQuestion,Title)
If Question = vbYes Then
WaitingMsg = "Please wait ... The download of : <font color=Yellow>"& DblQuote(Save2File) & "</font> is in progress ..."
Call CreateProgressBar(Title,WaitingMsg)'Creation of Waiting Bar
Call LaunchProgressBar() 'Launch of the Waiting Bar
Call Download(Dynamic_Link,Save2File)
Call CloseProgressBar()
MsgBox "The download of the file : "& Save2File & vbCrlf &_
"is Completed !",vbInformation,Title
Else
Wscript.Quit()
End If
ElseIf Instr(Base_Link,"php") > 0 And Flag = False Then
Save2File = GetFileName(GetHeaderLocation(Base_Link)) ' for site of autoitscript.fr
If Save2File = "" Then
MsgBox "An unknown error has occurred ! Quitting the script !",vbCritical,Title
Wscript.Quit()
End If
Question = MsgBox("Did you want to download this file ?" & vbCrlf &_
Save2File,vbQuestion+vbYesNo,Title)
If Question = vbYes Then
WaitingMsg = "Please wait ... The download of : <font color=Yellow>"& DblQuote(Save2File) & "</font> is in progress ..."
Call CreateProgressBar(Title,WaitingMsg)'Creation of Waiting Bar
Call LaunchProgressBar() 'Launch of the Waiting Bar
Call Download(Base_Link,Save2File)
pause(3)
Call CloseProgressBar()
MsgBox "The download of the file : "& Save2File & vbCrlf &_
"is Completed !",vbInformation,Title
Else
Wscript.Quit()
End If
End If
End If
'------------------------------------------------
Function GetHeaderLocation(URL)
On Error Resume Next
Dim h,GetLocation
Set h = CreateObject("WinHttp.WinHttpRequest.5.1")
h.Option(WHR_EnableRedirects) = False
h.Open "HEAD", URL , False
h.Send()
GetLocation = h.GetResponseHeader("Location")
If Err = 0 Then
Flag = True
GetHeaderLocation = GetLocation
Else
Flag = False
GetHeaderLocation = h.GetResponseHeader("Content-Disposition")
End If
End Function
'---------------------------------------------
Function GetFileName(Data)
Dim regEx, Match, Matches,FileName
Set regEx = New RegExp
regEx.Pattern = "\x27{2}(\w.*)"
regEx.IgnoreCase = True
regEx.Global = True
If regEx.Test(Data) Then
Set Matches = regEx.Execute(Data)
For Each Match in Matches
FileName = Match.subMatches(0)
Next
Else
Set regEx = New RegExp
regEx.Pattern = "\x22(\w.*)\x22"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(Data)
For Each Match in Matches
FileName = Match.subMatches(0)
Next
End If
GetFileName = FileName
End Function
'---------------------------------------------
Function Extract_Dynamic_Link(Data)
Dim regEx, Match, Matches,Dynamic_Link
Set regEx = New RegExp
regEx.Pattern = Base_Link & "\?s=[^""]*"
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(Data)
For Each Match in Matches
Dynamic_Link = Match.Value
Next
Extract_Dynamic_Link = Dynamic_Link
End Function
'------------------------------------------------
Function GetDataFromURL(strURL, strMethod, strPostData)
Dim lngTimeout
Dim strUserAgentString
Dim intSslErrorIgnoreFlags
Dim blnEnableRedirects
Dim blnEnableHttpsToHttpRedirects
Dim strHostOverride
Dim strLogin
Dim strPassword
Dim strResponseText
Dim objWinHttp
lngTimeout = 59000
strUserAgentString = "http_requester/0.1"
intSslErrorIgnoreFlags = 13056 ' 13056: ignore all err, 0: accept no err
blnEnableRedirects = True
blnEnableHttpsToHttpRedirects = True
strHostOverride = ""
strLogin = ""
strPassword = ""
Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
objWinHttp.SetTimeouts lngTimeout, lngTimeout, lngTimeout, lngTimeout
objWinHttp.Open strMethod, strURL
If strMethod = "POST" Then
objWinHttp.setRequestHeader "Content-type", _
"application/x-www-form-urlencoded"
End If
If strHostOverride <> "" Then
objWinHttp.SetRequestHeader "Host", strHostOverride
End If
objWinHttp.Option(0) = strUserAgentString
objWinHttp.Option(4) = intSslErrorIgnoreFlags
objWinHttp.Option(6) = blnEnableRedirects
objWinHttp.Option(12) = blnEnableHttpsToHttpRedirects
If (strLogin <> "") And (strPassword <> "") Then
objWinHttp.SetCredentials strLogin, strPassword, 0
End If
On Error Resume Next
objWinHttp.Send(strPostData)
If Err.Number = 0 Then
If objWinHttp.Status = "200" Then
GetDataFromURL = objWinHttp.ResponseText
Else
GetDataFromURL = "HTTP " & objWinHttp.Status & " " & _
objWinHttp.StatusText
End If
Else
GetDataFromURL = "Error " & Err.Number & " " & Err.Source & " " & _
Err.Description
End If
On Error GoTo 0
Set objWinHttp = Nothing
End Function
'------------------------------------------------
Sub Download(URL,Save2File)
Dim File,Line,BS,ws
On Error Resume Next
Set File = CreateObject("WinHttp.WinHttpRequest.5.1")
File.Open "GET",URL, False
File.Send()
If err.number <> 0 then
Line = Line & vbcrlf & "Error Getting File"
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & vbcrlf &_
err.description
Line = Line & vbcrlf & "Source " & err.source
MsgBox Line,vbCritical,"Error getting file"
Err.clear
wscript.quit
End If
If File.Status = 200 Then ' File exists and it is ready to be downloaded
Set BS = CreateObject("ADODB.Stream")
Set ws = CreateObject("wscript.Shell")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile Save2File, 2
ElseIf File.Status = 404 Then
MsgBox "File Not found : " & File.Status,vbCritical,"Error File Not Found"
Else
MsgBox "Unknown Error : " & File.Status,vbCritical,"Error getting file"
End If
End Sub
'------------------------------------------------
Function GetFileNamefromDirectLink(URL)
Dim ArrFile,FileName
ArrFile = Split(URL,"/")
FileName = ArrFile(UBound(ArrFile))
GetFileNamefromDirectLink = FileName
End Function
'------------------------------------------------
Function CheckDirectLink(URL)
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "(.exe|.zip|.rar|.msi|.vbs|.bat|.hta|.txt|.log|.doc" & _
"|.docx|.xls|.xlsx|.pdf|.mp3|.mp4|.avi|.png|.jpg|.jpeg|.bmp|.gif)"
regEx.IgnoreCase = True
regEx.Global = False
If regEx.Test(URL) Then
CheckDirectLink = True
End If
End Function
'------------------------------------------------
'**********************************************************************************************
Sub CreateProgressBar(Title,WaitingMsg)
Dim ws,fso,f,f2,ts,ts2,Ligne,i,fread,LireTout,NbLigneTotal,Temp,PathOutPutHTML,fhta,oExec
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Temp = WS.ExpandEnvironmentStrings("%Temp%")
PathOutPutHTML = Temp & "\Barre.hta"
Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
fhta.WriteLine "<HTML>"
fhta.WriteLine "<HEAD>"
fhta.WriteLine "<Title> " & Title & "</Title>"
fhta.WriteLine "<HTA:APPLICATION"
fhta.WriteLine "ICON = ""magnify.exe"" "
fhta.WriteLine "BORDER=""THIN"" "
fhta.WriteLine "INNERBORDER=""NO"" "
fhta.WriteLine "MAXIMIZEBUTTON=""NO"" "
fhta.WriteLine "MINIMIZEBUTTON=""NO"" "
fhta.WriteLine "SCROLL=""NO"" "
fhta.WriteLine "SYSMENU=""NO"" "
fhta.WriteLine "SELECTION=""NO"" "
fhta.WriteLine "SINGLEINSTANCE=""YES"">"
fhta.WriteLine "</HEAD>"
fhta.WriteLine "<BODY text=""white""><CENTER>"
fhta.WriteLine "<marquee DIRECTION=""LEFT"" SCROLLAMOUNT=""3"" BEHAVIOR=ALTERNATE><font face=""Comic sans MS"">" & WaitingMsg &"</font></marquee>"
fhta.WriteLine "<img src=""data:image/gif;base64,R0lGODlhgAAPAPIAAP////INPvvI0/q1xPVLb/INPgAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAgAAPAAAD5wiyC/6sPRfFpPGqfKv2HTeBowiZGLORq1lJqfuW7Gud9YzLud3zQNVOGCO2jDZaEHZk+nRFJ7R5i1apSuQ0OZT+nleuNetdhrfob1kLXrvPariZLGfPuz66Hr8f8/9+gVh4YoOChYhpd4eKdgwDkJEDE5KRlJWTD5iZDpuXlZ+SoZaamKOQp5wAm56loK6isKSdprKotqqttK+7sb2zq6y8wcO6xL7HwMbLtb+3zrnNycKp1bjW0NjT0cXSzMLK3uLd5Mjf5uPo5eDa5+Hrz9vt6e/qosO/GvjJ+sj5F/sC+uMHcCCoBAAh+QQJCgAAACwAAAAAgAAPAAAD/wi0C/4ixgeloM5erDHonOWBFFlJoxiiTFtqWwa/Jhx/86nKdc7vuJ6mxaABbUaUTvljBo++pxO5nFQFxMY1aW12pV+q9yYGk6NlW5bAPQuh7yl6Hg/TLeu2fssf7/19Zn9meYFpd3J1bnCMiY0RhYCSgoaIdoqDhxoFnJ0FFAOhogOgo6GlpqijqqKspw+mrw6xpLCxrrWzsZ6duL62qcCrwq3EsgC0v7rBy8PNorycysi3xrnUzNjO2sXPx8nW07TRn+Hm3tfg6OLV6+fc37vR7Nnq8Ont9/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ZDpuXlZ+SoZaamKOQp5wAm56loK6isKSdprKotqqttK+7sb2zq6y8wcO6xL7HwMbLtb+3zrnNycKp1bjW0NjT0cXSzMLK3uLd5Mjf5uPo5eDa5+Hrz9vt6e/qosO/GvjJ+sj5F/sC+uMHcCCoBAA7AAAAAAAAAAAA"" />"
fhta.WriteLine "</CENTER></BODY></HTML>"
fhta.WriteLine "<SCRIPT LANGUAGE=""VBScript""> "
fhta.WriteLine "Set ws = CreateObject(""wscript.Shell"")"
fhta.WriteLine "Temp = WS.ExpandEnvironmentStrings(""%Temp%"")"
fhta.WriteLine "Sub window_onload()"
fhta.WriteLine " CenterWindow 570,100"
fhta.WriteLine " Self.document.bgColor = ""DarkOrange"" "
fhta.WriteLine " End Sub"
fhta.WriteLine " Sub CenterWindow(x,y)"
fhta.WriteLine " Dim iLeft,itop"
fhta.WriteLine " window.resizeTo x,y"
fhta.WriteLine " iLeft = window.screen.availWidth/2 - x/2"
fhta.WriteLine " itop = window.screen.availHeight/2 - y/2"
fhta.WriteLine " window.moveTo ileft,itop"
fhta.WriteLine "End Sub"
fhta.WriteLine "</script>"
fhta.close
End Sub
'**********************************************************************************************
Sub LaunchProgressBar()
Set oExec = Ws.Exec("mshta.exe " & Temp & "\Barre.hta")
End Sub
'**********************************************************************************************
Sub CloseProgressBar()
oExec.Terminate
End Sub
'**********************************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
Sub Pause(Secs)
Wscript.Sleep(Secs * 1000)
End Sub
'**********************************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'*********************************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'*********************************************************************************************

You can use this code:
set objShell = CreateObject("Wscript.shell")
sub start()
do while valeur < 101
valeur = valeur + 1
refresh
wait 1
loop
msgbox "Loading completed!"
end sub
Sub wait (Timesec)
objShell.Run "Timeout /T " & Timesec & " /nobreak" ,0 ,true
End Sub
sub refresh()
document.getelementbyid("chargement").style.width = valeur&"%"
end sub
This code use CSS:
#barreComp
{
width:300px;
height:30px;
border: 2px solid #00cc00;
}
#chargement
{
width:1%;
height:100%;
background-color:#00cc00;
}
chargement (it mean loading) is a div inside barreComp (completebar).
When the width of chargement is to 50%, it show a half filled rectangle.
Do you understand what I mean?

Related

Unable to pin .exe with parameter to Taskbar/Start Menu

I'm trying to write a .vbs script to pin an .exe to my taskbar and start menu.
However, the .exe will only run if I pass in a package parameter.
Here's the target of the shortcut:
"C:\Program Files (x86)\Launch\AppLauncher.exe" package=TEST
I currently have the following for code but I get the error message attached when I try and run it.
Const a = """"
arrActions = Array( _
"pin", "Start Menu", """C:\Program Files (x86)\Launch\AppLauncher.exe"" package=TEST", _
"pin", "Taskbar", """C:\Program Files (x86)\Launch\AppLauncher.exe"" package=TEST" _ )
For intAction = 0 To (UBound(arrActions) - 2) Step 3
arrFileNames = Array(arrActions(intAction + 2))
'strMode can be "Pin" or "Unpin"
strMode = arrActions(intAction)
'strLocation can be "Start Menu" or "Taskbar" or "Both"
strLocation = arrActions(intAction + 1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShellApp = CreateObject("Shell.Application")
Set objShell = CreateObject("WScript.Shell")
If LCase(strLocation) = "both" Then
arrLocations = Array("Start Menu", "Taskbar")
Else
arrLocations = Array(strLocation)
End If
For Each strLocation In arrLocations
If LCase(strMode) <> "pin" And LCase(strMode) <> "unpin" Then
WScript.Echo "Mode is incorrect. Please set to ""pin"" or ""unpin""."
WScript.Quit
ElseIf LCase(strLocation) <> "start menu" And LCase(strLocation) <> "taskbar" Then
WScript.Echo "Location is incorrect. Please set to ""Start Menu"" or ""Taskbar""."
WScript.Quit
Else
strMode = LCase(strMode)
If strMode = "pin" Then
strVerb = LCase(strMode & " to " & strLocation)
strMessage = " has been " & strMode & "ned to the " & strLocation & "."
ElseIf strMode = "unpin" Then
strVerb = LCase(strMode & " from " & strLocation)
strMessage = " has been " & strMode & "ned from the " & strLocation & "."
End If
For Each strFilePath In arrFileNames
If LCase(strFilePath) = "unpin_all" And strMode = "unpin" Then
strPinLocation = objShell.ExpandEnvironmentStrings("%APPDATA%") & _
"\Microsoft\Internet Explorer\Quick Launch\User Pinned\" & _
Replace(strLocation, " ", "") & "\"
For Each objFile In objFSO.GetFolder(strPinLocation).Files
strFullPath = objFile.Path
'Set objFile = objFSO.GetFile(objFile.Path)
Set objFolder = objShellApp.Namespace(objFile.ParentFolder & "\")
Set objFolderItem = objFolder.ParseName(objFile.Name)
Set colVerbs = objFolderItem.Verbs
For Each objVerb In colVerbs
If LCase(Replace(objVerb.name, "&", "")) = strVerb Then
objVerb.DoIt
WScript.Echo strFullPath & strMessage
End If
Next
Next
Else
If objFSO.FileExists(strFilePath) = True Then
Set objFile = objFSO.GetFile(strFilePath)
Set objFolder = objShellApp.Namespace(objFile.ParentFolder & "\")
Set objFolderItem = objFolder.ParseName(objFile.Name)
Set colVerbs = objFolderItem.Verbs
blnOptionFound = False
For Each objVerb In colVerbs
If LCase(Replace(objVerb.name, "&", "")) = strVerb Then
objVerb.DoIt
blnOptionFound = True
End If
Next
If blnOptionFound = True Then
WScript.Echo strFilePath & strMessage
Else
WScript.Echo "Unable to " & strMode & " " & strFilePath & _
" from the " & strLocation & ". The verb does not exist."
End If
Else
WScript.Echo "Could not find " & strFilePath
End If
End If
Next
End If
Next
Next
Error message

How to download a file without browser and open/save dialog batch maybe?

I'm asking that what other method to download a file from internet other than browsers and other softwares, i think is possible with CMD(command line), batch script ?
To be more exactly to use a windows (let say 7) component to download a file without a dialog like vbs, hta, ..etc, is possible? I dont want to download wget, curl, telnet or other component
This will work on windows 7?
http://semitwist.com/articles/article/view/downloading-files-from-plain-batch-with-zero-dependencies
Try this sample in vbscript :
Option Explicit
Dim URL,ws,fso,Srcimage,Temp,PathOutPutHTML,fhta,stRep,stFichier,oShell,oFolder,oFichier,Dimensions
Dim arrSize,intLength,intHorizontalSize,intVerticalSize,Tab
URL = "http://www.animatedimages.org/data/media/902/animated-tunisia-flag-image-0023.gif"
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Temp = WS.ExpandEnvironmentStrings("%Temp%")
PathOutPutHTML = Temp & "\image.hta"
Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
stRep = Temp
Tab = split(url,"/")
stFichier = Tab(UBound(Tab))
Srcimage = stRep & "\" & stFichier
If Not fso.FileExists(Srcimage) Then
Call DownloadingFile(URL,Srcimage)
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.Namespace(stRep)
Set oFichier = oFolder.Items.Item(stFichier)
Dimensions = oFolder.GetDetailsOf(oFichier,31)
arrSize = Split(Dimensions,"x")
'***************************************Important à savoir **********************************************
'Instead, we ended up retrieving item 31, which gave us the total dimensions of the picture,
'using an output format similar to this: ?150 x 354?
'http://blogs.technet.com/b/heyscriptingguy/archive/2008/05/16/how-can-i-search-a-folder-for-all-the-image-files-that-are-not-a-specified-height-and-width.aspx
'Un grand merci à omen999 ==>
'http://www.developpez.net/forums/d1504644/autres-langages/general-visual-basic-6-vbscript/vbscript/passage-variables-procedure/#post8163406
intLength = Len(arrSize(0))
intHorizontalSize = Right(arrSize(0),intLength -1)
intLength = Len(arrSize(1))
intVerticalSize = Left(arrSize(1),intLength - 1)
'***************************************Important à savoir **********************************************
Call LoadImage(Srcimage,intHorizontalSize,intVerticalSize,Timeout(51))
ws.run "mshta.exe " & PathOutPutHTML
Else
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.Namespace(stRep)
Set oFichier = oFolder.Items.Item(stFichier)
Dimensions = oFolder.GetDetailsOf(oFichier,31)
arrSize = Split(Dimensions,"x")
intLength = Len(arrSize(0))
intHorizontalSize = Right(arrSize(0),intLength -1)
intLength = Len(arrSize(1))
intVerticalSize = Left(arrSize(1),intLength - 1)
Call LoadImage(Srcimage,intHorizontalSize,intVerticalSize,Timeout(51))
ws.run "mshta.exe " & PathOutPutHTML
End If
'********************************************************************************************************
Function TimeOut(T)
TimeOut = T * 1000
End Function
'********************************************************************************************************
Sub LoadImage(Srcimage,intHorizontalSize,intVerticalSize,TimeOut)
fhta.WriteLine "<html>"
fhta.WriteLine " <hta:application id=""oHTA"" "
fhta.WriteLine " border=""none"" "
fhta.WriteLine " caption=""no"" "
fhta.WriteLine " contextmenu=""no"" "
fhta.WriteLine " innerborder=""no"" "
fhta.WriteLine " scroll=""no"" "
fhta.WriteLine " showintaskbar=""no"" "
fhta.WriteLine " />"
fhta.WriteLine "<style>"
fhta.WriteLine "{ margin: 0; padding: 0; }"
fhta.WriteLine "body {background: url(" & DblQuote(Srcimage) & ") no-repeat center center fixed;}"
fhta.WriteLine "</style>"
fhta.WriteLine " <script language=""VBScript"">"
fhta.WriteLine " Sub Window_OnLoad()"
fhta.WriteLine " width = " & intHorizontalSize
fhta.WriteLine " height = " & intVerticalSize
fhta.WriteLine " window.resizeTo width, height"
fhta.WriteLine " window.moveTo screen.availWidth\2 - width\2, screen.availHeight\2 - height\2"
fhta.WriteLine " idTimer = window.setTimeout(""vbscript:window.close"","& TimeOut &")"
fhta.WriteLine " window.setInterval ""setfocus()"",100"
fhta.WriteLine " End Sub"
fhta.WriteLine " Function setfocus"
fhta.WriteLine " Window.Focus()"
fhta.WriteLine " End Function"
fhta.WriteLine " </script>"
fhta.WriteLine "<body>"
fhta.WriteLine "<bgsound src=""http://hackoo.alwaysdata.net/Tunisie.mp3"">"
fhta.WriteLine "</body>"
fhta.WriteLine "</html>"
End Sub
'**********************************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
Sub DownloadingFile(URL,strHDLocation)
Dim Titre,objFSO,Ws,objXMLHTTP,PathScript,Tab,objADOStream,Command,Start,File
Dim MsgTitre,MsgAttente,StartTime,DurationTime,ProtocoleHTTP
Set objFSO = Createobject("Scripting.FileSystemObject")
Set Ws = CreateObject("wscript.Shell")
ProtocoleHTTP = "http://"
If Left(URL,7) <> ProtocoleHTTP Then
URL = ProtocoleHTTP & URL
End if
Tab = split(url,"/")
File = Tab(UBound(Tab))
File = Replace(File,"%20"," ")
File = Replace(File,"%28","(")
File = Replace(File,"%29",")")
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.3.0")
strHDLocation = PathScript & "\" & File
On Error Resume Next
objXMLHTTP.open "GET",URL,false
objXMLHTTP.send()
If Err.number <> 0 Then
MsgBox err.description,16,err.description
Exit Sub
Else
If objXMLHTTP.Status = 200 Then
strHDLocation = Temp & "\" & File
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
objADOStream.SaveToFile strHDLocation,2 '2=adSaveCreateOverWrite
objADOStream.Close
Set objADOStream = Nothing
End If
End if
Set objXMLHTTP = Nothing
End Sub
And may be another samples here : VBS/Batch Check if Download Complete
Batch cannot natively download files.
To download files from the command line, you must use third party tools like cURL or wget.
PowerShell will pretty easily do this; however - even though a version is included in Windows 7 - you'll probably want to download the latest version.
Within Windows 7 or Windows 8 (and related server versions) you can map a drive to a WebDAV folder and use COPY, XCOPY or ROBOCOPY to your heart's content. You can map the drive using command-line NET USE if you prefer.
For example, NET USE S: https:\live.sysinternals.com (or use PUSHD), and follow up with you copy commands.
cheers!
You can try this Vbscript that use PowerShell to download and execute the file.
So in this example we download an mp3 file and we play it.
Option Explicit
Dim MyCmd,Ws,Ret
Set Ws = CreateObject("wscript.Shell")
MyCmd = "cmd /c Powershell.exe -ExecutionPolicy bypass -noprofile -WindowStyle Hidden (New-Object System.Net.WebClient).DownloadFile('http://hackoo.alwaysdata.net/Matrix.mp3','%TEMP%\Matrix.mp3'); Start-Process %TEMP%\Matrix.mp3;"
Ret = Ws.run(MyCmd,0,True)
Linux:
wget http://somedomain.com/somefile.xxx
If you are using windows, download a exe named wget.exe(here) and you will be able to use the above code.

Find Specific Folder in Root of main and all drives attached vbs

I'd like to look for a specific folder that could be on the root of the main drive of a Windows 7 Machine or on the root of any usb drives attached to it. I'd prefer to do it in vbscript or in an hta (not htaaccess) using vbscript.
ex. I need to find the folder "xyz". It could be either here: C:\xyz or D:\xyz or Z:\xyz etc. I don't care if it's here: c:\Users\Joe\xyz or F:\folder1\xyz.
I figure the search would be fairly quick if the search is concentrated to just the root folders of each drive.
This vbscript can looking for folder in all your connected drives, so i add a waiting bar to let the user to be patient until it finish its job
Option Explicit
If AppPrevInstance() Then
MsgBox "There is an existing proceeding !" & VbCrLF & CommandLineLike(WScript.ScriptName),VbExclamation,"There is an existing proceeding !"
WScript.Quit
Else
Dim ws,fso,LogFile,Title,WaitingMsg,StartTime,DurationTime,FolderName,oExec,Temp
Set ws = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
LogFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log"
if fso.FileExists(LogFile) Then
fso.DeleteFile LogFile
end if
FolderName = InputBox("In the box below type in the folder you are looking for","Find Folder by Hackoo 2015","folder")
If FolderName = "" Then WScript.Quit
Temp = ws.ExpandEnvironmentStrings("%Temp%")
Title = "Looking for folder name "& DblQuote(FolderName) & " using Vbscript by Hackoo 2015"
WaitingMsg = "Please wait... Searching for folder name : <font color=Yellow>"& DblQuote(FolderName) & "</font> is in progress..."
Call CreateProgressBar(Title,WaitingMsg)'Creation of Waiting Bar
Call LancerProgressBar() 'Launch of the Waiting Bar
StartTime = Timer 'Start the Timer Counter
Call FindFolder(FolderName)
DurationTime = FormatNumber(Timer - StartTime, 0) & " seconds." 'The duration of the script
Call FermerProgressBar() 'Closing the Waiting Bar
ws.Popup "The Searching of " & Dblquote(FolderName) & " is finished in " & DurationTime &" !","5","The Download of " & Dblquote(FolderName) & " is finished in " & DurationTime &" !",64
ws.run DblQuote(LogFile) ' To open the LogFile
End If
'*************************************************************************************************************************
'Search for Folders
Sub FindFolder(Name)
Dim strComputer,objWMIService,colFolders,objFolder
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like "& CommandLineLike(Name) &"")
For Each objFolder in colFolders
WriteLog objFolder.Name
Next
End sub
'*************************************************************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'*************************************************************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'*****************************************************************************************************************************
Sub WriteLog(strText)
Dim fs,ts
Const ForAppending = 8
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "log", ForAppending, True)
ts.WriteLine strText
ts.Close
End Sub
'*******************************************************************************************************************************
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'*******************************************************************************************************************************
Sub CreateProgressBar(Title,WaitingMsg)
Dim ws,fso,f,f2,ts,ts2,Ligne,i,fread,LireTout,NbLigneTotal,Temp,PathOutPutHTML,fhta,oExec
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Temp = WS.ExpandEnvironmentStrings("%Temp%")
PathOutPutHTML = Temp & "\Barre.hta"
Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
fhta.WriteLine "<HTML>"
fhta.WriteLine "<HEAD>"
fhta.WriteLine "<Title> " & Title & "</Title>"
fhta.WriteLine "<HTA:APPLICATION"
fhta.WriteLine "ICON = ""magnify.exe"" "
fhta.WriteLine "BORDER=""THIN"" "
fhta.WriteLine "INNERBORDER=""NO"" "
fhta.WriteLine "MAXIMIZEBUTTON=""NO"" "
fhta.WriteLine "MINIMIZEBUTTON=""NO"" "
fhta.WriteLine "SCROLL=""NO"" "
fhta.WriteLine "SYSMENU=""NO"" "
fhta.WriteLine "SELECTION=""NO"" "
fhta.WriteLine "SINGLEINSTANCE=""YES"">"
fhta.WriteLine "</HEAD>"
fhta.WriteLine "<BODY text=""white""><CENTER>"
fhta.WriteLine "<marquee DIRECTION=""LEFT"" SCROLLAMOUNT=""3"" BEHAVIOR=ALTERNATE><font face=""Comic sans MS"">" & WaitingMsg &"</font></marquee>"
fhta.WriteLine "<img src=""data:image/gif;base64,R0lGODlhgAAPAPIAAP////INPvvI0/q1xPVLb/INPgAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAgAAPAAAD5wiyC/6sPRfFpPGqfKv2HTeBowiZGLORq1lJqfuW7Gud9YzLud3zQNVOGCO2jDZaEHZk+nRFJ7R5i1apSuQ0OZT+nleuNetdhrfob1kLXrvPariZLGfPuz66Hr8f8/9+gVh4YoOChYhpd4eKdgwDkJEDE5KRlJWTD5iZDpuXlZ+SoZaamKOQp5wAm56loK6isKSdprKotqqttK+7sb2zq6y8wcO6xL7HwMbLtb+3zrnNycKp1bjW0NjT0cXSzMLK3uLd5Mjf5uPo5eDa5+Hrz9vt6e/qosO/GvjJ+sj5F/sC+uMHcCCoBAAh+QQJCgAAACwAAAAAgAAPAAAD/wi0C/4ixgeloM5erDHonOWBFFlJoxiiTFtqWwa/Jhx/86nKdc7vuJ6mxaABbUaUTv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t6+CfDcafDGbOG5hhcYKoz4cGIrh80cPAOQAAAh+QQJCgAAACwAAAAAgAAPAAAD5wi0C/6sPRfJpPGqfKv2HTeBowiZGLORq1lJqfuW7Gud9YzLud3zQNVOGCO2jDZaEHZk+nRFJ7R5i1apSuQ0OZT+nleuNetdhrfob1kLXrvPariZLGfPuz66Hr8f8/9+gVh4YoOChYhpd4eKdgwFkJEFE5KRlJWTD5iZDpuXlZ+SoZaamKOQp5wAm56loK6isKSdprKotqqttK+7sb2zq6y8wcO6xL7HwMbLtb+3zrnNycKp1bjW0NjT0cXSzMLK3uLd5Mjf5uPo5eDa5+Hrz9vt6e/qosO/GvjJ+sj5F/sC+uMHcCCoBAA7AAAAAAAAAAAA"" />"
fhta.WriteLine "</CENTER></BODY></HTML>"
fhta.WriteLine "<SCRIPT LANGUAGE=""VBScript""> "
fhta.WriteLine "Set ws = CreateObject(""wscript.Shell"")"
fhta.WriteLine "Temp = WS.ExpandEnvironmentStrings(""%Temp%"")"
fhta.WriteLine "Sub window_onload()"
fhta.WriteLine " CenterWindow 490,110"
fhta.WriteLine " Self.document.bgColor = ""DarkOrange"" "
fhta.WriteLine " End Sub"
fhta.WriteLine " Sub CenterWindow(x,y)"
fhta.WriteLine " Dim iLeft,itop"
fhta.WriteLine " window.resizeTo x,y"
fhta.WriteLine " iLeft = window.screen.availWidth/2 - x/2"
fhta.WriteLine " itop = window.screen.availHeight/2 - y/2"
fhta.WriteLine " window.moveTo ileft,itop"
fhta.WriteLine "End Sub"
fhta.WriteLine "</script>"
fhta.close
End Sub
'**********************************************************************************************
Sub LancerProgressBar()
Set oExec = Ws.Exec("mshta.exe " & Temp & "\Barre.hta")
End Sub
'**********************************************************************************************
Sub FermerProgressBar()
oExec.Terminate
End Sub
'**********************************************************************************************
From Help
Read-only collection of all available drives.
Remarks
Removable-media drives need not have media inserted for them to appear in the Drives collection.
The following example illustrates how to get the Drives collection using the Drives property and iterate the collection:
Visual Basic Script Copy Code
Function ShowDriveList
Dim fso, d, dc, s, n
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives
For Each d in dc
n = ""
s = s & d.DriveLetter & " - "
If d.DriveType = 3 Then
n = d.ShareName
ElseIf d.IsReady Then
n = d.VolumeName
Else
n = "[Drive not ready]"
End If
s = s & n & "<BR>"
Next
ShowDriveList = s
End Function
Methods
The Drives collection has no methods.
Properties
Count Property | Item Property
See Also
Reference
Drive Object
Drives Property
File Object
Files Collection
Folder Object
Folders Collection
Thanks to #user4532213 for leading me in the right direction. Basically the information and code he gave lists all the drives that are attached and ready to use on your computer. It doesn't however look for a particular folder on each drive. So, I took some of what he mentioned and
Created a basic HTA file to make it easy to see if anyone finds this useful.
Added the ability to search for the particular folder on all drives.
Also realized you can use this to search for similar folder paths on different drives.
The usage is remarked in the HTA.
<html>
<Head>
<Title>Folder Finder.HTA</Title>
<HTA:Application
APPLICATIONNAME = " Folder Finder.HTA"
Border = Thick
ShowInTaskBar = No
MaximizeButton = Yes
MinimizeButton = Yes>
<Script Language = VBScript>
Sub Window_onLoad
window.resizeTo 400,300
self.MoveTo 100,100
searchfoldername.Focus
End Sub
Sub FindFolder
' this will search all active drives for a folder or path matching the word inputed by user and list them in this HTA.
' Usage: type in a word to search or a path in the box.
' Example: if you type in FOLDERONE it will search C:\FOLDERONE and/or B:\FOLDERONE (as long the drive is ready) etc.
' Example: if you type in FOLDERONE\SUBFOLDERONE it will search for C:\FOLDERONE\SUBFOLDERONE and/or F:\FOLDERONE\SUBFOLDERONE
Dim fso, d, dc, s, n, searchfolder
searchfolder = searchfoldername.value
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives
i = 0
For Each d in dc
s = d.DriveLetter & ":\"
Set oFSO=CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(s & searchfolder) Then
s = s & searchfolder & "<BR>"
ShowDriveList = s & ShowDriveList
i = i + 1
End If
Next
document.getElementById("DataArea").innerHTML = i & " matches:" & "<BR>" & ShowDriveList
End Sub
</Script><Body>In the box below type in the folder you are looking for<br></br>
<input type="text" name="searchfoldername"> </input><br></br>
<input type="button" button value="Search Folder" name="run_button" onClick="FindFolder"><br></br>
<Span Id = "DataArea"> </Span></Body>

VB script to check if the file size has been increased from the previous check

i need a VB script that checks the file size and captures it and in the next check it compares it with the previous check. If the size has increased, it should prompt File size increased.
You can give a try to this vbscript :
Option Explicit
const bytesToKb = 1024
Dim strFile,Title
Title = "The File Size Checker by Hackoo 2015"
strFile = "C:\test.txt"
Call CheckSize(strFile)
'*****************************************************************
Sub CheckSize(File)
Dim ws,fso,objFile,ReadSize,WriteSize,MySizeFile,Temp,LastSize
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Temp = ws.ExpandEnvironmentStrings("%Temp%")
MySizeFile = Temp & "\MyFileSize.txt"
If Not fso.FileExists(MySizeFile) Then
Set WriteSize = fso.OpenTextFile(MySizeFile,2,True)
set objFile = fso.GetFile(strFile)
WriteSize.Write objFile.Size
End If
Set ReadSize = fso.OpenTextFile(MySizeFile,1)
LastSize = ReadSize.readall
set objFile = fso.GetFile(strFile)
If CLng(objFile.Size) = CLng(LastSize) Then
MsgBox "There is no change on file size : " & CLng(LastSize) & " bytes" & vbcr &_
"Size in Kb : "& CLng(objFile.Size/bytesToKb) & " Kb",VbInformation,Title
else
Set WriteSize = fso.OpenTextFile(MySizeFile,2,True)
MsgBox "Last File Size is : " & CLng(LastSize) & " bytes" & vbcr &_
"New File Size is : " & objFile.Size & " bytes" & vbcr &_
"Size in Kb : "& CLng(objFile.Size/bytesToKb) & " Kb",VbExclamation,Title
WriteSize.Write objFile.Size
end if
End Sub
'*******************************************************************
I improved a little this script to check every minute in a loop if the size was changed or not, if yes it will popup a msgbox to notify you that size was changed, if no, it sleeps for 1 minute and it checks it again.
Option Explicit
const bytesToKb = 1024
Dim strFile,Title
Title = "The File Size Checker by Hackoo 2015"
strFile = "C:\test.txt"
If AppPrevInstance() Then
MsgBox "There is an existing proceeding",VbExclamation,"There is an existing proceeding"
WScript.Quit
Else
Do
Call CheckSize(strFile)
Loop
End If
'*****************************************************************
Sub CheckSize(File)
Dim ws,fso,objFile,ReadSize,WriteSize,MySizeFile,Temp,LastSize
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Temp = ws.ExpandEnvironmentStrings("%Temp%")
MySizeFile = Temp & "\MyFileSize.txt"
If Not fso.FileExists(MySizeFile) Then
Set WriteSize = fso.OpenTextFile(MySizeFile,2,True)
set objFile = fso.GetFile(strFile)
WriteSize.Write objFile.Size
End If
Set ReadSize = fso.OpenTextFile(MySizeFile,1)
LastSize = ReadSize.readall
set objFile = fso.GetFile(strFile)
If CLng(objFile.Size) = CLng(LastSize) Then
Call Pause(1) 'To sleep for 1 minute
else
Set WriteSize = fso.OpenTextFile(MySizeFile,2,True)
MsgBox strFile & vbcr &"Last Size is : " & CLng(LastSize) & " bytes" & vbcr &_
"New Size is : " & objFile.Size & " bytes" & vbcr &_
"Size in Kb : "& CLng(objFile.Size/bytesToKb) & " Kb",VbExclamation,Title
WriteSize.Write objFile.Size
end if
End Sub
'**************************************************************************
'Checks whether a script with the same name as this script is already running
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'**************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'**************************************************************************
Sub Pause(Minutes)
Wscript.Sleep(Minutes*1000*60)
End Sub
'**************************************************************************
Here is another approch that can monitor and check more than one file in changing size :
Option Explicit
const bytesToKb = 1024
Dim Title,strFile,ListFiles
Title = "The File Size Checker by Hackoo 2015"
ListFiles = Array("c:\test.txt","E:\My test dossier\t.txt","E:\My test dossier\TmpLog.txt")
If AppPrevInstance() Then
MsgBox "There is an existing proceeding",VbExclamation,"There is an existing proceeding"
WScript.Quit
Else
Do
Call Main(ListFiles)
Call Pause(1) 'To Sleep for 1 minute
Loop
End If
'******************************************************************
Sub Main(strFilesPaths)
Dim strFile
For Each strFile In strFilesPaths
CheckSize(strFile)
Next
End Sub
'******************************************************************
Function StripPath(Path)
Dim arrStr : arrStr = Split(Path,"\")
StripPath = arrStr(UBound(arrStr))
End Function
'*****************************************************************
Sub CheckSize(File)
Dim ws,fso,objFile,ReadSize,WriteSize,MySizeFile,Temp,LastSize,strFile
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Temp = ws.ExpandEnvironmentStrings("%Temp%")
For Each strFile In ListFiles
MySizeFile = Temp & "\" & StripPath(strFile)
If Not fso.FileExists(MySizeFile) Then
Set WriteSize = fso.OpenTextFile(MySizeFile,2,True)
set objFile = fso.GetFile(strFile)
WriteSize.Write objFile.Size
End If
Set ReadSize = fso.OpenTextFile(MySizeFile,1)
LastSize = ReadSize.readall
set objFile = fso.GetFile(strFile)
If CLng(objFile.Size) = CLng(LastSize) Then
else
Set WriteSize = fso.OpenTextFile(MySizeFile,2,True)
MsgBox strFile & vbcr &"Last Size is : " & CLng(LastSize) & " bytes" & vbcr &_
"New Size is : " & objFile.Size & " bytes" & vbcr &_
"Size in Kb : "& CLng(objFile.Size/bytesToKb) & " Kb",VbExclamation,Title
WriteSize.Write objFile.Size
end if
Next
End Sub
'**************************************************************************
'Checks whether a script with the same name as this script is already running
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'**************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'**************************************************************************
Sub Pause(Minutes)
Wscript.Sleep(Minutes*1000*60)
End Sub
'**************************************************************************

Ping list of servers with VBS

I have the following script which pings a list of servers (txt file with one server per line) and if down, records the info to a csv file. The script works, but I have two issues with the script that I can't figure out:
1) I would like the script to only create a file if one of the servers on the list is down. Currently, if no servers are down, it creates an empty file with a header row. I have temporarily fixed this by writing another script that later deletes the empty files, but it would be best if the file isn't created in the first place.
2) Is there a way to ping two or three times to double/triple check if a server is down, then record that it's down? Currently, the script is logging that sometimes a server is down when I don't think it actually is, maybe my internet connection or computer hangs for a second so the ping fails?
Thanks in advance! I'm just getting into VBS so this is unfamiliar territory for me.
Dim WshShell
Set WshShell = createobject("wscript.shell")
strURL = "www.yahoo.com"
set png = WshShell.exec("ping -n 1 " & strURL)
do until png.status = 1
wscript.sleep 100
loop
strPing = lcase(png.stdout.readall)
Select Case True
Case InStr(strPing, "reply from") > 1
dim strInputPath, strOutputPath, strStatus
dim objFSO, objTextIn, objTextOut
strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
strDateTime = strSafeDate & "-" & strSafeTime
strInputPath = "C:\Users\user\Desktop\PING\serverlist.txt" '- location of input
strOutputPath = "C:\Users\user\Desktop\PING\log\" & strDateTime & ".csv" '- location of output
set objFSO = CreateObject("Scripting.FileSystemObject")
set objTextIn = objFSO.OpenTextFile( strInputPath,1 )
set objTextOut = objFSO.CreateTextFile( strOutputPath )
objTextOut.WriteLine("website,status,date")
Do until objTextIn.AtEndOfStream = True
strComputer = objTextIn.ReadLine
if fPingTest( strComputer ) then
strStatus = "UP"
else
strStatus = "DOWN"
end if
if strStatus = "DOWN" then
objTextOut.WriteLine(strComputer & "," & strStatus & "," & Now)
end if
loop
function fPingTest( strComputer )
dim objShell,objPing
dim strPingOut, flag
set objShell = CreateObject("Wscript.Shell")
set objPing = objShell.Exec("ping " & strComputer)
strPingOut = objPing.StdOut.ReadAll
if instr(LCase(strPingOut), "reply") then
flag = TRUE
else
flag = FALSE
end if
fPingTest = flag
end function
Case Else
End Select
You can try my modification code with a waiting bar if you want :
Option Explicit
Dim strInputPath,strOutputPath,strStatus,strSafeDate,strSafeTime,strDateTime,Titre,MsgTitre,MsgAttente
Dim objFSO,objTextIn,objTextOut,ReadAllFile,Lines,Line,Ws,Command,OpenCSVFile,oExec,Temp,StartTime,DurationTime
Set Ws = CreateObject("WScript.Shell")
Titre = "Ping list of servers"
MsgTitre = Titre
MsgAttente = "Please wait ... the pinging is on progress ...."
Temp = ws.ExpandEnvironmentStrings("%Temp%")
strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
strDateTime = strSafeDate & "-" & strSafeTime
strInputPath = "C:\PingServer\serverlist.txt" '- location of input
strOutputPath = "C:\PingServer\" & strDateTime & ".csv" '- location of output
set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strInputPath) Then
set objTextIn = objFSO.OpenTextFile(strInputPath,1)
else
MsgBox "CRITICAL ERROR " & VbCrLF & "The File "& DblQuote(strInputPath) & " dosen't exists !",VbCritical,"CRITICAL ERROR " & Titre
Wscript.Quit
End if
set objTextOut = objFSO.CreateTextFile(strOutputPath)
objTextOut.WriteLine("website;status;date")
ReadAllFile = objTextIn.ReadAll
Lines = Split(ReadAllFile,vbCrLf)
Call CreateProgressBar(MsgTitre,MsgAttente)'Create the waiting Bar
Call LancerProgressBar()'Lancement de la barre de progression
StartTime = Timer 'Debut du Compteur Timer
For Each Line In Lines
If OnLine(Line) = True Then
strStatus = "UP"
objTextOut.WriteLine(Line & ";" & strStatus & ";" & Now)
else
strStatus = "DOWN"
objTextOut.WriteLine(Line & ";" & strStatus & ";" & Now)
end if
Next
Call FermerProgressBar()'Closing the waiting Bar
DurationTime = FormatNumber(Timer - StartTime, 0) & " seconds." 'La duree de l'execution du script
Command = "cmd /c CD " & DblQuote(ExcelPath()) & " | Start Excel.exe" &" /E "& DblQuote(strOutputPath)
Ws.Popup "The pinging Script is finshed in "& DurationTime,"2",MsgTitre,64
OpenCSVFile = ws.run(Command,0,False)
'************************************************************************************************************************************************************
Function OnLine(strHost)
Dim objPing,z,objRetStatus,PingStatus
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & strHost & "'")
z = 0
Do
z = z + 1
For Each objRetStatus In objPing
If IsNull(objRetStatus.StatusCode) Or objRetStatus.StatusCode <> 0 Then
PingStatus = False
Else
PingStatus = True
End If
Next
Call Pause(1)
If z = 5 Then Exit Do 'here you can incerase or decerase the value of z = 5
Loop until PingStatus = True
If PingStatus = True Then
OnLine = True
Else
OnLine = False
End If
End Function
'*********************************************************************************************
Sub Pause(NSeconds)
Wscript.Sleep(NSeconds*1000)
End Sub
'**********************************************************************************************
Function ExcelPath()
Dim appXL,s
Set appXL = CreateObject("Excel.Application")
ExcelPath = appXL.Path
appXL.Quit
Set appXL = Nothing
End Function
'**********************************************************************************************
'Fonction pour ajouter les doubles quotes dans une variable
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
Sub CreateProgressBar(Titre,MsgAttente)
Dim ws,fso,f,f2,ts,ts2,Ligne,i,fread,LireTout,NbLigneTotal,Temp,PathOutPutHTML,fhta,oExec
Set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Temp = WS.ExpandEnvironmentStrings("%Temp%")
PathOutPutHTML = Temp & "\Barre.hta"
Set fhta = fso.OpenTextFile(PathOutPutHTML,2,True)
fhta.WriteLine "<HTML>"
fhta.WriteLine "<HEAD>"
fhta.WriteLine "<Title> " & Titre & "</Title>"
fhta.WriteLine "<HTA:APPLICATION"
fhta.WriteLine "ICON = ""magnify.exe"" "
fhta.WriteLine "BORDER=""THIN"" "
fhta.WriteLine "INNERBORDER=""NO"" "
fhta.WriteLine "MAXIMIZEBUTTON=""NO"" "
fhta.WriteLine "MINIMIZEBUTTON=""NO"" "
fhta.WriteLine "SCROLL=""NO"" "
fhta.WriteLine "SYSMENU=""NO"" "
fhta.WriteLine "SELECTION=""NO"" "
fhta.WriteLine "SINGLEINSTANCE=""YES"">"
fhta.WriteLine "</HEAD>"
fhta.WriteLine "<BODY text=""white""><CENTER>"
fhta.WriteLine "<marquee DIRECTION=""LEFT"" SCROLLAMOUNT=""3"" BEHAVIOR=ALTERNATE><font face=""Comic sans MS"">" & MsgAttente &"</font></marquee>"
fhta.WriteLine "<br><img src=""data:image/gif;base64,R0lGODlhgAAPAPIAAP////INPvvI0/q1xPVLb/INPgAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAgAAPAAAD5wiyC/6sPRfFpPGqfKv2HTeBowiZGLORq1lJqfuW7Gud9YzLud3zQNVOGCO2jDZaEHZk+nRFJ7R5i1apSuQ0OZT+nleuNetdhrfob1kLXrvPariZLGfPuz66Hr8f8/9+gVh4YoOChYhpd4eKdgwDkJEDE5KRlJWTD5iZDpuXlZ+SoZaamKOQp5wAm56loK6isKSdprKotqqttK+7sb2zq6y8wcO6xL7HwMbLtb+3zrnNycKp1bjW0NjT0cXSzMLK3uLd5Mjf5uPo5eDa5+Hrz9vt6e/qosO/GvjJ+sj5F/sC+uMHcCCoBAAh+QQJCgAAACwAAAAAgAAPAAAD/wi0C/4ixgeloM5erDHonOWBFFlJoxiiTFtqWwa/Jhx/86nKdc7vuJ6mxaABbUaUTvljBo++pxO5nFQFxMY1aW12pV+q9yYGk6NlW5bAPQuh7yl6Hg/TLeu2fssf7/19Zn9meYFpd3J1bnCM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GqfKv2HTeBowiZGLORq1lJqfuW7Gud9YzLud3zQNVOGCO2jDZaEHZk+nRFJ7R5i1apSuQ0OZT+nleuNetdhrfob1kLXrvPariZLGfPuz66Hr8f8/9+gVh4YoOChYhpd4eKdgwFkJEFE5KRlJWTD5iZDpuXlZ+SoZaamKOQp5wAm56loK6isKSdprKotqqttK+7sb2zq6y8wcO6xL7HwMbLtb+3zrnNycKp1bjW0NjT0cXSzMLK3uLd5Mjf5uPo5eDa5+Hrz9vt6e/qosO/GvjJ+sj5F/sC+uMHcCCoBAA7AAAAAAAAAAAA"" />"
fhta.WriteLine "</CENTER></BODY></HTML>"
fhta.WriteLine "<SCRIPT LANGUAGE=""VBScript""> "
fhta.WriteLine "Set ws = CreateObject(""wscript.Shell"")"
fhta.WriteLine "Temp = WS.ExpandEnvironmentStrings(""%Temp%"")"
fhta.WriteLine "Sub window_onload()"
fhta.WriteLine " CenterWindow 350,100"
fhta.WriteLine " Self.document.bgColor = ""DarkOrange"" "
fhta.WriteLine " End Sub"
fhta.WriteLine " Sub CenterWindow(x,y)"
fhta.WriteLine " Dim iLeft,itop"
fhta.WriteLine " window.resizeTo x,y"
fhta.WriteLine " iLeft = window.screen.availWidth/2 - x/2"
fhta.WriteLine " itop = window.screen.availHeight/2 - y/2"
fhta.WriteLine " window.moveTo ileft,itop"
fhta.WriteLine "End Sub"
fhta.WriteLine "</script>"
fhta.close
End Sub
'**********************************************************************************************
Sub LancerProgressBar()
Set oExec = Ws.Exec("mshta.exe " & Temp & "\Barre.hta")
End Sub
'**********************************************************************************************
Sub FermerProgressBar()
oExec.Terminate
End Sub
'**********************************************************************************************
You're empty file is being created because the header details are being written without verifying the file actually needs to be created. This occurs prior to verifying whether any target servers are down.
Trying modifying your code as follows:
Verify server availability first;
Populate an array with details of servers that aren't available;
Check whether the array has any items:
If yes, create the file with header and server details;
If no, cleanup and exit script;
You might also consider placing the timestamp at the start of the row as occurs in most logs.
HTH
Cheers
Rob

Resources