Click here to Skip to main content
15,885,033 members
Home / Discussions / C#
   

C#

 
Generalstill doesn't work Pin
Rüpel23-Sep-02 20:52
Rüpel23-Sep-02 20:52 
Generalfinally Pin
Rüpel23-Sep-02 21:53
Rüpel23-Sep-02 21:53 
GeneralEiffel .NET for Visual Studio .NET Plug-in Pin
Kevin McFarlane20-Sep-02 1:50
Kevin McFarlane20-Sep-02 1:50 
GeneralBackground and foreground color for disabled state Pin
valos20-Sep-02 1:18
valos20-Sep-02 1:18 
QuestionShut down one program from another? Pin
Matt Philmon19-Sep-02 18:11
Matt Philmon19-Sep-02 18:11 
AnswerRe: Shut down one program from another? Pin
Stephane Rodriguez.19-Sep-02 19:08
Stephane Rodriguez.19-Sep-02 19:08 
GeneralRe: Shut down one program from another? Pin
Matt Philmon19-Sep-02 20:50
Matt Philmon19-Sep-02 20:50 
GeneralRe: Shut down one program from another? Pin
Stephane Rodriguez.19-Sep-02 21:23
Stephane Rodriguez.19-Sep-02 21:23 
Here is the actual code executed by the .NET framework when you do Process.GetMainWindowHandle():
// Process.MainWindowHandle property :
public IntPtr get_MainWindowHandle() {
	if (!(this.haveMainWindow)) {
		this.EnsureState(10);
		this.mainWindowHandle = ProcessManager.GetMainWindowHandle(this.processInfo);
		this.haveMainWindow = 1;
	}
	return this.mainWindowHandle;
}

// ProcessManager.GetMainWindowHandle(...) :
public static IntPtr GetMainWindowHandle(ProcessInfo processInfo) {
	MainWindowFinder local0;

	local0 = new MainWindowFinder();
	return local0.FindMainWindow(processInfo.processId);
}

// MAinWindowFinder :
public MainWindowFinder() : base() {
}

public IntPtr FindMainWindow(int processId) {
	EnumThreadWindowsCallback local0;

	this.bestHandle = 20315E582031596Cop_Explicit20315970
020315968;
	this.processId = processId;
	local0 = new EnumThreadWindowsCallback(this, EnumWindowsCallback);
	NativeMethods.EnumWindows(local0, 20315E582031596Cop_Explicit20315970020315968);
	return this.bestHandle;
}

private bool EnumWindowsCallback(IntPtr handle, IntPtr extraParameter) {
	int local0;

	NativeMethods.GetWindowThreadProcessId(handle, local0);
	if (local0 == this.processId && this.IsMainWindow(handle)) {
		this.bestHandle = handle;
		return 0;
	}
	return 1;
}
private bool IsMainWindow(IntPtr handle) {
	if (20315E58NativeMethods.GetWindow(handle, 4) != 20315E582031596Cop_Explicit2031597002031596820315968 || !(NativeMethods.IsWindowVisible(handle)))
		return 0;
	return 1;
}



It is clear in the IsMainWindow that your window is required to be visible, otherwise it returns 0, see :
!(NativeMethods.IsWindowVisible(handle)))


Otherwise, I would see that the behaviour of enumeration is not the same whether you execute as non interactive user (your service), or interactive user. If you had time, you could just write a C++ service doing just that and check if there is a problem.




MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
GeneralRe: Shut down one program from another? Pin
Matt Philmon20-Sep-02 4:47
Matt Philmon20-Sep-02 4:47 
GeneralRe: Shut down one program from another? Pin
leppie20-Sep-02 5:22
leppie20-Sep-02 5:22 
GeneralRe: Shut down one program from another? Pin
Matt Philmon20-Sep-02 21:33
Matt Philmon20-Sep-02 21:33 
GeneralRe: Shut down one program from another? Pin
Stephane Rodriguez.21-Sep-02 1:52
Stephane Rodriguez.21-Sep-02 1:52 
GeneralRe: Shut down one program from another? Pin
leppie21-Sep-02 2:01
leppie21-Sep-02 2:01 
GeneralRe: Shut down one program from another? Pin
Matt Philmon21-Sep-02 5:49
Matt Philmon21-Sep-02 5:49 
GeneralBeta of .NET Framework Version 1.1 now available Pin
Eric Gunnerson (msft)19-Sep-02 12:30
Eric Gunnerson (msft)19-Sep-02 12:30 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone19-Sep-02 13:11
sitebuilderDavid Stone19-Sep-02 13:11 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Eric Gunnerson (msft)23-Sep-02 7:30
Eric Gunnerson (msft)23-Sep-02 7:30 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Matt Philmon20-Sep-02 21:34
Matt Philmon20-Sep-02 21:34 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
James T. Johnson21-Sep-02 2:07
James T. Johnson21-Sep-02 2:07 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
leppie21-Sep-02 2:06
leppie21-Sep-02 2:06 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone21-Sep-02 5:26
sitebuilderDavid Stone21-Sep-02 5:26 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
leppie21-Sep-02 5:50
leppie21-Sep-02 5:50 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone21-Sep-02 10:57
sitebuilderDavid Stone21-Sep-02 10:57 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
leppie23-Sep-02 10:29
leppie23-Sep-02 10:29 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Derek Lakin26-Sep-02 22:22
Derek Lakin26-Sep-02 22:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.