I am having some issues, when I try to launch another process using
Process.Start(P rocessStartInfo psi) on win xp sp2 box (Other versions
of xp have no issue).
Here is the detail.
Main app checks for updates on startup and if updates are available, it
launches separate exe to copy files.
Before launching new process(exe), I am impersonating admin user as
main app is being launched by non-admin user.
User identity is changed after impersonation, but during update,
"Access is denied" win32Exception is being thrown when main code tries
to launch copier exe.
Impersonation is implemented using following win32 api.
<code>
string domainName = string.Empty;
try
{
// Get current windows identity
string currentWindowsI dentity = WindowsIdentity .GetCurrent().N ame;
domainName = currentWindowsI dentity.Substri ng(0,
currentWindowsI dentity.IndexOf ('\\'));
const int LOGON32_PROVIDE R_DEFAULT = 0;
//This parameter causes LogonUser to create a primary token.
const int LOGON32_LOGON_I NTERACTIVE = 2;
const int SecurityImperso nation = 2;
tokenHandle = IntPtr.Zero;
dupeTokenHandle = IntPtr.Zero;
// Call LogonUser to obtain a handle to an access token.
bool returnValue = LogonUser(_impe rsonationUserna me,
domainName,_imp ersonationPassw ord, LOGON32_LOGON_I NTERACTIVE,
LOGON32_PROVIDE R_DEFAULT,ref tokenHandle);
if (false == returnValue)
{
int ret = Marshal.GetLast Win32Error();
int errorCode = 0x5; //ERROR_ACCESS_DE NIED
throw new System.Componen tModel.Win32Exc eption(errorCod e);
}
// Check the identity.
bool retVal = DuplicateToken( tokenHandle, SecurityImperso nation, ref
dupeTokenHandle );
if (false == retVal)
{
CloseHandle(tok enHandle);
return;
}
// The token that is passed to the following constructor must
// be a primary token in order to use it for impersonation.
WindowsIdentity newId = new WindowsIdentity (dupeTokenHandl e);
_impersonatedUs er = newId.Impersona te();
}
catch(Exception ex)
{
}
</code>
I have enabled following security policies for non-admin user:
1) Replace a process level token.
2) Debug programs
3) Adjust memory quotas for a process
NOTE: 'Launching another exe' works fine, if no user impersonation is
used.
Any ideas, what might be wrong ?
~ViPuL 27 6712
I can't answer your question for you, but have you considered using
ClickOnce Deployment instead of your current method of checking for
updates? Then you wouldnt even need to bother with this whole issue.
Well, we are still using .net 1.1 sp1. So ClickOnce is not a option...:(
Following is the Detail Exception ia m getting:
Exception: System.Componen tModel.Win32Exc eption
Message: Access is denied
Source: System
at System.Diagnost ics.ProcessMana ger.OpenProcess (Int32 processId,
Int32 access, Boolean throwIfExited)
at System.Diagnost ics.NtProcessMa nager.GetModule Infos(Int32
processId)
at System.Diagnost ics.Process.get _Modules()
at System.Diagnost ics.Process.get _MainModule()
Help!!!!!!!!!!! !!
~ViPuL
"vipleo" <vn*****@gmail. com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
| Following is the Detail Exception ia m getting:
|
| Exception: System.Componen tModel.Win32Exc eption
| Message: Access is denied
| Source: System
| at System.Diagnost ics.ProcessMana ger.OpenProcess (Int32 processId,
| Int32 access, Boolean throwIfExited)
| at System.Diagnost ics.NtProcessMa nager.GetModule Infos(Int32
| processId)
| at System.Diagnost ics.Process.get _Modules()
| at System.Diagnost ics.Process.get _MainModule()
|
| Help!!!!!!!!!!! !!
| ~ViPuL
|
And the code that throws this exception?
Willy.
Here is the code I am using for launching another exe.
ProcessStartInf o proc = new ProcessStartInf o(CopierExecuta ble,
commandLine);
proc.WorkingDir ectory = ClientAppDirect ory;
proc.UseShellEx ecute = true; //I have also tried 'False'
Process.Start(p roc);
Here, CopierExecutabl e represents name of exe.
~ViPuL
Here is complete function:
private void LaunchCopierExe cutable()
{
string filePath = Path.Combine(Cl ientAppDirector y, CopierExecutabl e);
if (!File.Exists(f ilePath))
{
throw new ApplicationExce ption("Invalid CopierExecutabl e config
setting: " + CopierExecutabl e);
}
string commandLine = "appdir='" + ClientAppDirect ory + "';upddir=' " +
ClientUpdatesDi rectory + "';bakdir=' " + ClientBackupDir ectory
+ "';procid=" + Process.GetCurr entProcess().Id + ";exe='" +
Process.GetCurr entProcess().Ma inModule.FileNa me + "';timeoutsecs= " +
MainAppShutdown Seconds.ToStrin g() + ";";
if (_returnParms.L ength > 0)
{
string sc = _returnParms.Su bstring(_return Parms.Length - 1, 1);
if( sc != ";") //add semi-colon
commandLine += "returnparm s='" + _returnParms + "';";
else
commandLine += "returnparm s='" + _returnParms + "'";
}
ProcessStartInf o proc = new ProcessStartInf o(CopierExecuta ble,
commandLine);
proc.WorkingDir ectory = ClientAppDirect ory;
proc.UseShellEx ecute = true;
Process.Start(p roc);
}
That looks much better.
Your problem is that you are trying to get some information from the current
process (MainModule) while impersonating. This is not possible because your
thread runs in an impersonated context, so you don't have access to the
process context.
What you should do is get this info before impersonating.
Willy.
"vipleo" <vn*****@gmail. com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
| Here is complete function:
|
| private void LaunchCopierExe cutable()
| {
| string filePath = Path.Combine(Cl ientAppDirector y, CopierExecutabl e);
| if (!File.Exists(f ilePath))
| {
| throw new ApplicationExce ption("Invalid CopierExecutabl e config
| setting: " + CopierExecutabl e);
| }
|
| string commandLine = "appdir='" + ClientAppDirect ory + "';upddir=' " +
| ClientUpdatesDi rectory + "';bakdir=' " + ClientBackupDir ectory
| + "';procid=" + Process.GetCurr entProcess().Id + ";exe='" +
| Process.GetCurr entProcess().Ma inModule.FileNa me + "';timeoutsecs= " +
| MainAppShutdown Seconds.ToStrin g() + ";";
|
| if (_returnParms.L ength > 0)
| {
| string sc = _returnParms.Su bstring(_return Parms.Length - 1, 1);
| if( sc != ";") //add semi-colon
| commandLine += "returnparm s='" + _returnParms + "';";
| else
| commandLine += "returnparm s='" + _returnParms + "'";
| }
|
| ProcessStartInf o proc = new ProcessStartInf o(CopierExecuta ble,
| commandLine);
| proc.WorkingDir ectory = ClientAppDirect ory;
| proc.UseShellEx ecute = true;
| Process.Start(p roc);
| }
|
Thanks for reply, willy.
But why this would be problem on win xp sp2 only.
Thanks,
~ViPuL
"vipleo" <vn*****@gmail. com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
| Thanks for reply, willy.
|
| But why this would be problem on win xp sp2 only.
|
| Thanks,
| ~ViPuL
|
Different user privileges? Changes in SP2?
A process con only be 'opened' by the owner or by a caller with debug
provileges.
What I saw in your stack dump was that the caller did not have the requied
provileges to open the process:
<
Message: Access is denied
Source: System
at System.Diagnost ics.ProcessMana ger.OpenProcess (Int32 processId,
Int32 access, Boolean throwIfExited)
now I know why, the impersonating user is not the "owner" and he does not
have the required access privileges.
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Meier |
last post by:
Hi,
is it possible to get the environment variables for users other than the
user that is currently executing the application?
For example if I run a system service, how can the service find the
SpecialFolder.InternetCache of a certain user?
Thanks for input. Dave.
|
by: Markus Stehle |
last post by:
Hi all!
I have asp.net web application that uses static impersonation. Is it
possible to change the impersonated user during runtime? Within some parts
of my application I would like to impersonate another user in order to
access certain ressources and then switch back to the originally
impersonated user. How can I do this?
Thanks
|
by: Razak |
last post by:
Hi,
I have a class which basically do Impersonation in my web application. From
MS KB sample:-
++++++++++++++++++++code starts
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
|
by: RTT |
last post by:
i'm writing a windows form but codebased a iwant to run the code as a
different user.
like in a webapplication you can impersonate a user so the website does not
run on the standard ASP.NET user.
is it possible to do the same for a windows form and define a user codebased
and run the code like that user is running the application.
|
by: CJM |
last post by:
I use the following technique to impersonate a user in ASP, in order to
query active directory:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;248187
Although the article indicates that this technique is supported by IIS4 &
IIS5, I actually run it successfully on Windows Server 2003 (IIS6).
However, I've got a new development machine which is running XP Pro x64
Edition, and now this technique doesnt work ('Cannot create...
| |
by: John.NET |
last post by:
Hi,
First please forgive that this is a repost as the first time I didn't have
my proper nospam email configured...
I'm writing a web service where one method will launch another .NET program
under a specified user's account. It launches fine as the NT
AUTHORITY\NETWORK SERVICE user when I dont specify a username/password for
the ProcessStartInfo but I am having trouble getting it to work when I
specify any other username/password...
|
by: Dmitry |
last post by:
I am trying to figure out how to pass set of credentials to System.IO
Challenge is:
App is running under one set of credentials, but via GUI user have a chance
to enter another set. I would like to be able to use supplied credentials
with System.IO versus using default credentials that app is running under.
So far I am forced to use WMI which is less convenient and slower then
System.IO, but it's providing me with "Connection Options"
|
by: Daniel Knöpfel |
last post by:
Hello
On our asp.net 2.0 website we impersonate every request to the identity of
the user logged in. This works this way:
1. user logs in, providing username, password
2. user is authenticated against an active directory and the windows
identity is retrieved (and stored in the session!!)
3. user is impersonated using the windows identity (thread is now
running under the identity of the user)
|
by: =?Utf-8?B?QXZhRGV2?= |
last post by:
ASP.Net 2.
We are migrating to Windows 2008 64 bit Server with IIS 7 from Windows 2003
32 Bit with IIS 6. A few library classes we wrote uses impersonation in code
like explained in this article:
http://support.microsoft.com/?id=306158#4
This doesn't work in Windows 2008 Server, we receive the following exception:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |