RunProgram - prevent messagebox from appearing?

Just starting out? Need help? Post your questions and find answers here.
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

RunProgram - prevent messagebox from appearing?

Post by Nituvious »

Whenever you type an invalid executable or path with RunProgram on windows, you get a messagebox that appears "Windows cannot find '....'. Make sure you typed the name correctly, and then try again."
How can we prevent this run popping up? It halts my program until the annoying box is closed..
▓▓▓▓▓▒▒▒▒▒░░░░░
datachild
User
User
Posts: 11
Joined: Sat Jun 12, 2010 7:47 pm

Re: RunProgram - prevent messagebox from appearing?

Post by datachild »

Check first if the file is there/exists before try to run anything ...
:)
DarkPlayer
Enthusiast
Enthusiast
Posts: 107
Joined: Thu May 06, 2010 11:36 pm

Re: RunProgram - prevent messagebox from appearing?

Post by DarkPlayer »

Hello,

For Windows just use the CreateProcess() API.

Example:

Code: Select all

StartInfo.STARTUPINFO 
StartInfo\cb = SizeOf(STARTUPINFO)
ProcessInfo.PROCESS_INFORMATION 

If CreateProcess_("404.exe",0,0,0,0,0,0,0,@StartInfo, @ProcessInfo)
  Debug "started"
Else
  Debug "Not started :-("
  If GetLastError_() = 2
    Debug "File not found!"
  EndIf
EndIf
Replace the 404.exe with C:\windows\notepad.exe and it should start Notepad.

The Documentation for CreateProcess(): http://msdn.microsoft.com/en-us/library ... 85%29.aspx

DarkPlayer
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Re: RunProgram - prevent messagebox from appearing?

Post by Edwin Knoppert »

>you get a messagebox that appears "Windows cannot find '....'.
You're not kidding me heh?
Is this an action made by the compiler?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: RunProgram - prevent messagebox from appearing?

Post by netmaestro »

Why not just:

Code: Select all

If FileSize(path$) > 0
  RunProgram([..])
EndIf
BERESHEIT
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: RunProgram - prevent messagebox from appearing?

Post by Nituvious »

Thanks guys, I'm kind of "not all there" when it comes to programming. So the simplest tasks to you guys is a whole another country to me. :(
▓▓▓▓▓▒▒▒▒▒░░░░░
Post Reply