VBS Files Not Moving Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
ceyhunveysel
Posts: 49
Joined: 02 Aug 2019, 15:39

VBS Files Not Moving

25 Nov 2019, 16:45

Hello everybody.
Today I tried to make a script that runs a vbs file and then moves it to a position, but it does not move the file, and does nothing about it. When I run my file, the vbs file just stays where it was and the script just quits.
Thanks for any help you could include.

Code: Select all

FileAppend, 
(
X=Msgbox("Hello"), 0x16, ("Hello")
), vbsFile.vbs
run, vbsFile.vbs
random, x, 1, 1000
random, y, 1, 1000
WinMove, ahk_exe wscript.exe, %x%, %y% ; I checked and it is wscript.exe.
Homever, the code I posted's

Code: Select all

WinMove, ahk_exe wscript.exe, %x%, %y%
does not work.
Any help would be appreciated. :D
User avatar
Xtra
Posts: 1770
Joined: 02 Oct 2015, 12:15

Re: VBS Files Not Moving

25 Nov 2019, 16:50

Try waiting for the window to exist before moving it. Read: WinWait

Code: Select all

WinWait, ahk_exe wscript.exe
WinMove, ahk_exe wscript.exe, %x%, %y%
A_Perry_1984
Posts: 76
Joined: 07 Dec 2018, 12:08

Re: VBS Files Not Moving

25 Nov 2019, 16:54

@Xtra,

I am curious. I have had mixed results with Winwait. I often find it doesn't work, and use the If winexist. Have you had consistant results?
ceyhunveysel
Posts: 49
Joined: 02 Aug 2019, 15:39

Re: VBS Files Not Moving

25 Nov 2019, 16:55

@Xtra
I just tried it, still can't move the window.
signature C:
ceyhunveysel
Posts: 49
Joined: 02 Aug 2019, 15:39

Re: VBS Files Not Moving

25 Nov 2019, 16:57

@A_Perry_1984 Nope.
signature C:
User avatar
Xtra
Posts: 1770
Joined: 02 Oct 2015, 12:15

Re: VBS Files Not Moving  Topic is solved

25 Nov 2019, 16:59

Code: Select all

WinWait, ahk_exe wscript.exe
WinMove, ahk_exe wscript.exe,, %x%, %y%
Try it with the parameters set correctly there was a missing comma for the wintext. (common mistake)
Winwait works fine assuming you give it the correct WinTitle.
ceyhunveysel
Posts: 49
Joined: 02 Aug 2019, 15:39

Re: VBS Files Not Moving

25 Nov 2019, 17:05

@Xtra
That fixed my problem so well!!! Thank you for that SO MUCH.
signature C:
A_Perry_1984
Posts: 76
Joined: 07 Dec 2018, 12:08

Re: VBS Files Not Moving

25 Nov 2019, 17:07

I often have better results with

If WinExist(Window Title)
WinActivate, WinMove, etc
User avatar
Xtra
Posts: 1770
Joined: 02 Oct 2015, 12:15

Re: VBS Files Not Moving

25 Nov 2019, 23:12

A_Perry_1984 wrote:
25 Nov 2019, 17:07
I often have better results with

If WinExist(Window Title)
WinActivate, WinMove, etc
That would only check for the WinTitle condition one time.
You would need to use your code in a loop to wait for a window. (Which will work but adds unnecessary lines)

Code: Select all

Loop
{
    if WinExist("ahk_exe wscript.exe")
        break
    Sleep 500
}
WinMove, ahk_exe wscript.exe,, %x%, %y%
Or:

Code: Select all

while !WinExist("ahk_exe wscript.exe")
    Sleep 500
WinMove, ahk_exe wscript.exe,, %x%, %y%

If you are not sure if a window will exist you could use the timeout parameter of WinWait and check ErrorLevel.
Example:

Code: Select all

WinWait, ahk_exe wscript.exe,, 5
if (ErrorLevel)
    MsgBox,, 5 seconds timeout!, Window does not exist!
else
    WinMove, ahk_exe wscript.exe,, %x%, %y%
HTH
A_Perry_1984
Posts: 76
Joined: 07 Dec 2018, 12:08

Re: VBS Files Not Moving

27 Nov 2019, 10:32

Those are some great suggestions! Thank you!

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Canengy, Google [Bot], RickC and 135 guests