Jump to content

Recommended Posts

Posted

Hi,

I've got a script compiled into an EXE that runs fine when I'm logged in and start it manually. But when I launch it on startup (user login, not system startup), I get the following error (as shown in attached file)

The relevant section of code is:

CODE
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then

For $objItem In $colItems

if StringInStr($objItem.CommandLine, $pagename, False) then

;consolewrite(@crlf & "$pagename$: Got process " & $objItem.caption & ":" & $objItem.CommandLine)

$commandLine = $objItem.Commandline

if StringInStr($commandLine, $pagename) Then

;_DebugOut ("True")

; Get process details

$aProcesses = _ProcessListProperties($objItem.ProcessId)

ConsoleWrite(@crlf & "CPU: " & $aProcesses[1][6]) ; <<<<<< LINE 305 <<<<<<<<<<<

return $objItem.ProcessId

EndIf

;_DebugOut ("False")

Else

; consolewrite(@crlf & "didn't find $pagename$ in " & $objItem.CommandLine)

EndIf

Next

EndIf

Any ideas why this works OK once I'm logged on and the PC has finished processing my logon (ie, I can work normally), but doesn't if it's fired at the point the PC is still going through the logon process?

Or do you have any suggestions/warnings about adding a one-off delay that runs when the EXE first runs?

Regards,

Andy

post-8991-1230542669_thumb.gif

Posted (edited)

@Andrew

It seems that the system hasnt completly started, try to run your script with regedit at startup on the RunOnceEx for it start after system finish loading :)

Cheers, FireFox.

Edited by FireFox
Posted (edited)

Get some more debug info like this:

If StringInStr($commandLine, $pagename) Then
                ; Get process details
                ConsoleWrite("Debug: $objItem.ProcessId = " & $objItem.ProcessId & @LF)
                $aProcesses = _ProcessListProperties($objItem.ProcessId)
                _ArrayDisplay($aProcesses, "Debug: $aProcesses")
                ConsoleWrite(@CRLF & "CPU: " & $aProcesses[1][6])
                Return $objItem.ProcessId
            EndIf

This will tell you if you are passing a valid PID, and will show the array _ProcessListProperties() is returning.

:)

P.S. Change the ConsoleWrite() functions to _FileWriteLog() or MsgBox() if you don't see those debug outputs.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
  • Recently Browsing   0 members

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