Requesting debug privileges

Share your advanced PureBasic knowledge/code with the community.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Requesting debug privileges

Post by Mistrel »

source: http://www.experts-exchange.com/Program ... 03461.html

Code: Select all

#SE_DEBUG_NAME="SeDebugPrivilege" ; missing constant

Procedure EnableDebugPrivNT()
	DebugValue.LUID;
	tkp.TOKEN_PRIVILEGES
	
	; Retrieve a handle of the access token
	If Not OpenProcessToken_(GetCurrentProcess_(),#TOKEN_ADJUST_PRIVILEGES|#TOKEN_QUERY,@hToken)
		ProcedureReturn #False;
	EndIf
	
	; Enable the SE_DEBUG_NAME privilege
	If Not LookupPrivilegeValue_("",#SE_DEBUG_NAME,@DebugValue)
		ProcedureReturn #False;
	EndIf
	
	NewState.TOKEN_PRIVILEGES
	NewState\PrivilegeCount=1
	NewState\Privileges[0]\Luid\HighPart=DebugValue\HighPart
	NewState\Privileges[0]\Luid\LowPart=DebugValue\LowPart
	NewState\Privileges[0]\Attributes=#SE_PRIVILEGE_ENABLED
	AdjustTokenPrivileges_(hToken,#False,@NewState,SizeOf(TOKEN_PRIVILEGES),@PreviousState.TOKEN_PRIVILEGES,@ReturnLength)
	
	If GetLastError_()<>#ERROR_SUCCESS
		ProcedureReturn #False
	EndIf

	ProcedureReturn #True
EndProcedure
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Hey, would this allow shadowcopying as well?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

blueznl wrote:Hey, would this allow shadowcopying as well?
I'm not familiar with shadow copying. You'll have to try it yourself.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Shadow copying is a point-in-time snapshot of a shared folder that is exposed to Windows uers by use of the "Previous Versions" tab on a shared file. Its present in Windows 2003 and Windows XP SP1 and greater. Also, if i'm not mistaken you can add it to Windows 2000 but i'm not sure.
Post Reply