CreateProcessAsUser and Windows Vista trouble



I run under SYSTEM account the code posted below. My goal is run an
executable in a specific user context.
With Windows XP works fine but with Vista the executable doesn't run. anyone
can help me?

Thanks very much.

Here is the code:
-----------------------------------------------------------------

Public Sub createProcess(ByVal Percorso As String, ByVal Parametri As
String, ByVal Utente As String)

Dim server As IntPtr = IntPtr.Zero
Dim token As IntPtr = IntPtr.Zero

server = OpenServer("localhost")

Dim ppSessionInfo As IntPtr = IntPtr.Zero

Dim count As Int32 = 0
'gets the session ID
Dim retval As Int32 = WTSEnumerateSessions(server, 0, 1,
ppSessionInfo, count)

Dim sa As New SECURITY_ATTRIBUTES()
Dim pi As New PROCESS_INFORMATION()
Dim si As New STARTUPINFO()


For Each sessionID As UInt32 In ListSessions()
Dim ppBuffer As System.IntPtr
Dim pBytesReturned As UInteger
WTSQuerySessionInformation(OpenServer("localhost"), sessionID,
WTS_INFO_CLASS.WTSUserName, ppBuffer, pBytesReturned)
Dim WTSUserName As String = Marshal.PtrToStringAnsi(ppBuffer)


If WTSUserName = Utente Then

Dim gotToken As Boolean = WTSQueryUserToken(sessionID, token)
Dim pSecurityAttributes As SECURITY_ATTRIBUTES
pSecurityAttributes.bInheritHandle = True
pSecurityAttributes.Length =
Marshal.SizeOf(pSecurityAttributes)
pSecurityAttributes.lpSecurityDescriptor = IntPtr.Zero

Dim tokenDup As IntPtr = IntPtr.Zero
DuplicateTokenEx(token, MAXIMUM_ALLOWED,
pSecurityAttributes, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation,
TOKEN_TYPE.TokenPrimary, tokenDup)

CreateProcessAsUser(tokenDup, Percorso, Percorso & " " &
Parametri, pSecurityAttributes, pSecurityAttributes, False, 0, IntPtr.Zero,
My.Application.Info.DirectoryPath, si, pi)
MsgBox((New
System.ComponentModel.Win32Exception).Message)
Exit For
End If
Next

End Sub
.



Relevant Pages

  • Virtual memory C++ problem
    ... (ByVal hWnd As IntPtr, _ ... (ByVal hWndParent As IntPtr, _ ... ByVal lParam As String) As Integer ... Dim aihWnds As ArrayList ...
    (microsoft.public.win32.programmer.kernel)
  • VirtualAllocEx returns a bad pointer in some processes
    ... (ByVal hWnd As IntPtr, _ ... (ByVal hWndParent As IntPtr, _ ... ByVal lParam As String) As Integer ... Dim aihWnds As ArrayList ...
    (microsoft.public.vc.mfc)
  • SetPrinter for network printers
    ... Public dmDeviceName As String ... Public pSecurityDescriptor As IntPtr ... Dim pPrinterInfo As IntPtr ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MapiSendMail and web browser
    ... Public Shared Function SendMail(ByVal strAttachmentFileName As String, ... Dim winhandle As IntPtr = New IntPtr ... Public Class MapiMessage ...
    (microsoft.public.win32.programmer.messaging)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)

Loading