Re: Launch Shell process under different identity

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Chris Conner (Chris.Conner_at_nomansland.com)
Date: 04/06/04


Date: Tue, 6 Apr 2004 11:27:29 -0400

I have run into the same problem and have had solved it using a different
approach:

Depending on what you need to do, use of the following two ways:

1) If the clients are Windows XP or higher machines, use the RUNAS command
instead. This way, you can still Shell execute the process with the current
user credentials and pass the credentials you want to run to this.
OR
2) Create a service account (my choice) that has network rights that runs on
the users machine and create a process file for it to execute. As an
example, have it create a folder in your program files\<application>\process
directory. Create a directory monitor in the service to process the text in
these files as commands to be executed. THIS IS DANGEROUS if you do not have
any kind of security. What I do is encrypt the contents of the file with a
key that is decryted with by the service. Once you have read in the
information - just delete the file and process those commands. The service
will have full local admin rights as well as whatever network rights you
give this service.

=-Chris

"Trips" <anonymous@discussions.microsoft.com> wrote in message
news:4A433DA7-A3B5-48C7-8A10-18483B74EB04@microsoft.com...
> Yes It's a domain service accout and it has proper permissions to access
the domain network folder. With in the code I did a messagebox display
method and it showed the impersonated account as the current changed
identity. The issus is Shell opens up for a second and closes.
>
> I am using these dll in order to impersonate
> [DllImport("advapi32.dll")]
> public static extern int LogonUserA(String lpszUserName,
> String lpszDomain,
> String lpszPassword,
> int dwLogonType,
> int dwLogonProvider,
> ref IntPtr phToken);
> [DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
> public static extern int DuplicateToken(IntPtr hToken,
> int impersonationLevel,
> ref IntPtr hNewToken);
>
> [DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
> public static extern bool RevertToSelf();
>
> [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
> public static extern bool CloseHandle(IntPtr handle);
> There is nothing wring with the impersonation code as I could see the
changed identity in a message box.
> I am simply doing this after the identity is changed
> System.Diagnostics.Process.Start(cmd); where cmd is a pth to bat file.
>
> thanks
> Ajay
>



Relevant Pages

  • Re: Re: Impersonating from a non admin user account
    ... public static extern int LogonUserA(String lpszUserName, ... String lpszPassword, ... Basically how do i Impersonate another user from a non-admin account? ...
    (microsoft.public.platformsdk.security)
  • Impersonate progromatically persist through session or just page?
    ... session/process (i.e. from request to request) or does it only apply ... Impersonate a Specific user whereever required within the code ... public static extern int RevertToSelf(); ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Crystalreport export into TIFF
    ... private IntPtr m_pInstance = IntPtr.Zero; ... private string tiff_path; ... public static extern int MessageBox(int hWnd, String text, String ...
    (microsoft.public.vb.crystal)
  • Re: Pinvoke help
    ... public static extern int StartCamera; ... MouseButtons button, Int32 clicks) ... at System.AppDomain.ExecuteAssembly(String assemblyFile, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Pinvoke help
    ... public static extern int StartCamera; ... ; an interface function: ... at System.AppDomain.ExecuteAssembly(String assemblyFile, ...
    (microsoft.public.dotnet.languages.csharp)