473,594 Members | 2,663 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2037
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.StartIn fo.Domain is not set because we
are dealing with local accounts only.

public static Process RunExecutable(s tring 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().I ndexOf(EXE_INDI CATOR);
if (iPos 0)
{
fileName = exe.Substring(0 , iPos + EXE_INDICATOR.L ength);

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

Process prc = new Process();

prc.StartInfo.F ileName = fileName.Trim() ;
prc.StartInfo.A rguments = arguments.Trim( );

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

if (password != string.Empty)
{
SecureString ssPassword = new SecureString();
foreach (char c in password.ToChar Array())
ssPassword.Appe ndChar(c);

prc.StartInfo.P assword = 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_Diagno stics_ProcessSt artInfo_Passwor d.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.Reflecti on.Assembly.Get EntryAssembly() .Location;
FileInfo fi = new FileInfo(fullPa th);

prc.StartInfo.W orkingDirectory = fi.DirectoryNam e;

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

prc.Start();
return prc;
}

Next, for logging off I use the WindowsControll er class from
http://www.mentalis.org/soft/class.qpx?id=7
It is very well documented and it's easy to use. I call
WindowsControll er.ExitWindows( RestartOptions. LogOff, 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("Se ShutdownPrivile ge");
if (force)
how = how | EWX_FORCE;
if (ExitWindowsEx( how, 0) == 0)
throw new PrivilegeExcept ion(FormatError (Marshal.GetLas tWin32Error())) ;
}
/// <summary>
/// Tries to enable the specified privilege.
/// </summary>
/// <param name="privilege ">The privilege to enable.</param>
/// <exception cref="Privilege Exception">Ther e was an error while
requesting a required privilege.</exception>
/// <remarks>Than ks to Michael S. Muegel for notifying us about a bug in
this code.</remarks>
protected static void EnableToken(str ing privilege ) {
if (Environment.OS Version.Platfor m != PlatformID.Win3 2NT ||
!CheckEntryPoin t("advapi32.dll ", "AdjustTokenPri vileges"))
return;
IntPtr tokenHandle = IntPtr.Zero;
LUID privilegeLUID = new LUID();
TOKEN_PRIVILEGE S newPrivileges = new TOKEN_PRIVILEGE S();
TOKEN_PRIVILEGE S tokenPrivileges ;
if (OpenProcessTok en(Process.GetC urrentProcess() .Handle,
TOKEN_ADJUST_PR IVILEGES | TOKEN_QUERY, ref tokenHandle) == 0)
throw new PrivilegeExcept ion(FormatError (Marshal.GetLas tWin32Error())) ;
if (LookupPrivileg eValue("", privilege, ref privilegeLUID) == 0)
throw new PrivilegeExcept ion(FormatError (Marshal.GetLas tWin32Error())) ;
tokenPrivileges .PrivilegeCount = 1;
tokenPrivileges .Privileges.Att ributes = SE_PRIVILEGE_EN ABLED;
tokenPrivileges .Privileges.pLu id = privilegeLUID;
int size = 4;
if (AdjustTokenPri vileges(tokenHa ndle, 0, ref tokenPrivileges , 4 + (12 *
tokenPrivileges .PrivilegeCount ), ref newPrivileges, ref size) == 0)
throw new PrivilegeExcept ion(FormatError (Marshal.GetLas tWin32Error())) ;
}
I suggest you may and this class in your project and set break point in the
method of EnableToken(str ing 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(str ing 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
3662
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( ) logger = logging.getLogger(None) logging.Logger.client('test') I get error:
0
395
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' But when i am trying to run the sample, i am getting the following error in the Event Viwer Kindly help me on this
6
7312
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 possibility of shutting logging down at compile time and suffer no performance penalty whatsoever for getting logging on whenever I wish. Of course that I would need to recompile the project each time I want to turn logging on or off. But given a...
23
2207
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 %(function)s, which results in the name of the entity which logged the record. My version even deduces the class name in the case which the logger is a bound method, and assuming the name of the "self" variable is indeed "self".
6
10267
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 Instance:lzgneu Node:000 PID:1293(db2loggw (TELEMATX)) TID:1024 Appid:none data protection sqlpgwlp Probe:909 TailPage 0 does not match pagelsn 0023CEBF0FFB and firstlsn 0023CEBF8000
0
1849
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 want to put this comment and a alternative most simple default framework for discussion. Maybe there are more Python users which like to see that imported (managed) logging issue more down-to-earth and flexible ? ... Vinay Sajip wrote: >...
0
2099
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 logging to event log. To make it active again I need to open the web.config and save without making any changes. It starts to work again. Here is the configuration I am using. <exceptionHandling>
3
11527
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 logging system will create a default logger that *also* emits logs, which I can't seem to get rid of. Is there a way I can suppress the creation of this default logger, or remove it when I 'm setting up my handlers? Thanks. Sample code:
3
6410
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 logging.config.fileConfig() function. Let say my logging class is called "MyLogHandler" and it's in a module called "mylogmodule", I want to be able to make an entry something like this in my logging config file:
4
1613
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() to configure a log file, and then calling logging.getLogger('').addHandler(console) to add the console. However, in section 14.5.4 (Sending and receiving logging events across a network), a call is made to rootLogger.addHandler(socketHandler),...
0
7880
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8010
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8242
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6665
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5413
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3868
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.