Launch a hidden application window

Discussion about the open-source Phalanger [?] project.

Launch a hidden application window

Postby Antilles » November 2nd, 2015, 3:43 pm

My app uses an external console application to complete its task but I couldn't figure out how to launch it without creating a console window. Here's the code I'm using:

Code: Select all
$arguments = " /foor /bar";

$app = new System\Diagnostics\Process;
$app->StartInfo->CreateNoWindow = true;
$app->StartInfo->WindowStyle = ProcessWindowStyle.Hidden;
$app->Start("app.exe",  $arguments);


This launches the app, but creates a console window.

Also, upon execution, I'm getting following error messages:

Notice: Use of undefined constant ProcessWindowStyle - assumed 'ProcessWindowStyle' in C:\Program Files\Phalanger 3.0\Bin\program.php on line 1111, column 1.

Notice: Use of undefined constant Hidden - assumed 'Hidden' in C:\Program Files\Phalanger 3.0\Bin\program.php on line 1112, column 1.




I also tried the following method:

Code: Select all
$arguments = " /foo /bar";

$app = new System\Diagnostics\ProcessStartInfo;
$app->Filename("app.exe");
$app->Arguments($arguments);
$app->WindowStyle = System\Diagnostics\ProcessWindowStyle\Hidden;
$app->UseShellExecute = false;
$app->Start();


Upon execution:

Error: Call to undefined method: System\Diagnostics\ProcessStartInfo::FileName() in C:\Program Files\Phalanger 3.0\Bin\program.php on line 1111, column 1.

for line $app->Arguments($arguments);


This doesn't even launch the application (although it used to, I must have messed it up).

Could you help me to assign the necessary attributes to my Process or ProcessStartInfo object? Thank you.
Antilles
 
Posts: 6
Joined: September 13th, 2015, 10:10 pm

Re: Launch a hidden application window

Postby Antilles » November 2nd, 2015, 7:35 pm

Addition: Namespace calls:

Code: Select all
use System;
use System\Management;
use System\Diagnostics;


Included libraries from compilation config:



Code: Select all
<add assembly="mscorlib" />
<add assembly="PhpNetClassLibrary, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4af37afe3cde05fb" />
<add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add assembly="System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />


I'm using console compiler (PHPC) of Phalanger 3.0.
Antilles
 
Posts: 6
Joined: September 13th, 2015, 10:10 pm

Re: Launch a hidden application window

Postby Jakub Misek » November 10th, 2015, 9:35 am

Hi,

First try to switch to Phalanger 4.0 (https://visualstudiogallery.msdn.micros ... cf66037797)

Then, accessing members in PHP uses operator ::. (\ is for namespaces, . is for string concatenation).
Code: Select all
System\Diagnostics\ProcessWindowStyle::Hidden


Also note, 'use' in PHP has a different meaning than in C#.
use System\Diagnostics; is equivalent to use System\Diagnostics as Diagnostics;
Then you should write Diagnostics\ProcessWindowStyle, not just ProcessWindowStyle.
Jakub Misek │ DEVSENSE s.r.o. │ Email: jakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2058
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Launch a hidden application window

Postby Antilles » November 16th, 2015, 7:35 pm

Thank you Jakub! I just used the :: operator and solved my issue.

I can't install Phalanger 4.0 because my app requires .Net Framework 3.5 compatibility (for target machines that running Windows XP). So I keep using Phalanger 3.0. So far, so good.
Antilles
 
Posts: 6
Joined: September 13th, 2015, 10:10 pm


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 2 guests

User Control Panel

Login

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 62 on January 7th, 2012, 10:54 pm

Users browsing this forum: No registered users and 2 guests
Phalanger