473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CreateProcessAsUser() - 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

Jul 29 '08 #1
0 1910

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pete Fong | last post by:
Dear all, I am a beginner with Python. I want to write a program as "runas" in Windows XP. But I have got the following error: File...
3
by: Bo | last post by:
In my asp.net webservice application, I need to launch a DOS process as authorized users. To impersonate users, I use <impersonation = true> in my webconfig. I can't use Diagnostics.Process.Start,...
1
by: Jay | last post by:
Hey There, I am trying to execute the CreateProcessAsUser function, but when I do, I get this error: "Cannot create a file when that file already exists.". What would cause that error to occur in...
9
by: salad | last post by:
Due to an earlier posting I read in this newsgroup regarding Office 2007 beta, I downloaded it. After I DL'd it, I got an invitation from MS to get WinVista. I am now wondering if, since both...
6
by: j2ee.singh | last post by:
Hi, I'm looking to buy a new laptop primarily to learn & practice .NET and C#. My Question is: Is there any requirement for .NET and C# in terms of the following Operating Systems: -...
19
by: =?Utf-8?B?TWlrZTk5MDA=?= | last post by:
When there is a shortcut of our app on the desctop, the app is not run until all the security in control panel of win vista is cleared. What to do to not have this problem. We do not want to tell...
2
by: mindspring | last post by:
A pc that was created in MS office xp's Access 2002 has been working fine on a windows vista Ultimate pc that has MS OFfice Vista Edition. But all of the sudden it stopped working and gives this...
0
by: EricBlair | last post by:
Hello, I wrote a windows service that is supposed to start an interactive GUI app. I realize a service will not readily do this so I've pieced together the code below to bypass that. However, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.