473,403 Members | 2,222 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,403 software developers and data experts.

Error Using LookupPrivilegeValue(...)

I used DllImport() to load the function
LookupPrivilegeValue() in advapi32.dll, and then called
it in my button click event. But the function always
returns false. I got the error code it left through
GetLastError() function and the result is "997" which
means, in the system error code in MSDN, "Overlapped I/O
operation is in progress." I don't know what's wrong with
it. The calling code is as below:
--------------------------------
OpenProcessToken(NULL,
SE_SHUTDOWN_NAME,
&Luid))
--------------------------------
Here SE_SHUTDOWN_NAME is "SeShutdownPrivilege", and the
type of Luid is long.

Please help me, and thanks a lot :)

Nov 17 '05 #1
3 4537
Liang,

Are you using the SetLastError property of the DllImport attribute, and
the System::Runtime::InteropServices::Marshall::GetLas tWin32Error
method? Do not use GetLastError with P/Invoke.

Also: I assume you meant to write LookupPrivilegeValue instead of
OpenProcessToken?

Bart Jacobs

Liang Yitao wrote:
I used DllImport() to load the function
LookupPrivilegeValue() in advapi32.dll, and then called
it in my button click event. But the function always
returns false. I got the error code it left through
GetLastError() function and the result is "997" which
means, in the system error code in MSDN, "Overlapped I/O
operation is in progress." I don't know what's wrong with
it. The calling code is as below:
--------------------------------
OpenProcessToken(NULL,
SE_SHUTDOWN_NAME,
&Luid))
--------------------------------
Here SE_SHUTDOWN_NAME is "SeShutdownPrivilege", and the
type of Luid is long.

Please help me, and thanks a lot :)


Nov 17 '05 #2
Liang,
I used DllImport() to load the function
LookupPrivilegeValue() in advapi32.dll, and then called
it in my button click event. But the function always
returns false. I got the error code it left through
GetLastError() function and the result is "997" which
means, in the system error code in MSDN, "Overlapped I/O
operation is in progress." I don't know what's wrong with
it. The calling code is as below:
--------------------------------
OpenProcessToken(NULL,
SE_SHUTDOWN_NAME,
&Luid))
--------------------------------
Here SE_SHUTDOWN_NAME is "SeShutdownPrivilege", and the
type of Luid is long.

If you're using DllImport instead of using IJW, then make sure you set the
SetLastError property of the DllImport attribute to true. You'd probably be
better off then calling Marshal.GetLastWin32Error() instead of
GetLastError().

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #3
Oh, yes. I made a mistake ^_^
Thank you for your reply, and I'll try to do it in your
way.
-----Original Message-----
Liang,

Are you using the SetLastError property of the DllImport attribute, andthe System::Runtime::InteropServices::Marshall::GetLas tWin32Er
rormethod? Do not use GetLastError with P/Invoke.

Also: I assume you meant to write LookupPrivilegeValue instead ofOpenProcessToken?

Bart Jacobs

Liang Yitao wrote:
I used DllImport() to load the function
LookupPrivilegeValue() in advapi32.dll, and then called it in my button click event. But the function always
returns false. I got the error code it left through
GetLastError() function and the result is "997" which
means, in the system error code in MSDN, "Overlapped I/O operation is in progress." I don't know what's wrong with it. The calling code is as below:
--------------------------------
OpenProcessToken(NULL,
SE_SHUTDOWN_NAME,
&Luid))
--------------------------------
Here SE_SHUTDOWN_NAME is "SeShutdownPrivilege", and the type of Luid is long.

Please help me, and thanks a lot :)


.

Nov 17 '05 #4

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

Similar topics

5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
4
by: Mohammed Abdel-Razzak | last post by:
Dear sirs I want to know how can I shutdown or restart my computer using C# Also I want to know how can I open any windows program using C# (EX: opening the windows calculator from my...
2
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess,...
1
by: plmanikandan | last post by:
Hi, I am using LookupPrivilegeValue to check whether SE_TCB_NAME privilege exists for the user or not in windows 2000 .The value returned from LookupPrivilegeValue function is always true.i...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
0
by: =?Utf-8?B?c2po?= | last post by:
Writing an app in VB.NET 2005 which needs to load a registry hive. As far as I can determine, there isn't any managed code to do this (sigh), so I need to revert to APIs. Additional privileges...
0
by: remya1000 | last post by:
i'm using VB.NET. i wrote a Auto Reboot program. and here is the codes i tried... Code: Private Enum ShutDown1 LogOff = 0 Shutdown = 1 Reboot = 2 ...
4
by: HumSupLow69 | last post by:
Here is my code... #include <windows.h> #include <iostream> int main() { DWORD pId; HWND hWnd; HANDLE hMine; do {
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
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...
0
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...
0
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...
0
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...

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.