TestStack White with a tray window - c#

I need to interact with another application, that resides in the tray.
I'm currenty using TestStack White this way:
ProcessStartInfo processStartInfo = new ProcessStartInfo("MyProg.exe");
Application application = Application.AttachOrLaunch(processStartInfo);
_window = application.GetWindows()[0];
Everything works if the application was not running before this call, since launching it, this is visible.
Instead, if the application was already running, and in the tray, White could not find any window, and I can see this in the console as the following log:
Could not find any windows for this application
...and, after some retries, it fails with an exception.
Now, the best solution I found is to kill the application and relaunch it:
application.Kill();
application = Application.Launch("MyProg.exe");
and this works.
But I guess there is a better solution to this.

Open the application you want to automate and print all the running process names, find which stands for the application.
The add the following code...
Application myApp;
myApp = Application.Attach("ProcessName");
Hope it helps...

Did you try attaching to the explorer.exe process?? Since the system tray icon for the app will reside under the explorer.exe.
Something like this:
Did you try attaching to the explorer.exe process?? Since the system tray icon for the app will reside under the explorer.exe.
Something like this:
Process _explorerProcess = Process.GetProcessesByName("explorer")[0];
application = Application.Attach(_explorerProcess.Id);
Window desktopWindow = application.GetWindows()[0];
You should then be able to interact with the system tray icon.

Related

Can I call Windows 10 Wifi settings screen without explorer.exe shell?

I have a custom application running as a the shell (Windows 10 Enterprise) for a particular user - i.e. the user boots straight into this application.
However, I want to be able to provide access to the WiFi settings form. I have read that the way to do this is something like
Process.Start("ms-settings:network-wifi");
or
Process.Start("ms-availablenetworks:");
However, as far as I can tell, that relies on explorer running as the shell.
I've tried...
Process proc = new Process();
proc.StartInfo.FileName = #"c:\windows\explorer.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.Arguments = "ms-availablenetworks:";
proc.Start();
All of the above work fine if I run in a normal environment, i.e. with explorer as the shell.
But for this user (with my custom shell application), I get an instance of explorer.exe running and displaying an error, Class not registered
I have also come across using LaunchUriAsync() but I don't think that would help me here, besides it's only available for Windows Store applications for what I've read, which this is not.
Well I managed to get this working
First start explorer on its own, then a second Process.Start() to run the settings page.
Unfortunately, when explorer.exe runs, it displays the taskbar which I don't want. (I had previously assumed I'd be able to hide it with a group policy setting or something but this doesn't appear to be the case).
But I suppose that's another question...

AppServiceBridge without console window

I'm playing with Microsoft's UWP AppServiceBridgeSample (here).
It is working well, but I would like to get rid of the console window of the BackgroundProcess application. The reason for this is that my BackgroundProcess starts another Win32 desktop application and works only as a mediator, so I don't want to disturb users with a console window. (Yes, it can be minimized, but I would rather not show it at all).
I have tried to hide it using the API mentioned here, but with no luck, the console window is still visible. Neither did switching the project's output type from Console Application to Windows Application.work.
Another thing I have tried was to create other BackgroundProcess project as a Windows application. It runs fine until I call AppServiceConnection.OpenAsync(), which causes the BackgroundProcess application to exitstrong text, thus the connection to UWA is not available.
static async void ThreadProc()
{
try
{
AppServiceConnection connection = new AppServiceConnection();
connection.AppServiceName = "CommunicationService";
connection.PackageFamilyName = Windows.ApplicationModel.Package.Current.Id.FamilyName;
connection.RequestReceived += Connection_RequestReceived;
AppServiceConnectionStatus status = await connection.OpenAsync();
//status check etc. ...
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
It seems that opening the AppService connection is only possible from a console app.
So here are my two questions:
Is it, by any chance, even possible to hide the background process' console window?
Can I use the background process as a Windows application, without AppServiceConnection failing during OpenAsync calls?
Re 1: Go into the project settings and change the output type from Console to Windows app. Also make sure the Main() function doesn't exit until you are done with the background process. Here is a better sample that shows this with a Windows Application:
https://stefanwick.com/2017/05/26/uwp-calling-office-interop-apis/
Re 2: AppServiceConnection works the same way from a windowed application as well. Make sure you add the right reference to the Windows.winmd to be able to build. If you have trouble with that, please post a specific question with details of the problem you are seeing

link app with windows service like shut down so that process never end?

link app with windows process so that when user terminated or end the process it says used by another process and also need to insert it into system file like shutdown file using c sharp so that my app never end or terminates
i tried that material but not usefull
this.ShowInTaskbar = false;
I also tried that code in click:
WindowsImpersonationContext ctx = null;
if (!WindowsIdentity.GetCurrent().IsSystem)
{
ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero);
}
string thisuser = WindowsIdentity.GetCurrent().Name;
But have a look at image it is still present in process, what I want is that my process never stops.
what I want is that my process never stops.
To ensure that your process is always running and is started when Windows boots it's easiest to create a windows service instead. It will probably still show up somewhere in task manager and could be killed manually by the user. But windows will try to keep it running.
How to create a service:
https://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx
And if you need other programs to communicate with your service I find it easy to use a WCF service instead.
https://msdn.microsoft.com/en-us/library/bb386386.aspx

How to launch a Windows8 Metro App by C# form application?

Now I want to launch a Windows 8 Metro App by a C# form application, but it's hard for me to find the right way...
I had tried these ways(I had installed the Metro App and registered a protocol):
1.
var success = await Windows.System.Launcher.LaunchUriAsync(new Uri("TestContent"));
In the "TestContent" above, I tried the protocol name registered on my computer and the Metro App's name, but the same error "Access Denied" occurred.
2.
Process p = new Process();
p.StartInfo.FileName = "ProtocolName://";
p.Start();
This time the Metro App only showed the splash screen but didn't launch the whole program.
Any ideas?
Thank you in advance.
2015/10/01 ADD:
After Reading this question:
[link]stackoverflow.com/questions/18787609/…
I think it is impossible to run a metro app from a windows form.
The right format to launch is :
Uri uri = new Uri("protocolname://anything");
await Windows.System.Launcher.LaunchUriAsync(uri);
And, Make sure that you're doing that from the foreground app, i.e. Not Background Task or a Toast notification or Tile .. etc.
After Reading this question:
C# Mixing WinRT and Windows Forms
I think it may be impossible to run a metro app from a windows form.
But when I try the code below :
Process p = new Process();
p.StartInfo.FileName = #"BINGMAPS://";
p.Start();
The BINGMAPS runs normally.
Did I miss any necessary setting in the Metro App?
First you need your app to handle protocol activation and then in App.xaml.cs in OnActivated event handle it to launch the first page or whatever page you want to call in Metro app. In C# form application using javascript set the current page content as the metro app. It will work.

Start a new explorer.exe process from C#

If I run this command:
C:\WINDOWS\explorer.exe "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{2227A280-3AEA-1069-A2DE-08002B30309D}"
from the Windows shell (via Windows+R), my printer and faxes open in a new explorer.exe process. (So I have 2 running explorer.exe processes.)
If i execute:
Process.Start(#"C:\WINDOWS\explorer.exe", #"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\" +
#"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\" +
#"::{2227A280-3AEA-1069-A2DE-08002B30309D}");
from a C# program, my printer and faxes open too, but as an child process of the main explorer.exe process (the one running the Windows shell, including the taskbar, etc.).
What can I do to start a second explorer.exe process with the printer and faxes window from C#?
Initial thoughts - check your "Launch folder windows in a separate process" in Folder Options (Organize -> Folder & Search Options -> View tab). This is unchecked by default, hence "Check" this and try your C# code again.
I know this setting affects the ShellExecute function but I am not sure if .NET's Diagnostic namespace uses the same route.
ShellExecute(handle, "explore", , NULL, NULL, SW_SHOWNORMAL);
Second thoughts - a similar issue has been already discussed in stackoverflow and this post might give you some idea.
Start new process, without being a child of the spawning process

Categories

Resources