Force screen redraw - vbscript

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.

Related

Possible for VBS to sendkeys while a full screen application is above it?

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!

Controling volume based on the name of a tab in the taskbar

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.

vbs start application(hh.exe) with specific window size

I want to start an application (hh.exe) (Windows Help) in VBScript but I want to give that app a specific window size anb possibly a position where to open
to start the app I use this code :
Set hh = CreateObject( "WScript.Shell" )
hh.Run("hh.exe -800 C:\Users\me\Desktop\HELP_I_CREATED.CHM")
This works but I can't find a way to give that application a size. If anybody has an idea it would be very apreciated.
Thank you
Here is the spec for this function:
http://msdn.microsoft.com/en-us/library/d5fk67ky(v=vs.84).aspx
You can see from the list of options that there is no way to specify a specific window size other than "minimized", "maximized", "original", "most recent".

How to use VBS to program 1) windows media player? 2) your computer in general?

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.

vbscript delete folder containing multiple files with progress bar

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

Resources