Bat Files

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Bat Files

06 Oct 2023, 16:18

Good Day. Have spent hours on this and it should be simple. Just want my Numpadup key to run a bat file.I have to click the bat file itself twice for it to work and I am fine with that if I could just figure out how when I press numpadup for bat to click itself twice.I am not a programmer but this shouldn't be that hard. Open bat Send click twice. Running as admin does not help.Any ideas out there? Tk's

Code: Select all

NumpadUp::
Run, D:\Batch Fles\File Explorer Restart.bat
Return
sofista
Posts: 654
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Bat Files

06 Oct 2023, 17:41

Perhaps it is only a syntax issue, because the Run command requires that paths that contain spaces should be quoted.
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Bat Files

06 Oct 2023, 17:57

No luck. Quotes didn't help. Is there no way to have ahk send click twice or run twice to open the bat file? When I click twice on the bat file everything works like a charm. Something like this?

Code: Select all

NumpadUp::
Send, {Click 2},"D:\Batch Fles\File Explorer Restart.bat"
Return
TAC109
Posts: 1129
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Bat Files

06 Oct 2023, 18:05

Try:

Code: Select all

NumpadUp::
Run %comspec% /c "D:\Batch Fles\File Explorer Restart.bat"
Return
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Bat Files

06 Oct 2023, 18:13

@TAC109. Sorry Tac. Tried this before. All that happens when I run this is a white screen with the explorer window on top. If there was just awy to make ahk click twice to open bat file. Then problem solved. Tk's for trying thou.
User avatar
andymbody
Posts: 993
Joined: 02 Jul 2017, 23:47

Re: Bat Files

06 Oct 2023, 21:33

jrachr wrote:
06 Oct 2023, 18:13
All that happens when I run this is a white screen with the explorer window on top.
What is suppose to happen? IOW... what happens when you double-click the file manually? Can we look at the batch file? It sounds like it ran, just not giving you the expected results?

Just a thought... What happens if you run as admin? Does the double-click open the file as admin by default maybe?

Code: Select all

NumpadUp::
Run *RunAs %comspec% /c "D:\Batch Fles\File Explorer Restart.bat"
Return
If there was just awy to make ahk click twice to open bat file
There is, but it would have to know the position of the batch file on screen to move the mouse to it and double-click
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Bat Files

06 Oct 2023, 22:16

@andymoody. This is the bat file.When it runs it closes the explore taskbar and then restarts everything just fine.

Code: Select all

taskkill /f /im explorer.exe
start explorer.exe
exit
When you run it as an ahk file everything closes but when it restarts there is no taskbar.Just the explorer window.

Code: Select all

Run, taskkill /f /im explorer.exe
Sleep 5000
Run, explorer.exe
exit
When I run , Run *RunAs %comspec% /c "D:\Batch Fles\File Explorer Restart.bat", It suts everything down but when it restart's there is a full screen of white with the explorer window on top.


If I need to I already know how to use mousemove and how to get position.,etc.
Tk's for any help.
User avatar
andymbody
Posts: 993
Joined: 02 Jul 2017, 23:47

Re: Bat Files

06 Oct 2023, 22:26

jrachr wrote:
06 Oct 2023, 22:16
a full screen of white with the explorer window on top.
I'm curious now... can you post a screenshot of this
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Bat Files

06 Oct 2023, 22:43

@andymoody. Best I can do.Not really good at this stuff. But when I run that code you sent this is the outcome.
Attachments
20231007_003553.jpg
20231007_003553.jpg (1017.73 KiB) Viewed 1575 times
Last edited by jrachr on 06 Oct 2023, 23:19, edited 3 times in total.
User avatar
andymbody
Posts: 993
Joined: 02 Jul 2017, 23:47

Re: Bat Files

06 Oct 2023, 23:06

You can delete 2 of those images (edit the post)

Do you have any idea what the white screen is? Is it a window? Can it be closed once it appears? Or does the computer require a reboot at this point? Is it possibly the command line window that the background has been changed to white somehow (white font on white background)? I have seen that when Run executes the command line, the attributes can be different than the normal command line window. But those settings can be set back to default so it looks normal.

Confirm whether that white screen is the command line window or not.
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Bat Files

06 Oct 2023, 23:18

No idea what it is. Will play with it tomorrow. Will delete images as soon ad I figure out how to do it. Tk's
User avatar
andymbody
Posts: 993
Joined: 02 Jul 2017, 23:47

Re: Bat Files

06 Oct 2023, 23:22

jrachr wrote:
06 Oct 2023, 23:18
No idea what it is.
Google says White Screen of Death (as opposed to the old blue)... you may want to investigate further
User avatar
andymbody
Posts: 993
Joined: 02 Jul 2017, 23:47

Re: Bat Files

06 Oct 2023, 23:39

Have a look at this thread...

viewtopic.php?f=76&t=77404#p336311
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Bat Files

06 Oct 2023, 23:47

This is starting to become to much of a headache. It shouldn't have been this difficult to open a simple bat file via ahk. Click twice open file. Anyways I will leave it go. Tk's for all your help.

@andymoody.the white screen I doubt is the command window as the command window is only about the size of the explorer window.

Cheer's
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Bat Files

06 Oct 2023, 23:49

@andymoody. I will check li k out tomorrow. Thanks.
User avatar
andymbody
Posts: 993
Joined: 02 Jul 2017, 23:47

Re: Bat Files

06 Oct 2023, 23:52

jrachr wrote:
06 Oct 2023, 23:47
the white screen I doubt is the command window as the command window is only about the size of the explorer window.
I agree, seems to be WSOD.

There should be a way to do what you want, but I agree, it doesn't seem to be as straight forward as expected.
jrachr
Posts: 545
Joined: 01 Mar 2021, 17:33

Re: Bat Files

09 Oct 2023, 07:16

For anyone interested out there. I found an easy way to fix my issue by simply converting it to an exe which ahk runs just fine. There a bat to exe converter online which I downloaded and it converts just fine.Hopefully somewhere down the road ahk will be able to run bat files but for the meantime this work's. Cheer's

Code: Select all

NumpadUp::                                                                                          ;Numpad8    
Run, "C:\Users\Jr\Desktop\File Explorer Restart.exe"    
Return
off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Bat Files

09 Oct 2023, 21:36

Just using this scripts also works:

Code: Select all

run, %ComSpec% /c "taskkill /f /im explorer.exe"
sleep, 500
run, %ComSpec% /c "start explorer.exe"
Edit:
The "WSOD" happen because of no background process of explorer.exe running. Because of prematurely Run, explorer.exe only opens up File Explorer.
i can assume Run in autohotkey different from start in cmd.
and also, the color of background when the ".. Screen Of Death" sometimes come in Black, Blue, or other color.
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], mstrauss2021 and 245 guests