programId crashes on Windows XP

Just starting out? Need help? Post your questions and find answers here.
rootbear
New User
New User
Posts: 4
Joined: Wed Sep 28, 2011 2:47 pm

programId crashes on Windows XP

Post 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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: programId crashes on Windows XP

Post 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).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
rootbear
New User
New User
Posts: 4
Joined: Wed Sep 28, 2011 2:47 pm

Re: programId crashes on Windows XP

Post 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

Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: programId crashes on Windows XP

Post by Thorium »

Still, the same typo in there that gnozal showed you.
Thats why we should use EnableExplicit.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: programId crashes on Windows XP

Post by luis »

prog <> prod

EnableExplicit is your friend. :wink:


EDIT: damn, Thorium faster by 1 SEC ... ergh no... those are minutes... well ... faster !
"Have you tried turning it off and on again ?"
User avatar
kenmo
Addict
Addict
Posts: 2043
Joined: Tue Dec 23, 2003 3:54 am

Re: programId crashes on Windows XP

Post 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.
rootbear
New User
New User
Posts: 4
Joined: Wed Sep 28, 2011 2:47 pm

Re: programId crashes on Windows XP

Post 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
Post Reply