Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages
Started by Jos�
Mon, 11 Feb 2008 17:26
Shutting down
Author: Jos�
Date: Mon, 11 Feb 2008 17:26
Date: Mon, 11 Feb 2008 17:26
34 lines
1919 bytes
1919 bytes
Some time ago I asked how to shut down my computer. I thought it
worked, but after all it apears there is something wrong with
privileges. After reading help files and websites, I wrote this:
TOKEN_PRIVILEGES tp;
HANDLE hToken;
LUID luid;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
tp.Privileges[0].Attributes = 0;
LookupPrivilegeValue(
NULL, // lookup privilege on local system
"SE_SHUTDOWN_NAME", // privilege to lookup
&luid ) ; // receives LUID of privilege
AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
ExitWindowsEx(EWX_POWEROFF,0);
I think the trouble is the first parameter of AdjustTokenPrivileges,
which, according to the help file "TokenHandle identifies the access
token that contains the privileges to be modified". That's Greek to
me.
--
Jos�
Re: Shutting down
Author: Remy Lebeau (TeamB)
Date: Mon, 11 Feb 2008 18:25
Date: Mon, 11 Feb 2008 18:25
27 lines
2038 bytes
2038 bytes
"Jos�" <jose@127.0.0.1> wrote in message
news:nr01r35bb4etpk28l2uf89a7f01bvlvsqk@4ax.com...
> LookupPrivilegeValue(
> NULL, // lookup privilege on local system
> "SE_SHUTDOWN_NAME", // privilege to lookup
> &luid ) ; // receives LUID of privilege
SE_SHUTDOWN_NAME is a precompiler macro, not a string. The actual string
value is "SeShutdownPrivilege". To use SE_SHUTDOWN_NAME, you need to get
rid of the quotation marks, ie:
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid);
> I think the trouble is the first parameter of AdjustTokenPrivileges,
> which, according to the help file "TokenHandle identifies the access
> token that contains the privileges to be modified". That's Greek to
> me.
You need to use OpenThreadToken() and/or OpenProcessToken() to get the
required access token. I suggest you go to http://www.deja.com and search
through the newsgroup archives. Examples of using AdjustTokenPrivileges()
have been posted many times before.
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads