hiding progress window during file transfer - vb6

I have some older visual basic programs I wrote that run every hour to transfer files between folders.
The VB programs work fine (compiled into EXE) on my new laptop with Windows 8. But occasionally when the copy operation of a file is delayed or lags in Windows, the mini progress window appears in the foreground (preparing to copy, x% complete).
This is annoying while I'm trying to work on my laptop.
On this thread, you can see a screenshot of what this progress windows looks like (similar not exact)
Is there an API for the Windows 8 progress dialog API?
To copy files, I'm using
FileCopy oldfile, newfile
I also can use
bSuccess = ShellFileCopy(oldfile, newfile)
Is there any attribute I can set with either of these commands, to disable or minimize the progress mini window during file transfers?
Alternately, is there another command or shell extension I can try, that does allow me to disable or minimize the progress mini window during file transfers?

Here are two additional ways you can try:
With CreateObject("Scripting.FileSystemObject")
.CopyFile oldFile, newFile, True ' (True overwrites, if it exists)
End With
Or (use the command-line copy):
With CreateObject("WScript.Shell")
.Run "%comspec% /c copy """ & oldFile & """ """ & newFile & """", 0, True
End With

Related

(VB.NET) Is There a Way to "lock" a Windows Folder and its Contents?

I want to have my VB.NET program secure folder(s) which all contain a handful of different files so the files within cannot be edited unless the program "unlocks" the folder in Windows. Is this possible? I do not want the folder/files hidden just essentially in some Read-Only state or something or fake out windows into thinking they are already open. The goal is if someone opens the files without the program "unlocking" them, they cannot edit/save changes.
Maybe this article can be useful for you:
How to password protect a folder in Windows 10
The best solution to achieve this functionality is to create a Kernel Minifilter file system driver that prevents other apps from writing or even reading files specified by your program, however, driver development needs extensive knowledge of the system Kernel.
Filter Manager Concepts
https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/filter-manager-concepts
Processing I/O Operations
https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/processing-i-o-operations
Communication Between User Mode and Kernel Mode
https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/communication-between-user-mode-and-kernel-mode
Writing Preoperation Callback Routines
https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/writing-preoperation-callback-routines
Completing an I/O Operation in a Preoperation Callback Routine
https://learn.microsoft.com/en-us/windows-hardware/drivers/ifs/completing-an-i-o-operation-in-a-preoperation-callback-routine
To my surprise just making the file/folder have the Read Only attribute solves my problem exactly how I wanted. Sample code to make a file or folder Read Only is below:
Dim LockFolder As New ProcessStartInfo("cmd", "/c ATTRIB +R " + """" + Application.StartupPath() + "\" + SelectedNodeText + """\* /S /D") _
With {.WindowStyle = ProcessWindowStyle.Hidden, .Verb = "runas"}
Process.Start(LockFolder)
'===== FILE LOCK:
Dim LockFile As New ProcessStartInfo("cmd", "/c ATTRIB +R " + """" + Application.StartupPath() + "\" + SelectedNodeText + """") _
With {.WindowStyle = ProcessWindowStyle.Hidden, .Verb = "runas"}
Process.Start(LockFile)
Application.StartupPath is the first half of my path and the SelectedNodeText is the actual file name which complete the CMD command. The rest is just to make the command run as Admin and not have a popup command window.

Run batch file in background

I've got a batch file that I want to run in the background whenever the system (Windows 2007) is turned on. The batch file monitors the task list for a given program, and when it sees that it's shut down, prompts the user to de-licence it.
I'm currently trying to do this without converting the batch file into either an executable or Windows service file.
I've found more online references than I can count which tell me that I should use "start /b file.bat" to run the batch file in the background, but this doesn't work for me, it just starts up the batch file in the same cmd line window that I'm using.
Can anyone suggest either what's going wrong, or even better; a nice simple way for me to get the batch file to run ion start up (I cannot use a GUI as I have to roll this out to several computers remotely)
Thanks
You could make a shortcut to your batch file and place the shortcut in your Startup Programs directory:
C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Since you have to roll this out to several computers remotely, you should be able to copy the batch file to the startup programs directory over the network assuming the remote machines have WinRM enabled and your account has adequate permissions.
If you want this batch file to run in the background at start up, you could reference your batch file from a VBScript (instead of using the batch file's short cut) and set the VBscript to run in invisible mode:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\path\to\your\batchfile.bat" & Chr(34), 0
Set WshShell = Nothing
Just give this vbscript file the .vbs extension.
If the program you are concerned about is a GUI program (ie non console) just wait for it to exit. Batch waits for GUI programs to exit (but not when started interactively).
notepad
echo My notepad exited
Start /b says to start program in same window. See Start /?. Also Start is usually the wrong command to be using. It starts programs in abnormal ways. See end of http://stackoverflow.com/questions/41030190/command-to-run-a-bat-file/41049135#41049135 for how to start programs.
This is a VBS file.
This monitors for notepad exiting, pops up a messagebox, and restarts notepad.
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set objEvents = objWMIService.ExecNotificationQuery("SELECT * FROM Win32_ProcessStopTrace")
Do
Set objReceivedEvent = objEvents.NextEvent
msgbox objReceivedEvent.ProcessName
If lcase(objReceivedEvent.ProcessName) = lcase("Notepad.exe") then
Msgbox "Process exited with exit code " & objReceivedEvent.ExitStatus
WshShell.Run "c:\Windows\notepad.exe", 1, false
End If
Loop
This should use less battery power and CPU cycles. Batch files are read line by line so make VERY poor background tasks.
If the program you are concerned about is a GUI program (ie non console) just wait for it to exit. Batch waits for GUI programs to exit (but not when started interactively).
notepad
echo My notepad exited

Command to find Active Drive

I am trying to build a VBScript to automatically run some .exe files. The problem is that the script and the .exe files are on a flashdrive, so it needs to find the current drive letter by itself. I can do it on a batch file using %~d0, but I like some of the functions of VBScript better, especially the ability to send keystrokes. Anyways, I found a whole list of VBScript commands, but I am no expert and I need help with the syntax. So far I have it set to open the task manager and press some keys to have it select the "performance tab" of the task manager:
Dim Act :Set Act = CreateObject("Wscript.Shell")
Act.Run("taskmgr.exe")
Success = Act.AppActivate("taskmgr")
Wscript.Sleep 250
Act.SendKeys "{TAB 5}" :WScript.Sleep 500
Act.SendKeys "{RIGHT 3}" :WScript.Sleep 500
I'd like to know what command I need to use to tell the script to use the drive letter where the script was executed from (USB drive).
Use the .ScriptFullName property to get the full file spec of the running script and apply .GetParentFolderName for the folder's path or .GetDriveName for just the drive letter.
>> Set oFS = CreateObject("Scripting.FileSystemObject")
>> s = WScript.ScriptFullName
>> WScript.Echo oFS.GetParentFolderName(s), oFS.GetDriveName(s)
>>
M:\bin M:
cf. here

When I use a VBS script to change my wallpaper, I have to log off for changes to take effect

When I use a VBS script to change my wallpaper, I have to log off for changes to take effect. How can I make it so I don't have to log off once I run my script?
I am running Windows 7 and am running code which will take a given path file, such as a.jpg or a.bmp, and replace the file at the location:
C:\Users\Brad\AppData\Roaming\Microsoft\Windows\Themes\TranscodedWallpaper.jpg
I have listed the code for a VBS file that I found and it is supposed to refresh my active desktop. It flashes like the script works, however it does not update my wallpaper:
' Create explorer command file to toggle desktop window
Set oFSO = CreateObject("Scripting.FileSystemObject")
sSCFFile= oFSO.BuildPath(oFSO.GetSpecialFolder(2), oFSO.GetTempName &".scf")
With oFSO.CreateTextFile(sSCFFile, True)
.WriteLine("[Shell]")
.WriteLine("Command=2")
.WriteLine("[Taskbar]")
.WriteLine("Command=ToggleDesktop")
.Close
End With
' Toggle desktop and send F5 (refresh)
With CreateObject("WScript.Shell")
.Run """" & sSCFFile & """"
WScript.Sleep 100
.Sendkeys "{F5}"
End With
' Delete explorer command file
oFSO.DeleteFile sSCFFile
The settings are stored in memory. Changing the registry key changes nothing.
The way programs do it is to use SystemParametersInfo
SystemParametersInfo
Retrieves or sets the value of one of the system-wide parameters. This function can also update the user profile while setting a parameter.
BOOL SystemParametersInfo(
UINT uiAction,
UINT uiParam,
PVOID pvParam,
UINT fWinIni
);
SPI_SETDESKWALLPAPER
Sets the desktop wallpaper. The value of the pvParam parameter determines the new wallpaper. To specify a wallpaper bitmap, set pvParam to point to a null-terminated string containing the name of a bitmap file. Setting pvParam to "" removes the wallpaper. Setting pvParam to SETWALLPAPER_DEFAULT or NULL reverts to the default wallpaper.
VB.Net is installed all computers. Use that instead.
I did a little searching and found a block of code for a .bat file that looks like this:
> #echo off
> taskkill /f /IM explorer.exe
> Start explorer.exe
> #pause
That resolves my issue since the background is loaded when explorer.exe starts up.

Executable running in background

I am trying to run a simple batch script via Jenkins (which in turn calls a VBscript). The script which i am executing in Jenkins is:
cd "C:\Product\workspace"
cscript Test.vbs
The test.vbs is simple code which calls an exe in console mode
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /K C:\Product\workspace\Product.exe -c -dir C:\ProductDir", 1
Set objShell = Nothing
The parameter 1 : Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position.
The problem which I am facing is I am not able to see the cmd.exe and the Product.exe installer. Though the process explorer shows cmd.exe and Product.exe running. I don't get why I its not running in foreground and only in background.
How can I get the exe to run in foreground?
When I tried running directly on VM, I can see it running in foreground. Cant understand this situation. Any light on this?
Thanks.
Are you running Jenkins slave agent as headless service on windows? I remember in this case the GUI would have problem. You should run the agent with jnlp when you add the slave VM. This works perfect with me.
Here's another way to skin the cat using VBScript.
I experienced the same issue trying schedule a task to launch Internet Explorer into the foreground. I was using WScript's Run method with the 3 window option to force it to be maximized. I just couldn't force it to come up in the foreground.
I FINALLY got that to work with WScript's AppActivate method. The trick was to monitor AppActivate's return value in a loop to ensure the application is fully launched with the correct TITLE before using AppActivate to bring it to the foreground.
AppActivate Method
Here's my example script:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "iexplore.exe https://www.google.com", 3, false
WScript.Sleep 2000
While WshShell.AppActivate("Internet Explorer") = FALSE
WScript.Sleep 1000
Wend
WshShell.AppActivate "Internet Explorer"
WScript.Quit
=========================
Note: AppActivate will choose the closest match for the application TITLE (or process ID, which is not as simple). You don't have to have the complete TITLE. I'm showing "Internet Explorer" here, but I was able to use the TITLE of the web site that I was redirecting to ("Google" would work OK in this example). So, if you don't want to pull up any random instance of an application you may already have open, be as specific as possible. A CMD.EXE TITLE wouldn't be your best bet.
AppActivate works especially well for CMD/COMMAND windows, as (mentioned previously) you can use the TITLE batch file command to specify a unique window title.
I think im late but I did this and it worked:
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /K C:\Product\workspace\Product.exe -c -dir C:\ProductDir", 0, False Rem 0: run in background, False: exit without waiting process to stop, True to wait for process
Set objShell = Nothing
You can use the .visible property in order to display the applications that are running and bring them to the foreground e.g. objShell.Visible = True
Example below of how I used it when launching an application:
Dim objQtpApp
Set objQtpApp = CreateObject("QuickTest.Application")
'make QTP visible
objQtpApp.Visible = True

Resources