Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AnhurChivas
Posts: 9
Joined: 30 Jul 2022, 03:43

Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by AnhurChivas » 01 Feb 2023, 23:04

Hello.
There is a long script that I wrote myself. This script works normally in Windows 7 and Windows 10 with VMWare Workstation, but in Windows 8 and Windows 8.1 it freezes after a while and starts to consume a lot of CPU.
A script I wrote for a game, after the game starts, AHK starts to load too much on the CPU.

Windows 8.1
windows8.1.jpg
windows8.1.jpg (7.81 KiB) Viewed 736 times
Windows 7 (It's usually around 1%-4%, it's very normal)
windows7.jpg
windows7.jpg (4.91 KiB) Viewed 736 times
I've tried many versions of Windows 8.1 but they're all the same.
In some versions of Windows 10 and Windows 7, I had the same problems as in Windows 8.1, but I could not find the cause of the problem.
Any ideas?

AnhurChivas
Posts: 9
Joined: 30 Jul 2022, 03:43

Re: Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by AnhurChivas » 01 Feb 2023, 23:45

Okey, i found the problem... It happens when I try to get data with API, I have no idea how to fix the problem...
Any help?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by swagfag » 01 Feb 2023, 23:51

u may have allocated a different number of cores to the win8.1 vm, skewing the results. other that that there wont be any ideas without seeing the code

AnhurChivas
Posts: 9
Joined: 30 Jul 2022, 03:43

Re: Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by AnhurChivas » 02 Feb 2023, 00:01

swagfag wrote:
01 Feb 2023, 23:51
u may have allocated a different number of cores to the win8.1 vm, skewing the results. other that that there wont be any ideas without seeing the code
Hey, i found the problem but idk how to fix.
I have this problem when I try to get data using API.
I'm using this

Code: Select all

StdOutToVar(cmd) 
{
	DllCall("CreatePipe", "PtrP", hReadPipe, "PtrP", hWritePipe, "Ptr", 0, "UInt", 0)
	DllCall("SetHandleInformation", "Ptr", hWritePipe, "UInt", 1, "UInt", 1)

	VarSetCapacity(PROCESS_INFORMATION, (A_PtrSize == 4 ? 16 : 24), 0)    ; http://goo.gl/dymEhJ
	cbSize := VarSetCapacity(STARTUPINFO, (A_PtrSize == 4 ? 68 : 104), 0) ; http://goo.gl/QiHqq9
	NumPut(cbSize, STARTUPINFO, 0, "UInt")                                ; cbSize
	NumPut(0x100, STARTUPINFO, (A_PtrSize == 4 ? 44 : 60), "UInt")        ; dwFlags
	NumPut(hWritePipe, STARTUPINFO, (A_PtrSize == 4 ? 60 : 88), "Ptr")    ; hStdOutput
	NumPut(hWritePipe, STARTUPINFO, (A_PtrSize == 4 ? 64 : 96), "Ptr")    ; hStdError
	
	if !DllCall(
	(Join Q C
		"CreateProcess",             ; http://goo.gl/9y0gw
		"Ptr",  0,                   ; lpApplicationName
		"Ptr",  &cmd,                ; lpCommandLine
		"Ptr",  0,                   ; lpProcessAttributes
		"Ptr",  0,                   ; lpThreadAttributes
		"UInt", true,                ; bInheritHandles
		"UInt", 0x08000000,          ; dwCreationFlags
		"Ptr",  0,                   ; lpEnvironment
		"Ptr",  0,                   ; lpCurrentDirectory
		"Ptr",  &STARTUPINFO,        ; lpStartupInfo
		"Ptr",  &PROCESS_INFORMATION ; lpProcessInformation
	)) {
		DllCall("CloseHandle", "Ptr", hWritePipe)
		DllCall("CloseHandle", "Ptr", hReadPipe)
		return ""
	}

	DllCall("CloseHandle", "Ptr", hWritePipe)
	VarSetCapacity(buffer, 4096, 0)
	while DllCall("ReadFile", "Ptr", hReadPipe, "Ptr", &buffer, "UInt", 4096, "UIntP", dwRead, "Ptr", 0)
		sOutput .= StrGet(&buffer, dwRead, "CP0")

	DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, 0))         ; hProcess
	DllCall("CloseHandle", "Ptr", NumGet(PROCESS_INFORMATION, A_PtrSize)) ; hThread
	DllCall("CloseHandle", "Ptr", hReadPipe)
	return sOutput
}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by swagfag » 02 Feb 2023, 03:45

doubt thats the issue

AnhurChivas
Posts: 9
Joined: 30 Jul 2022, 03:43

Re: Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by AnhurChivas » 02 Feb 2023, 04:25

swagfag wrote:
02 Feb 2023, 03:45
doubt thats the issue

Code: Select all

GoldCheck()
{
  strStdOut:=StdOutToVar("curl --insecure https://127.0.0.1:2999/liveclientdata/activeplayer")
	 goldPos := InStr(strStdOut, "currentGold" , CaseSensitive := true, StartingPos := 1, Occurrence := 1)
	 offset:=0
	 while (char!=".")
	 {
		  offset:=offset+1
	   char:=SubStr(strStdOut, goldPos+12+offset, 1)
	 }
	 goldEndPos:=goldPos+offset-2
	 lenght:=(goldEndPos-goldPos)
	 currentGold := SubStr(strStdOut, goldPos+14, lenght)
  return %currentGold%
}
When I delete "while" part, the script doesn't get stuck and the CPU doesn't go up but output is different on both machines...

OS without issue also gives this output, there is no problem
gold.jpg
gold.jpg (5.7 KiB) Viewed 598 times
but OS with issue also gives blank output

There is absolutely no problem with the codes, as long as I use While properly, it gives the output it should like this
gold2.jpg
gold2.jpg (3.11 KiB) Viewed 598 times
But when I use while properly, the script gets stuck on the problematic OS and the CPU rises...
For example, I installed two different modified Windows 7 operating systems on the same computer via VMWare, but the script works fine in one and does not work in the other.
In Windows 8 or 8.1, it does not work properly in either of them.
Do not be misunderstood when I say it is problematic, there is no problem in any operating system, but it happens as I described and idk why

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by swagfag » 02 Feb 2023, 08:28

if StdOutToVar returns an empty string(a possibility which u arent accounting for), ull enter an infinite while-loop

StdOutToVar returns an empty string if the CreateProcess dllcall fails. to find out why it might be failing u need to check the dllcall's return value, ErrorLevel and A_LastError and compare the reported error values against the microsoft documentation

another possibility is that ur curl command returns an empty string

AnhurChivas
Posts: 9
Joined: 30 Jul 2022, 03:43

Re: Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by AnhurChivas » 02 Feb 2023, 11:02

swagfag wrote:
02 Feb 2023, 08:28
if StdOutToVar returns an empty string(a possibility which u arent accounting for), ull enter an infinite while-loop

StdOutToVar returns an empty string if the CreateProcess dllcall fails. to find out why it might be failing u need to check the dllcall's return value, ErrorLevel and A_LastError and compare the reported error values against the microsoft documentation

another possibility is that ur curl command returns an empty string
Hello again, I'm sorry to disturb you. I took a video and recorded all the codes and outputs.
I have no idea how the StdOutToVar part works, I got it from someone else.

So I have no idea how I should arrange them, but I don't think there is a mistake.
You can see everything in the video, same codes, different results.

https://www.youtube.com/watch?v=cZkTcJl2ciE

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Windows 8.1 AHK High CPU Usage (VMWare Workstation)

Post by swagfag » 02 Feb 2023, 12:41

dont change the while-loop, because it's pointless to do so and it won't fix anything. this isn't where the problem is.

it is as i said. either CreateProcess fails or the curl command is returning an empty string. u need to troubleshoot that first

Post Reply

Return to “Ask for Help (v1)”