473,382 Members | 1,425 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,382 software developers and data experts.

CreateProcessWithLogon and managed Processes

Sample code below:

Dim iRet As Integer
Dim si As New STARTUPINFO
Dim pi As PROCESS_INFORMATION

si.cb = Marshal.SizeOf(si)

iRet = CreateProcessWithLogonW(UserName, DomainName, Password, _
LOGON_WITH_PROFILE, Nothing, CommandLine, _
NORMAL_PRIORITY_CLASS, 0, StartIn, si, pi)

If iRet = 0 Then
Throw New System.ComponentModel.Win32Exception
Else
Try
p = Process.GetProcessById(pi.dwProcessId)
AddHandler p.Exited, AddressOf ProcessExitHandler
p.EnableRaisingEvents = True

Catch ex As ArgumentException
'Process ID no longer exists. Don't worry about it.
End Try

CloseHandle(pi.hThread)
CloseHandle(pi.hProcess)

End If

CreateProcessWithLogonW is called with credentials for an account belonging
to the Administrators group. The code above is run from a non-administrative
account. The problem is, I cannot get the managed Process class to access
any of the exit information for the process. Setting EnableRaisingEvents
generates another Win32Exception, as well as calling WaitForExit or checking
the HasExited property of the process class.

Is there any way to check the exit state of the process in this situation?
I have other code that needs to execute, but only after the process has
finished.

Thanks!
Sep 15 '05 #1
3 5130
Hi

What is the concret win32exception do you get?

Is it similar with below?

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.ComponentModel.Win32Exception: Access is denied
If so I think it is because the user accout did not have the enough
privilegeto open the process.
In the underlying level, the Process class will try to call the OpenProcess
API so that it can monitor the Process status.

You can look into the OpenProcess API in MSDN.
Remarks
To open a handle to another another process and obtain full access rights,
you must enable the SeDebugPrivilege privilege. For more information, see
Changing Privileges in a Token.

The handle returned by the OpenProcess function can be used in any function
that requires a handle to a process, such as the wait functions, provided
the appropriate access rights were requested.

When you are finished with the handle, be sure to close it using the
CloseHandle function.

I think you may try to Impersonalte the administrator account to do the
privilege job.
319615 PRB: "Unable to Impersonate User" Error Message When You Use
http://support.microsoft.com/?id=319615

248187 How to impersonate a user from Active Server Pages
http://support.microsoft.com/?id=248187
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 16 '05 #2
I also managed to get it to work as needed by calling the native
WaitForSingleObject using the process handle. This caused my current thread
to wait until the process had completed, then I was able to fire an event
after that call to do what I need.

Thanks for the help!
Sep 16 '05 #3
Hi

I am glad that you have figured out the problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 17 '05 #4

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

Similar topics

4
by: Vincent Finn | last post by:
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...
0
by: Nick | last post by:
Replying to x-post "Nick" <someone@somewhere.com> wrote in message news:ehLJlC52EHA.1564@TK2MSFTNGP09.phx.gbl... > Hi all, > > Using the .NET fx configuration utility, mscorcfg is it possible...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
0
by: Vincent Finn | last post by:
Hi, I am trying to use CreateProcessWithLogon in VB.net My code works fine when on a WinXP machine but fails on a Win2000 machine The error is "Object reference not set to an instance of...
3
by: Eric Livingston | last post by:
Sample code below: Dim iRet As Integer Dim si As New STARTUPINFO Dim pi As PROCESS_INFORMATION si.cb = Marshal.SizeOf(si) iRet = CreateProcessWithLogonW(UserName, DomainName, Password, _...
35
by: Carl J. Van Arsdall | last post by:
Alright, based a on discussion on this mailing list, I've started to wonder, why use threads vs processes. So, If I have a system that has a large area of shared memory, which would be better? ...
5
by: Newbie Coder | last post by:
Can anyone convert this to managed C++.NET 2003? Private Function PrevInstance() As Boolean If UBound(System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Proc...
3
by: adimangla | last post by:
Hi :-) I am creating a software that will save the present state of all the applications running on the desktop (WinXP). Can anyone point out the method to extract the filenames from the...
2
by: =?Utf-8?B?UG1hX1NoYW5l?= | last post by:
I am wring asp webservices in managed c++ for IIS 5.1 runing on XP SP2. Even though I set the aplication protection to High (Isolated), each service seems to run in the same process. I wrote a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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...

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.