Sign in to follow this  
Followers 0
HockeyFan

Script using 50% CPU

9 posts in this topic

#1 ·  Posted (edited)

I created this script to help monitor when the "Start Menu" is activated so that it can be closed automatically. When I test the script,

I notice that the CPU is right at 50% utilization...and 8% when not run. Can someone explain to me what part of the script is causing this? :)

Thanks! :)

$FullName = GetFullName(@UserName)
AdlibEnable("StartMenu",500)
While 1
WEnd
Exit
Func GetFullName($sUserName)
    $colItems = ""
    $strComputer = "localhost"
                $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount WHERE Name = '" & $sUserName &  "'", "WQL", 0x10 + 0x20)
    If IsObj($colItems) then
       For $objItem In $colItems
       Return $objItem.FullName
                   Next
    Else
       Return SetError(1,0,"")
    Endif
EndFunc

Func StartMenu()
 $StartMenu = WinExists("Start Menu", $FullName)
 If $StartMenu = 1 Then
  Send("{LWIN}")
 Else
  Return
 EndIf
EndFunc
Edited by HockeyFan

Share this post


Link to post
Share on other sites



You don't have any sleep. By your processor being at 50%, I can also tell you have a dual core or two processors.

Share this post


Link to post
Share on other sites

That's all it needed. :)

Share this post


Link to post
Share on other sites

You don't have any sleep. By your processor being at 50%, I can also tell you have a dual core or two processors.

WOW! That was simple...thanks!

What was asleep was me!! :)

Thanks for your help.

Share this post


Link to post
Share on other sites

I just placed a

SLeep( 100 )
within the
While 1
statement. That seems to have done it for me.

Thanks!!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

OK, changed a couple of things after doing some forum searching and tinkering.

HotKeySet( "{ESC}" , "terminate" )

While 1 
    Sleep( 500 )    
    If WinExists("Start Menu") = 1 Then 
        WinClose("Start Menu")
    EndIf
WEnd

Exit

Func terminate()
    EXIT
EndFunc

I guess that you could always make a bot in AutoIt that will select a certain program to open from the startmenu before your program has a chance to close the menu.

EDIT:

No that still doesn't work. Supposedly "If WinExists("Start Menu") = 1 Then" always reports a '1' for some reason and so the window is being closed all of the time no matter what.

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

Many programs will just hide windows instead of destroy them. It's much more resource efficient.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0