Page 1 of 1

programId crashes on Windows XP

Posted: Wed Sep 28, 2011 3:50 pm
by rootbear
new to here,

here is what i want to accomplish:

create a windows service in PB
1) to start console EXE {program1} (by another language) in background without CMD window;
2) to loop and check if program1 is running or not periodically, if not, restart it;

code here:

Code: Select all

prog = RunProgram(MY_PROGRAM_NAME, "","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
PrintN("prog=" + Str(prog))
If IsProgram(prog)
  PrintN("isProgram=true")
  pid = ProgramID(prod)
  PrintN("pid=" + Str(pid))
Else
  PrintN("not a program")
  Return false
EndIf

If !ProgramRunning(pid)
  ;restart it
EndIf
my code crashed on me at programID, i tried a couple of PCs and tried change program1 to calc.exe

appreciate any help

Re: programId crashes on Windows XP

Posted: Wed Sep 28, 2011 4:10 pm
by gnozal

Code: Select all

pid = ProgramID(prod) ; <---
Did you try

Code: Select all

pid = ProgramID(prog)
?

Also

Code: Select all

  Return false

Code: Select all

If !ProgramRunning(pid)
seem wrong to me (no valid PB syntax).

Re: programId crashes on Windows XP

Posted: Wed Sep 28, 2011 7:10 pm
by rootbear
sorry, some typo in the code.
here is the code i actually compiled, still crash on line

Code: Select all

pid = ProgramID(prod)

Code: Select all


MY_PROGRAM_NAME.s = "C:\windows\system32\calc.exe"

If OpenConsole()
  
  prog = RunProgram(MY_PROGRAM_NAME, "","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
  PrintN("prog=" + Str(prog))
  If IsProgram(prog)
    PrintN("isProgram=true, ok till here")
    pid = ProgramID(prod)
    PrintN("pid=" + Str(pid))
  Else
    PrintN("not a program")
  EndIf
  
EndIf


Re: programId crashes on Windows XP

Posted: Wed Sep 28, 2011 7:44 pm
by Thorium
Still, the same typo in there that gnozal showed you.
Thats why we should use EnableExplicit.

Re: programId crashes on Windows XP

Posted: Wed Sep 28, 2011 7:45 pm
by luis
prog <> prod

EnableExplicit is your friend. :wink:


EDIT: damn, Thorium faster by 1 SEC ... ergh no... those are minutes... well ... faster !

Re: programId crashes on Windows XP

Posted: Wed Sep 28, 2011 10:20 pm
by kenmo

Code: Select all

If !ProgramRunning(pid)
Should be If Not ProgramRunning(pid), the ! operator is XOR in PureBasic!

Code: Select all

Return false
Return is used with gosubs (otherwise you'll have an IMA error), and does not return a value!

Perhaps you mean ProcedureReturn (some value), but this of course is only used within procedures.

Re: programId crashes on Windows XP

Posted: Wed Sep 28, 2011 10:34 pm
by rootbear
thanks a lot, guys!

i end up coding it in vb6 (but i hate the runtime.) before i came back to check the reply.

now i can use pb, yahoo!

again, thanks