Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-2007, 11:41 AM
Jophry Jophry is offline
Newbie
 
Join Date: Jan 2007
Posts: 1
Rep Power: 0
Jophry is on a distinguished road
Default What is wrong with this code convertion ?

Hi
I have this code in c++, and I want to gain full access over an application.
Code:
HANDLE hToken; 
TOKEN_PRIVILEGES tkp; 
 
// Get a token for this process. 
if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
	return FALSE;
 
// Get the LUID for the shutdown privilege. 
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid); 
tkp.PrivilegeCount = 1;  // one privilege to set    
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
 
// Get the shutdown privilege for this process. 
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
and it works, but here comes my problem.
I want to convert this code to Pascal. All functions return true, but a call of GetLastError() just after AdjustTokenPrivileges() gives me an errorcode 1300 ( Not all privileges or groups referenced are assigned to the caller ). So what do I do wrong ?
Here's my code ( in Pascal )
Code:
 var
  hToken : handle;
  tp: TOKEN_PRIVILEGES;

   OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, @hToken);
   LookupPrivilegeValue( NULL, SE_DEBUG_NAME, @tp.Privileges[0].LUID );
   tp.PrivilegeCount := 1;
   tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
   AdjustTokenPrivileges( hToken, FALSE, @tp, sizeof(TOKEN_PRIVILEGES), 0, 0 );
   GetLastError(); // <- Returns 1300 :/
So please help me. What is wrong here I've compiled this code by using Dev-Pas v1.9.2.

Last edited by Jophry; 01-03-2007 at 01:47 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 01-04-2007, 12:10 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 1,953
Last Blog:
NaNoWriMo Day 15
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

Not seeing how AdjustTokenPrivileges or GetLastError are implemented, it's kind of tough to say.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code: Capture Code from USB Camera MrNobody VB Tutorials 44 07-28-2008 07:29 PM
Basic Calculator AfTriX VB Tutorials 3 02-29-2008 08:53 AM
Please Help With A C Program!! siren C and C++ 7 04-17-2007 08:45 AM
Where to Put PHP Code clookid PHP Tutorials 1 01-11-2007 08:44 PM


All times are GMT -5. The time now is 10:22 AM.

Contest Stats

John ........ 203.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 63%

Ads