473,666 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Programm - Shutdown win2k

Hi at all,

I've got this function (written in BC++)

bool TShutdown::MySy stemShutdown()
{
HANDLE hToken;
TOKEN_PRIVILEGE S tkp;

// Get a token for this process.

if (!OpenProcessTo ken(GetCurrentP rocess(),
TOKEN_ADJUST_PR IVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );

// Get the LUID for the shutdown privilege.

LookupPrivilege Value(NULL, SE_SHUTDOWN_NAM E,
&tkp.Privile ges[0].Luid);

tkp.PrivilegeCo unt = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_EN ABLED;

// Get the shutdown privilege for this process.

AdjustTokenPriv ileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILE GES)NULL, 0);

if (GetLastError() != ERROR_SUCCESS)
return FALSE;

// Shut down the system and force all applications to close.

if (!ExitWindowsEx (EWX_SHUTDOWN | EWX_FORCE, 0))
return FALSE;

return TRUE;
}

Now my problem. When I execute this funtion on my Laptop, running with
WinXP, my Laptop shuts
down and switchs off.

On my other system, running with win2k, win2k shut down, but the PC didn't
switch off. My Mainboard
supports this function. When I click at 'Start', 'Shutdown', the PC switchs
off, after shutdown. Why
dosen't it switch off, when I run my Function?! Can anyone help me?
Or can anyone tell me an other way, to realize that?!

THX a lot!!!

(The function isn't written by myself, I found it at the WWW)

Sorry for my bad english...

Andreas
Jul 22 '05 #1
2 2492
"Andreas Horneff" <G.**********@g mx.de> wrote in message
news:cf******** *****@news.t-online.com...
Hi at all,

I've got this function (written in BC++)

bool TShutdown::MySy stemShutdown()
{
HANDLE hToken;
TOKEN_PRIVILEGE S tkp;

// Get a token for this process.

if (!OpenProcessTo ken(GetCurrentP rocess(),
TOKEN_ADJUST_PR IVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );

// Get the LUID for the shutdown privilege.

LookupPrivilege Value(NULL, SE_SHUTDOWN_NAM E,
&tkp.Privile ges[0].Luid);

tkp.PrivilegeCo unt = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_EN ABLED;

// Get the shutdown privilege for this process.

AdjustTokenPriv ileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILE GES)NULL, 0);

if (GetLastError() != ERROR_SUCCESS)
return FALSE;

// Shut down the system and force all applications to close.

if (!ExitWindowsEx (EWX_SHUTDOWN | EWX_FORCE, 0))
return FALSE;

return TRUE;
}

Now my problem. When I execute this funtion on my Laptop, running with
WinXP, my Laptop shuts
down and switchs off.

On my other system, running with win2k, win2k shut down, but the PC didn't
switch off. My Mainboard
supports this function. When I click at 'Start', 'Shutdown', the PC switchs off, after shutdown. Why
dosen't it switch off, when I run my Function?! Can anyone help me?
Or can anyone tell me an other way, to realize that?!

THX a lot!!!

(The function isn't written by myself, I found it at the WWW)

Sorry for my bad english...

Andreas


Hello Andreas,

I would suggest that you re-post this question to
microsoft.publi c.win32.program mer.kernel.

Here C++ (not related to OS) topics are discussed.

--
Elias
Jul 22 '05 #2
On Mon, 16 Aug 2004 12:10:40 +0200, "Andreas Horneff"
<G.**********@g mx.de> wrote in comp.lang.c++:

The fastest way to shut down any version of Windows is to open email
in Outlook Express.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #3

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

Similar topics

6
3217
by: TIM | last post by:
for example i have one simple programm int main() { int test = NULL; while(1){ printf("%d\n",test); getch(); test++; }
6
5153
by: Ana | last post by:
Hi! I have problems with the following scenario: My application is developed using C# under .NET. It must run on all Windows versions starting from Windows 98. The user must open different documents (txt, MS Office files, pdf, pictures,…) from inside my app. It must start the file with the adequate external program (Notepad, MS Office programs, Acrobat Reader, some Picture viewer,... ) and be notified when this programs closes the...
83
7809
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face some other ploblems which i can not correct.I would appreciated if someone take a look at my programm so as to help me.I tried many times to find out where my mistakes are but i didn't manage something. I have made some comments due to the programm...
5
6639
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed another program that executes it as a child process using popen2.Popen4(). I was attempting to use signals to stop it (using os.kill()) but I keep running into a problem where sending the signal causes an infinite loop of printing the message...
0
8454
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8878
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8785
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8644
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
7389
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...
1
6200
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
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
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.