PC Review


Reply
Thread Tools Rate Thread

CreateProcessWithLogon\AdjustTokenPrivileges on Win2K

 
 
Vincent Finn
Guest
Posts: n/a
 
      22nd Jun 2004
Hi,

I am calling an exe from a webservice
I was using CreateProcessWithLogon() but it doesn't seem to work (MSDN
says it is supported) I get ERROR_ACCESS_DENIED.
It works fine if I am using an XP

Are there permissions that must be set in Win2K to allow this function
to work?

I tried swapping to using LogonUser() and CreateProcessAsUser() but
again they work fine and XP and fail on Win2K
this time the error is ERROR_PRIVILEGE_NOT_HELD

The MSDN says that the user calling LogonUser() needs SE_TCB_NAME
privilege.
I tried setting this and failed (on both OS this time)

The code I am using is in VB.Net below.

Can anyone tell me what I am doing wrong?
Or is there a way to set this without coding i.e. User settings
somewhere?

Vin

private declare Auto Function OpenProcessToken lib "advapi32.dll"
(ByVal ProcessHandle as IntPtr, ByVal DesiredAccess as Integer, ByRef
TokenHandle as IntPtr) as Boolean
private Declare auto Function LookupPrivilegeValue Lib "advapi32.dll"
(lpSystemName As String, lpName As String, ByRef lpLuid As LUID) As
Boolean
private Declare Function AdjustTokenPrivileges Lib "advapi32.dll"
(ByVal TokenHandle As IntPtr, ByVal DisableAllPrivileges As Boolean,
ByRef NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Integer,
ByVal PreviousState As IntPtr, ByVal ReturnLength As IntPtr) As
Boolean

Private Structure TOKEN_PRIVILEGES
public PrivilegeCount as Integer
' have tried variations on this parameter but none of them make
' a difference any array variant won't marshal
public Privileges as LUID_AND_ATTRIBUTES
end Structure
private Structure LUID_AND_ATTRIBUTES
Public Luid As LUID
Public Attributes As Integer
End Structure
private Structure LUID
Public LowPart As Integer
Public HighPart As Integer
End Structure

' Inside the Function
Dim hProc As IntPtr
dim hToken As IntPtr
Dim luid_TCB As LUID
Dim tp As New TOKEN_PRIVILEGES

' get the current process's token
hProc = Process.GetCurrentProcess().Handle
hToken = IntPtr.Zero
If Not OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY,
hToken) Then
throw new Exception(err.LastDllError)
End If

' get the LUID for the TCB privilege (provided it already exist)
luid_TCB.HighPart = 0
luid_TCB.lowPart = 0
If Not LookupPrivilegeValue(Nothing, SE_TCB_NAME, luid_TCB) Then
throw new Exception(err.LastDllError)
End If

tp.PrivilegeCount = 1
tp.Privileges.Luid = luid_TCB
tp.Privileges.Attributes = SE_PRIVILEGE_ENABLED

' enable the privileges
If Not AdjustTokenPrivileges(hToken, False, tp, 0, IntPtr.Zero,
IntPtr.Zero) Then
throw new Exception(err.LastDllError)
End If

dim errorCode as Integer
errorCode = err.LastDllError
' This will equal ERROR_NOT_ALL_ASSIGNED

 
Reply With Quote
 
 
 
 
Vincent Finn
Guest
Posts: n/a
 
      23rd Jun 2004
On Tue, 22 Jun 2004 17:24:22 +0100, Vincent Finn <(E-Mail Removed)> wrote:

>I tried swapping to using LogonUser() and CreateProcessAsUser() but
>again they work fine and XP and fail on Win2K
>this time the error is ERROR_PRIVILEGE_NOT_HELD


I found teh setting for this in the Local Security Settings
and that gets LogonUser() to work but CreateProcessAsUser() gives the
privilege not held error now

Vin
 
Reply With Quote
 
=?Utf-8?B?R2FiaQ==?=
Guest
Posts: n/a
 
      28th Jun 2004
can you wrote how you solved the problem
Thanks

p.s i've got the same problem also


"Vincent Finn" wrote:

> On Tue, 22 Jun 2004 17:24:22 +0100, Vincent Finn <(E-Mail Removed)> wrote:
>
> >I tried swapping to using LogonUser() and CreateProcessAsUser() but
> >again they work fine and XP and fail on Win2K
> >this time the error is ERROR_PRIVILEGE_NOT_HELD

>
> I found teh setting for this in the Local Security Settings
> and that gets LogonUser() to work but CreateProcessAsUser() gives the
> privilege not held error now
>
> Vin
>

 
Reply With Quote
 
Vincent Finn
Guest
Posts: n/a
 
      28th Jun 2004
On Mon, 28 Jun 2004 03:24:02 -0700, "Gabi"
<(E-Mail Removed)> wrote:

>can you wrote how you solved the problem
>Thanks
>
>p.s i've got the same problem also


I haven't solved it.

I am still trying.
I have tried a variety of things and got nowhere so far.

I'll post a solution if I get one, looks like it'll be a nasty hack of
some sort though

Vin
 
Reply With Quote
 
Vincent Finn
Guest
Posts: n/a
 
      30th Jun 2004
On Mon, 28 Jun 2004 03:24:02 -0700, "Gabi"
<(E-Mail Removed)> wrote:

>can you wrote how you solved the problem
>Thanks
>
>p.s i've got the same problem also


I have solved the problem now and it is messy

I had to write a windows service.
This runs under the system account
I call this using a COM function and it then calls
CreateProcessWithLogon

everything works fine on 2000 and XP with this method.
(I am having trouble with 2003 instead but that may something
completely different)

Vin
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Load registry hive (AdjustTokenPrivileges error) =?Utf-8?B?c2po?= Microsoft VB .NET 0 16th Feb 2007 02:10 AM
CreateProcessWithLogon and managed Processes =?Utf-8?B?RXJpYyBMaXZpbmdzdG9u?= Microsoft Dot NET 2 16th Sep 2005 02:10 PM
What is the C# equivalent of the Win32 AdjustTokenPrivileges API =?Utf-8?B?TmFkYXY=?= Microsoft C# .NET 2 17th Nov 2004 03:57 PM
CreateProcessWithLogon on Win2000 Vincent Finn Microsoft VB .NET 0 18th Jun 2004 04:36 PM
CreateProcessWithLogon Vs Runas patanish Microsoft Windows 2000 Developer 1 21st May 2004 08:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:45 AM.