WinForms- Windows forms Interview Question and answers Page 1
More Winforms
Page 1Page 2Page 3Page 4Page 5

1.1 How can I run an EXE from within my application?

Use the Process class found in the System.Diagnostics namespace.
[C#]
Process proc = new Process();
proc.StartInfo.FileName = @"Notepad.exe";
proc.StartInfo.Arguments = "";
proc.Start();

[VB.NET]
Dim proc As New Process()
proc.StartInfo.FileName = "Notepad.exe"
proc.StartInfo.Arguments = ""
proc.Start()

1.2 What are the common issues in redirecting assemblies using the publisher policy files?
1) Make sure to follow proper naming conventions for the policy dll. For example, if the original assembly name is TestAssembly.dll then the corresponding policy assembly should be called "policy.1.0.TestAssembly.dll" to make this redirection work for all "1.0.*" version bindings of the original assembly.

2) While specifying the name for the assembly in the policy file, do not include the ".dll" extension.

This is wrong:

>assemblyIdentity name="TestAssembly.dll" publicKeyToken="f638d0a8d5996dd4" culture="neutral" /<

Instead use:

>assemblyIdentity name="TestAssembly" publicKeyToken="f638d0a8d5996dd4" culture="neutral" /<

3) Make sure to sign the policy assembly with the same strong name as the original.

4) Make sure to distribute the policy file along with the policy assembly. Installing the policy assembly in the GAC alone will not suffice. Note that any change made to the policy file after creating the policy assembly will not take effect.

5) Always use /link (to the policy file) in the "al" command while creating the policy assembly. Do not use /embed.
It doesn't seem to be supported.

Some good links:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcreatingpublisherpolicyfile.asp

http://www.newtelligence.com/downloads/downloads-basta2001.aspx

http://www.only4gurus.com/DotNet/studies/managevers.htm

1.3 How can I find all programs with a GUI (not just arbitrary windows) that are running on my local machine?

You could use EnumWindows with p/Invoke, but using the static Process.GetProcesses() found in the System.Diagnostics namespace will avoid the interop overhead.
[C#]
Using System.Diagnostics;
...
foreach ( Process p in Process.GetProcesses(System.Environment.MachineName) )
{
if( p.MainWindowHandle != IntPtr.Zero)
{
//this is a GUI app
Console.WriteLine( p ); // string s = p.ToString();
}
}

[VB.NET]
Imports System.Diagnostics
...
Dim p As Process
For Each p In Process.GetProcesses(System.Environment.MachineName)
If p.MainWindowHandle <> IntPtr.Zero Then
'this is a GUI app
Console.WriteLine(p) ' string s = p.ToString();
End If
Next p


There is one potential problem on Windows 98. If a process was started with ProcessStartInfo.UseShellExecute set to true, this MainWindowHandle is not available.

1.4 How can I get a list of all processes running on my system?


Use the static Process.GetProcesses() found in the System.Diagnostics namespace.
[C#]
Using System.Diagnostics;
...
foreach ( Process p in Process.GetProcesses() )
Console.WriteLine( p ); // string s = p.ToString();

[VB.NET]
Imports System.Diagnostics
...
Dim p As Process
For Each p In Process.GetProcesses()
Console.WriteLine(p) ' string s = p.ToString()
Next p