Win32 API call from C# - ExitWindowsEx

J

Jeremy Horton

Hi,

New to C# and trying to build an app that has a logout button.
I just want the user to be able to log out of their Windows session from
within the Windows Form.
I have;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ExitWindowsEx(string teststring1, int testint1);
// private static extern bool ExitWindows(int testint1, int testint2);
// error: entry point not found in user32.dll (?)

and then when the button is clicked;

public void Logout_Click(object sender, System.EventArgs e)
{
ExitWindowsEx(@"EWX_LOGOFF", 0);
// ExitWindows(0, 0);
// error: entry point not found in user32.dll (?)
}
With ExitWindows the entry point is not found, but with ExitWindowsEx
nothing happens (?)
I also see the memory of the .exe increasing by 4k everytime I press the
logout button,
any help greatly appreciated.
Jeremy.
 
S

Shiva

Hi,

The 1st parameter of ExitWindowsEx should be an uint, not string and pass 0
(for log off) for the 1st one.

Hi,

New to C# and trying to build an app that has a logout button.
I just want the user to be able to log out of their Windows session from
within the Windows Form.
I have;

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool ExitWindowsEx(string teststring1, int testint1);
// private static extern bool ExitWindows(int testint1, int testint2);
// error: entry point not found in user32.dll (?)

and then when the button is clicked;

public void Logout_Click(object sender, System.EventArgs e)
{
ExitWindowsEx(@"EWX_LOGOFF", 0);
// ExitWindows(0, 0);
// error: entry point not found in user32.dll (?)
}
With ExitWindows the entry point is not found, but with ExitWindowsEx
nothing happens (?)
I also see the memory of the .exe increasing by 4k everytime I press the
logout button,
any help greatly appreciated.
Jeremy.
 
J

Jeremy

Shiva - worked first go.
Adam - pinvoke.net, if only I had know this site existed 12hrs ago !!

thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top