473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Logging off

I have the following situation:

1. Application X1 runs under a regular user account (this user is also
the currently logged on user).

2. Application X1 kicks off Application X2 using an Administrator
account and then quits itself.

3. Application X2 does a couple of things, then restarts Application X1
using the regular User account, then Application X2 quits itself.

4. Application X1 then needs to log off the system. It calls calls Win
API calls to enable log-off priviliges, then it calls ExitWindowsEx.
The api function kills the running app (e.g. X1), but the log-off itself
never happens.

The log-off works perfectly fine from the application running under the
regular user account, if it is not kicked off by an application running
under another account.

What am I missing here to make the log-off work?
Regards
Feb 20 '07 #1
6 2020
Hi Frank,

Can you show some code about how you lauch application from another
application with differen account and how you call API to enable log-off
priviliges? Also, if you first lauch APP X2, and then run APP X1 from it
and call ExitWindowsEx, will this make it successful?

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 20 '07 #2
Luke Zhang [MSFT] wrote:
Hi Frank,

Can you show some code about how you lauch application from another
application with differen account and how you call API to enable log-off
priviliges? Also, if you first lauch APP X2, and then run APP X1 from it
and call ExitWindowsEx, will this make it successful?
First of all, sorry for not replying in ascii - the code looks
unreadable in it.
Ok, here is how I kick off an executable. This routine is used by both
applications. It is fairly simply. The method separates the executable
from its arguments, applies user name and password and kicks off the
application. Note that Process.StartInfo.Domain is not set because we
are dealing with local accounts only.

public static Process RunExecutable(string exe, string userName,
string password)
{
string fileName = string.Empty;
string arguments = string.Empty;
bool useCredentials = false;
const string EXE_INDICATOR = ".exe";

// break up the exe parameter into filename and arguments
// basically look for data after .exe string

int iPos = exe.ToLower().IndexOf(EXE_INDICATOR);
if (iPos 0)
{
fileName = exe.Substring(0, iPos + EXE_INDICATOR.Length);

if (exe.Length iPos + EXE_INDICATOR.Length + 1)
arguments = exe.Substring(iPos +
EXE_INDICATOR.Length + 1);
}
else
fileName = exe;

Process prc = new Process();

prc.StartInfo.FileName = fileName.Trim();
prc.StartInfo.Arguments = arguments.Trim();

if (userName != string.Empty)
{
prc.StartInfo.UserName = userName;
useCredentials = true;
}

if (password != string.Empty)
{
SecureString ssPassword = new SecureString();
foreach (char c in password.ToCharArray())
ssPassword.AppendChar(c);

prc.StartInfo.Password = ssPassword;
useCredentials = true;
}

if (useCredentials)
{
// when using credentials, MS requires setting the
working directory as described in the following article
//
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref6/html/P_System_Diagnostics_ProcessStartInfo_Password.htm
// So will set the working directory to the current
directory.

// Derive the working directory from the location of the
entry assembly
string fullPath =
System.Reflection.Assembly.GetEntryAssembly().Loca tion;
FileInfo fi = new FileInfo(fullPath);

prc.StartInfo.WorkingDirectory = fi.DirectoryName;

// can't use Shell Execute when using credentials
prc.StartInfo.UseShellExecute = false;
}

prc.Start();
return prc;
}

Next, for logging off I use the WindowsController class from
http://www.mentalis.org/soft/class.qpx?id=7
It is very well documented and it's easy to use. I call
WindowsController.ExitWindows(RestartOptions.LogOf f, true);

Regards,
Robert
Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 20 '07 #3
Hi Robert,

The code lokks fine, what is the OS version, windows server 2003 or Vista?
If you use two local administrator accounts, will it also generate the
problem?

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 22 '07 #4
Any update on this issue?

Sincerely,

Luke Zhang

Microsoft Online Community Support
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 26 '07 #5
Luke Zhang [MSFT] wrote:
Hi Robert,

The code lokks fine, what is the OS version, windows server 2003 or Vista?
If you use two local administrator accounts, will it also generate the
problem?
Just XP Pro. With local admin accounts, the problem goes away.
>
Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Mar 5 '07 #6
Hello,

I just check the source code of Windows Controller class, and I found
following code:

protected static void ExitWindows(int how , bool force) {
EnableToken("SeShutdownPrivilege");
if (force)
how = how | EWX_FORCE;
if (ExitWindowsEx(how, 0) == 0)
throw new PrivilegeException(FormatError(Marshal.GetLastWin3 2Error()));
}
/// <summary>
/// Tries to enable the specified privilege.
/// </summary>
/// <param name="privilege">The privilege to enable.</param>
/// <exception cref="PrivilegeException">There was an error while
requesting a required privilege.</exception>
/// <remarks>Thanks to Michael S. Muegel for notifying us about a bug in
this code.</remarks>
protected static void EnableToken(string privilege ) {
if (Environment.OSVersion.Platform != PlatformID.Win32NT ||
!CheckEntryPoint("advapi32.dll", "AdjustTokenPrivileges"))
return;
IntPtr tokenHandle = IntPtr.Zero;
LUID privilegeLUID = new LUID();
TOKEN_PRIVILEGES newPrivileges = new TOKEN_PRIVILEGES();
TOKEN_PRIVILEGES tokenPrivileges ;
if (OpenProcessToken(Process.GetCurrentProcess().Hand le,
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref tokenHandle) == 0)
throw new PrivilegeException(FormatError(Marshal.GetLastWin3 2Error()));
if (LookupPrivilegeValue("", privilege, ref privilegeLUID) == 0)
throw new PrivilegeException(FormatError(Marshal.GetLastWin3 2Error()));
tokenPrivileges.PrivilegeCount = 1;
tokenPrivileges.Privileges.Attributes = SE_PRIVILEGE_ENABLED;
tokenPrivileges.Privileges.pLuid = privilegeLUID;
int size = 4;
if (AdjustTokenPrivileges(tokenHandle, 0, ref tokenPrivileges, 4 + (12 *
tokenPrivileges.PrivilegeCount), ref newPrivileges, ref size) == 0)
throw new PrivilegeException(FormatError(Marshal.GetLastWin3 2Error()));
}
I suggest you may and this class in your project and set break point in the
method of EnableToken(string privilege ). I suspect the problem occur here.
So, may run the application in debug mode, or add and some code to record
log information in the function, to check if there is any problem when
running the application in the real environment, for example, are all the
functions call successful in the method of EnableToken(string privilege )?

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 6 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jjesso | last post by:
I am trying to add a new logging level. logging.config.fileConfig("bengineLog.cfg") logging.CLIENT = logging.INFO + 1 logging.addLevelName( logging.CLIENT, 'CLIENT' ) logging.root.setLevel( )...
0
by: Karuppasamy | last post by:
H I am trying to use the Logging Module provided by Microsoft Application Blocks for .Net I installed everything as per the Instructions given in the 'Development Using the Logging Block' ...
6
by: pmatos | last post by:
Hi all, I am trying to create a simple but efficient C++ logging class. I know there are lots of them out there but I want something simple and efficient. The number one requirement is the...
23
by: Rotem | last post by:
Hi, while working on something in my current project I have made several improvements to the logging package in Python, two of them are worth mentioning: 1. addition of a logging record field...
6
by: Burkhard Schultheis | last post by:
As I wrote last week, we have a problem with a DB2 V8 on Linux. Here is what is in db2diag.log during online backup: Starting a full database backup. 2004-04-01-02.33.54.760164 ...
0
by: robert | last post by:
As more and more python packages are starting to use the bloomy (Java-ish) 'logging' module in a mood of responsibility and as I am not overly happy with the current "thickener" style of usage, I...
0
by: rajesh.hanchate | last post by:
Please help me in resolving this issue. I am using EnterpriseLibrary 2.0 Exception and logging block for logging exceptions to event log. It works fine for sometime. After some time it stops...
3
by: Chris Shenton | last post by:
I am setting up handlers to log DEBUG and above to a rotating file and ERROR and above to console. But if any of my code calls a logger (e.g., logging.error("foo")) before I setup my handlers, the...
3
by: Lowell Alleman | last post by:
Here is the situation: I wrote my own log handler class (derived from logging.Handler) and I want to be able to use it from a logging config file, that is, a config file loaded with the...
4
by: samwyse | last post by:
In the Python 2.5 Library Reference, section 14.5.3 (Logging to multiple destinations), an example is given of logging to both a file and the console. This is done by using logging.basicConfig()...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.