Jump to content

Script using 50% CPU


 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...