Strange action with scripts opening/pasting image files

Started by Garry, September 12, 2023, 06:45:34 AM

Previous topic - Next topic


I'm having some strange actions with scripts opening/pasting image files.

The winbatch script basically runs paint with a selected file and uses sekeys to automatically paste another image onto the existing image.

The first time the script runs there is a few second delay before the image is pasted.
The second time it has no delay and pastes immediately. Then it will paste it with no delay for subsequent runs.

As soon as a different  file is selected to paste the image to it has the delay the first time but not in subsequent runs.

It's driving me nuts. I can preform the same functions manually once the image is up and there's no delay pasting an image on top but the script using the sekeys to do it causes the delay for the first run.

Anyone had this problem?

I've made sure the paths for the image files are set properly and there's no delay with the script bringing up the original image to be pasted to.

I'm extremely confused. I tried putting extra time delays between the sekey sends but it makes no difference, it just adds more delay.
Of course I have to use a bit of delay after the sekey line where the image filename is sent to be opened to paste so the name has time to be sent.

Strange part is there is no delay the second time the script is run until a different original image is chosen. Then there is a delay in the first run again.


This is just a guess and you didn't indicate which version of Windows you are using but there are several bugs in the Windows 10/11 graphic shell that can cause random delays when accessing files.  Windows Defender can also cause strange delays when an application first starts accessing files. These Windows bugs have been widely reported but never addressed by MSFT.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade



I know this pain. Timing sendkeys feels like an invisible crazy monkey is screwing with you.  You try to code around it, add padding and conditions, but the problems just move around.  Infuriating.

I don't know anything about your specific situation (automating paint), but if it were me, I'd look into moving as many program functions as possible away from the automate-3rd-program-via-keystrokes method.  Even when I have had partial success, the pain just doesn't stop.

So, over the years, I've learned to look pretty hard for more direct ways to solve the problem. 
It's not less trouble, just less insanity inducing.

Have you looked into using ImageMagick?
I've had good success with executing command lines to do what I need.

Also, other folks have used ImageMagick via OLE!!~ImageMagickObject~COM~Object~~!!.txt

Good luck!!

just my $0.02
The mind is everything; What you think, you become.


Don't know if you it will do what you need but the Omnibus Extender will overlay images.  Look for the imOverlay() function under the Images section.



I'm using windows 10 64 bit. I use ESET  for security and windows defender is not running.

I have similar problems with opening the first couple of file in Piximillion Image converter which I use a winbatch script using sendkeys to convert a list of PCX files into one PDF file.

It looks like it's not opening any files but after 3 or more files they all show up at one time, so some strange thing is causing a delay.

From the replies so far I'm thinking it may be a MS bug

(I mentioned sekeys in my initial post which is an Autocad key mapping program, I meant to say sendkeys)

The MSpaint program isn't just being used for automated pasting in the script. The script has 8 different functions all of which work very fast with no problems such as cropping, auto resizing  or adding various labels. First it puts up an "Always on top" Winbatch box with 8 buttons for doing various things. It also saves the file with a Finished button or exits with no save with an Exit button so there's really no other software small and fast enough for doing all the things I want. Gimp is much too slow and clumsy but a great editor for more complex editing.

It's just the first time I paste an image that's delayed. If I paste it first time manually it's immediate. I can paste the same image or other images using the script buttons after and they go in immediately. All the other script functions execute immediately first time or subsequent times. It's more of an annoyance than a problem but I'd like to find out what's causing it so I can make it work better.


None of this rambling will likely help at all so consider what follows little more than the rants of a grumpy tech guy.

MSPaint along with many other utilities is now a "managed" application. In some cases, initial slow application response and other issues can be attributed to starting "managed" applications using Windows "native" APIs.  Many of MSFT's utilities have a stub native program whose sole purpose is the start the "managed" application. At some point starting the "managed" application directly instead of using the stub when using Windows native APIs could correct these issues.   However, now it appears that starting the "managed" application directly will not work at all.

For what it's worth "managed" applications are in the maze of folders under "C:\Program Files\WindowsApps" assuming "C:" is your system drive of course. For example, Notepad.exe is in the "C:\Program Files\WindowsApps\Microsoft.WindowsNotepad_11.2306.15.0_x64__8wekyb3d8bbwe\Notepad" on my system. Keep in mind that the "managed" version sometimes has a different file name than the "native" stub. Also, strange Windows application behaviors are almost impossible to predict from Windows update to Windows update.

For better and often worse Windows ain't what it used to be.

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade


Thanks for the replies:

I am seeing several differences between the win7 OS and win10 OS on the same dual boot system.

Win7 seems very precise and immediate. Windows 10 seems slow compared on the same system with the same peripherals.

I can not delete a file in a shell in windows 10 in a specific directory except when using the command black box.

I checked the security and sharing on the directory and it seems ok but not when using a script of any kind.

Deleting files in the black box cmd god works when I copy and paste the same line from a script but not when the script runs.



Cannot speak to your specific problem but the Windows command prompt defaults to running as a restricted admin whereas WinBatch defaults to executing as an elevated admin. This can have counterintuitive effects because mapped drives and shares are sometimes (perhaps often) inadvertently configured so that restricted admins have access while elevated admins do not. This problem is compounded by the fact that  UAC is handled differently on Windows 10/11 than on Windows 7.

Here is a link to a discussion of mapped drives:

Shared folders are a little trickier to explain but the solution is to create a user group and add users that need to write to or read from the share.

Again I have no idea if any of the above applies to your situation but generally, WinBatch file functions work more or less the same on Windows 10/11 as they do on Windows 7 excluding the previously mentioned Windows performance issues.

On the positive side, the next Windows 11 feature release appears to have several fixes for long-standing file system and File Explorer performance issues.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade


Also, need to mention that there was a bug in several feature versions of Windows 10/11 that caused file copies to fail on some files and not on others when using the Windows Win32 API functions to perform the copy like WinBatch does. However, this problem was corrected by Microsoft in one of the more recent Windows "Feature" releases.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade


I was mistaken about the not being able to delete files problem. I was trying to delete them the wrong way.

I was using a dos emulation program called DOSBOX and forgot that when in DOSBOX the directory structure is different. For instance it's not C:\dos\fax it's c:\fax as far as DOSBOX is concerned. It could be different depending on how you set up DOSBOX but for my mounting/setup the c:\DOS folder is basically the same as c:\ when in DOSBOX.

So I could delete files from c:\dos\fax when out of Dosbox but not when in Dosbox as I needed to delete them from c:\fax

Speaking of DosBox I was told it wouldn't work in windows 10 but the latest release works fine in Win10 64 bit.


It is something I experience way too often; being frustrated by a problem only to discover the solution right in front of my eyeballs. My ever-patient wife calls it "refrigerator blindness" for reasons I likely do not need to elaborate upon.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade


I think I understand now.
The windows "app" or whatever it is likes only certain types of files otherwise it has to convert the files to it's own "format".
So what I did is simply re-save the image files using the windows "ms paint" and it loads the files much faster.
I think what happened is that I used Gimp to alter the image files for "better colors etc" and then they wouldn't load as quickly as usual.
Then I opened them and re-saved them in Ms Paint and now they load faster.
So I would guess that MS paint has it's own "format" it likes to use.
I would suggest if one uses Gimp or other such software to redo the image one should once again using Ms paint to put it in ms favorite "format" before calling them from a script.

PS. Had great luck with Nconvert.exe today. I figured out how to get rid of any directories/filenames with spaces and now it works flawless with any choice of directory/file. It's not complicated.

I can upload the script for the Nconvert if anyone is interested.