was hoping their might be a way to visualize progress of the deletion of several files, I have an application that runs a cleanup when it's done, the directory it deletes is almost 3GB, so it would be nice to have a progress bar popup similar to the one that shows if you use the
Const FOF_CREATEPROGRESSDLG = &H0&
strTargetFolder = "C:\OfficeTemp"
Set oShell = CreateObject("Shell.Application")
Set objFolder = oShell.NameSpace(strTargetFolder)
objFolder.CopyHere "OfficeTemp\*.*", FOF_CREATEPROGRESSDLG
supposedly you can implement this with SHFileOperation, but I only see examples for using this in C++, anyone ever done this with VBScript?
C++ Win32 API Delete file with progress bar
My advise is don't do it if you want to keep yout script agile.
It's not the size in GB that takes long to delete, so for a couple of large files it's not suitable since before you get up your gui up and running and display some progress your filedelition allready could be done. You culd just show the filename as it is being deleted.
If it are many many small files that take longer the progress bar would be more suitable, only you need to do it in IE or another browser that you can script to and the result will never be very reliable nor beautifull. I've seen ActiveX objects that give such progress bar but even when you could use these you have problems. You need to know in advance how many files there are to be deleted and the divide the process in small steps and show the progress as a percentage of the total.
This alone could take as long as the deletion itself, vbscript is very slow in handling files.
Showing the files here would certainly slow down the process, you could show something like
1000 files deleted..
2000 files deleted..
so that the user knows there is something happening.
The fastest way do delete the map is by shelling out en let de OS take care of it, then wait for the process to end and resume the script from there.
For some of these aproaches i have samples, sorry that i can't give you and easy allproblemssolved answer.
For people on the look for a progressbar while copying, i found this in meanwhile, tested and working on Win7
Const FOF_CREATEPROGRESSDLG = &H0&
strTargetFolder = "D:\Scripts"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strTargetFolder)
objFolder.CopyHere "C:\Scripts\*.*", FOF_CREATEPROGRESSDLG
Related
Sorry if this seems like a dumb question but im curious to see if this would work?
So my plan was to create a .vbs script to send keys to go to a website, but my plan was to have a blank black screen over top of it so you couldnt see the process. Obviously it would not be hard to make the full black screen (it would be done in a different language, most likely an exe file) but then I completely forgot... would it even be possible? I tested it out with other full screen programs and obviously it sent the "sendkeys" command to the program that was in front.
Still confused? Here is an example
Set WshShell = CreateObject("WScript.shell") for i = 0 to 50 WshShell.SendKeys(chr(175)) next Process.Start("CMD", "/C start chrome.exe http://www.bing.com")
WScript.Sleep 2000
WshShell.SendKeys "this is an example of text being put into the search bar"
So my question is, would it be possible to have a fullscreen application open while this command runs in the background? it could be any fullscreen application, just anything to "hide" or cover this process.
Or would it even be possible to create a fullscreen program specifically to cover this?
Thank you for reading!
I'm using a code from this link to display a splash screen during start up of my short bat file that copies some files from the server and takes 15-20 seconds, to prevent multiple clicks by impatient users. I get a type mismatch VBScript error report, line 1, char 1, code 0. The splash window loads normally, but when it should close the error appears and the splash stays on the screen (though the rest of the bat goes on normally).
This is the vbscript code
<script language="VBScript">
Sub Window_OnLoad
' Resize and position the window
width = 500 : height = 400
window.resizeTo width, height
window.moveTo screen.availWidth\2 - width\2, screen.availHeight\2 - height\2
' Automatically close the windows after 5 seconds
idTimer = window.setTimeout("vbscript:window.close", 15000)
End Sub
</script>
I think this line
idTimer = window.setTimeout("vbscript:window.close", 15000)
causes the error.
This only happens on some computers and I haven't really found the common thing with them, they're running either Windows 7 or 8. I found it could do something with Internet Explorer updates, just not sure it applies here as there are no arrays used (AFAIK).
One of the answers on this site suggests setting Set in front of idtimer. -not working for me
I can confirm that a simple test HTA file containing your example code works fine on Win7 x64.
Since your type mismatch refers specifically to "vbscript" I'm led to believe that the vbscript: part of your timeout call is the issue. The word vbscript is being interpreted literally with the colon separating the next statement. Maybe some VBScript runtimes don't have a variable called vbscript at the global level.
When I changed the string to be simply "window.close" it worked just fine as well. Give it a try and see if that helps. Additionally, when I change the call to be something blatantly wrong, like "abc:window.close" then I get the Type Mismatch error you described.
I believe doing a vbscript: or javascript: prefix is only necessary in HTML anchor HREF attributes and the like (although many browsers gracefully allow it anyway for backwards compatibility).
You can check the link below - might provide some insight.
http://www.vbforums.com/showthread.php?342508-How-to-window-close-Resolved
I'm new to programming and as a first exercise I wanted to write a program that would mute the volume when the taskbar displays an element with a certain name.
Full disclosure, this is to mute out the ads on Spotify when they come on. I noticed the name of the tab changes to "Spotify - Spotify". When this happens, I'd like the program to mute the volume until the name changes again. Granted I could simply pay the (quite low) monthly subscription, I really wouldn't learn anything from a programming standpoint.
Can anyone point me in the right direction to get started on this?
I've already found this on SO but not exactly what I'm looking for (I think): How to control Windows system volume using JScript or VBScript?
Thanks all.
If you are ok with muting everything you could try to get all the tasks via the word object (i know...) as described here:
Set objWord = CreateObject("Word.Application")
Set colTasks = objWord.Tasks
For Each objTask in colTasks
If objTask.Visible Then
Wscript.Echo objTask.Name
End If
Next
objWord.Quit
You could put the inner for in a loop and check objTask.Name for "Spotify - Spotify" every second and sleep in between. If you find it you can use the sendkeys solution from the post you already found
var oShell = new ActiveXObject("WScript.Shell");
oShell.SendKeys(String.fromCharCode(0xAD));
to mute the whole system.
We just got a new win 7 64 computer and one very old program does not display properly on launch - it doesn't draw itself completely until I change the size of its window. I'd like to write a small script program that launches the old program, then changes its size (for example, minimize then restore or maximize then restore its window) or otherwise forces the program to redraw itself.
That way a user could click on the program icon and it would flicker a moment and display properly.
I tried:
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""c:\Program Files (x86)\VideoLan\VLC\vlc.exe""")
objShell.SendKeys "% x"
objShell.SendKeys "% r"
Set objShell = Nothing
Based on How can I maximize, restore, or minimize a window with a vb script? That worked to launch vlc (test program, not the problem program), but did not change its size.
EDIT: adding a slight delay after run (wscript.sleep(200)) fixed the problem. I'd still like to know if there's a better way.
Not sure if this will work, but you could give it a try:
CreateObject("Shell.Application").Namespace(0).Self.InvokeVerb "R&efresh"
The above invokes a "Refresh" of the desktop, which may or may not update your application window as well.
I would like to open my video using VBS and So far I have this and it works fine
Set wmp = CreateObject("WMPlayer.OCX")
wmp.openPlayer("C:\Users\myvideo.mp4")
I would also like to add one more line to make it full screen. How would one do that?
Also, my second question is probably more useful.
Is there a collective website to describe how to manipulate these objects?
When I played around with Matlab, I can at least press tab and see what can options are available under that object and I learned a lot that way (the website was also very helpful).
Is there a comparable way in VBS or for example, where can I find a extensive lists of command I could send to WM Player?
Thanks!
For switching the window to a full screen window you have to use Alt+Enter. This can be done using sendKeys method of the Shell object. Here's the code:
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 1000
WshShell.SendKeys "%{ENTER}"
Hope this suits you need. For further help check the documentation for SendKeys.