Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Win API / July 2008



Tip: Looking for answers? Try searching our database.

CreateProcessAsUser and Windows Vista trouble

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bobil - 29 Jul 2008 12:13 GMT
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
expvb - 29 Jul 2008 14:06 GMT
> System.ComponentModel.Win32Exception).Message)

You seem to be using dotnet. Quote from someone else:

[Canned response]
This is a VB "classic" newsgroup. Questions about VB.NET (including VB
2005/2008 and VB Express, which have dropped .NET from their names) are
off-topic here.

Please ask .NET questions in newsgroups with "dotnet" in their names. The
*.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.*
groups on your news server, connect directly to the Microsoft server:
msnews.microsoft.com.

For questions specific to the VB.NET language, use this group:
microsoft.public.dotnet.languages.vb

Please note that things like controls and data access, which have their own
subgroups in the Classic VB hierarchy, are not language-specific in .NET, so
you should look for groups like these:
microsoft.public.dotnet.framework.windowsforms.controls
microsoft.public.dotnet.framework.adonet
(Note that "vb" is not present in the group name.)
Bobil - 29 Jul 2008 15:03 GMT
OK, thanks

> > System.ComponentModel.Win32Exception).Message)
>
[quoted text clipped - 19 lines]
> microsoft.public.dotnet.framework.adonet
> (Note that "vb" is not present in the group name.)
fixitchris - 31 Jul 2008 21:03 GMT
Bobil,

There are extra calls needed on Vista to obtain info about Session0 for
SYSTEM.  You will need to Google the answer.
fixitchris - 31 Jul 2008 21:08 GMT
Sorry, didn't look through the code... try different
SECURITY_IMPERSONATION_LEVEL on duplicatetoken call.  

Where does the code fail?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.