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
Feb 9 '06
27 6714
I agree that the problem he's having right now is not related to the
solution I posted...Your advice of getting the process info before
impersonating is sound. What I'm saying is that even if he fixes his
current issue, a much larger one looms...Once the process is started,
it will be happily running under the process' permissions, not the
impersonated thread's, so he needs to consider another approach
altogether.
Jared
"JaredHite1 " <ja***@sharingd s.org> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
|I agree that the problem he's having right now is not related to the
| solution I posted...Your advice of getting the process info before
| impersonating is sound. What I'm saying is that even if he fixes his
| current issue, a much larger one looms...Once the process is started,
| it will be happily running under the process' permissions, not the
| impersonated thread's, so he needs to consider another approach
| altogether.
|
| Jared
|
That's true, that's why I'm a bit scared when people start to impersonate an
admin, I always wonder why they need it, and most of the time they don't.
The same, here, now I see what the OP is trying to achieve, the only
solution, is or calling "runas.exe" through Process.Start or trying to use
System.Manageme nt and WMI, which is not guaranteed to be succesfull because
of a security issue in v1.1.
Willy.
Interesting points, codefealls..:)
The reason I want to impersonate the admin is that app user doesn't
have write permission on app install dir and app uses auto-update
mechanism to get latest files from network share on start-up. Xcopy of
latest dlls is being done within app; so If exe itself need to be
updated, another copier exe will be launched to finish auto-update.
I didn't get chance to try your suggestion, willy.
I will try it today and post results.
Thanks for your help guys...
~ViPuL
Interesting points, codefealls..:)
The reason I want to impersonate the admin is that app user doesn't
have write permission on app install dir and app uses auto-update
mechanism to get latest files from network share on start-up. Xcopy of
latest dlls is being done within app; so If exe itself need to be
updated, another copier exe will be launched to finish auto-update.
I didn't get chance to try your suggestion, willy.
I will try it today and post results.
Thanks for your help guys...
~ViPuL
Good news & bad news..
Good news first, anothe exe is being launched with willy's suggestion
to get process info before doing impersonation.
But....(bad news begins), exe is getting following exception:
System.TypeInit ializationExcep tion: The type initializer for
"System.Runtime .Remoting.Ident ity" threw an exception. --->
System.Security .Cryptography.C ryptographicExc eption: CryptoAPI
cryptographic service provider (CSP) for this implementation could not
be acquired.
at
System.Security .Cryptography.R NGCryptoService Provider..ctor( CspParameters
cspParams)
at System.Security .Cryptography.R NGCryptoService Provider..ctor( )
at System.Runtime. Remoting.Identi ty..cctor()
--- End of inner exception stack trace ---
at
FHEG.Framework. AppUpdater.Copy FilesDelegate.B eginInvoke(Asyn cCallback
callback, Object object)
at FHEG.Framework. AppUpdater.Prog ressForm.BeginC opy()
at
FHEG.Framework. AppUpdater.Prog ressForm.Progre ssForm_Activate d(Object
sender, EventArgs e)
at System.Windows. Forms.Form.OnAc tivated(EventAr gs e)
at System.Windows. Forms.Form.set_ Active(Boolean value)
at System.Windows. Forms.Form.WmAc tivate(Message& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
"vipleo" <vn*****@gmail. com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
| Good news & bad news..
|
| Good news first, anothe exe is being launched with willy's suggestion
| to get process info before doing impersonation.
| But....(bad news begins), exe is getting following exception:
|
| System.TypeInit ializationExcep tion: The type initializer for
| "System.Runtime .Remoting.Ident ity" threw an exception. --->
| System.Security .Cryptography.C ryptographicExc eption: CryptoAPI
| cryptographic service provider (CSP) for this implementation could not
| be acquired.
| at
| System.Security .Cryptography.R NGCryptoService Provider..ctor( CspParameters
| cspParams)
| at System.Security .Cryptography.R NGCryptoService Provider..ctor( )
| at System.Runtime. Remoting.Identi ty..cctor()
| --- End of inner exception stack trace ---
| at
| FHEG.Framework. AppUpdater.Copy FilesDelegate.B eginInvoke(Asyn cCallback
| callback, Object object)
| at FHEG.Framework. AppUpdater.Prog ressForm.BeginC opy()
| at
| FHEG.Framework. AppUpdater.Prog ressForm.Progre ssForm_Activate d(Object
| sender, EventArgs e)
| at System.Windows. Forms.Form.OnAc tivated(EventAr gs e)
| at System.Windows. Forms.Form.set_ Active(Boolean value)
| at System.Windows. Forms.Form.WmAc tivate(Message& m)
| at System.Windows. Forms.Form.WndP roc(Message& m)
| at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
| at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
| at System.Windows. Forms.NativeWin dow.Callback(In tPtr hWnd, Int32
| msg, IntPtr wparam, IntPtr lparam)
|
As was said before, when impersonating, you are only running the thread in
the impersonated context, not the process that you spawn from this thread,
that's exactly why I asked why you were impersonating.
The result is that:
1. won't be able to copy to the .exe directory, and
2. apparently the application you start this way needs to access the crypto
store of the administrator, which is impossible because, the store (assumed
it's registry based) is not loaded and if it was you won't be able to access
it anyway.
Really, the only thing you can do (on v1.1) it create the process to run as
an administrator by calling CreateProcessAs through PInvoke, or better
integrate the "update" into your application (while impersonating). But
honestly, do you really want to take all this overhead when starting a
client application, just because you do not want to grant write access to
the .exe directory?
Do you think, this is a real security measure? I would say it's not, think
of what can happen when the process crashes when impersonating an
administrator!
Willy.
I was able to launch another exe successsfully using CreateProcessAU ser
but ran into other issue. So I gave up.
Thanks a lot for your help guys. I really appreciate it.
~ViPuL
I remember trying createprocessas user and not having any success
either...
I still think your best bet is to do File.Copy operations while
impersonating. In my case, I didn't have the option of granting the
user write rights to the folder since it was in an enterprise
environment where all that stuff was way out of my control.
Good luck,
Jared 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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: 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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |