Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 122799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:11:09+00:00 2026-05-11T04:11:09+00:00

I’m currently using a homegrown method to run a process as a different user

  • 0

I’m currently using a homegrown method to run a process as a different user in Vista, and I can’t escape the feeling that’s it hack-ish and less than ideal (in addition to the fact that it craps out UAC, crashing my app with a security exception, and forcing me to disable UAC altogether). My process consists of two projects (so two EXE files) – an ‘interface’ and a ‘launch stub’ – and here’s the process:

  1. User has a shortcut that launches ‘Interface.exe notepad.exe’
  2. Interface.exe has a form that asks for the credentials they’d like to use
  3. Interace.exe uses ProcessStartInfo to create an instance of LaunchStub.exe (LS) as the new user
  4. LS uses ProcessStartInfo (with ShellExecute set to true) to launch the requested file, and since it’s already running as the requested user, so is the new process.

The reason I have a two-step process is that I want users to be able to right-click on any file the OS has a default action for (.EXE, .SQL, .MSC, etc) and launch it, and ProcessStartInfo only supports that with ‘UseShellExecute’ enabled, but that switch prevents me from using new credentials, so I can only do one at a time.

This causes a few problems – first, the user has to already exist on the computer, meaning they have to have logged in locally before. If there’s no local profile for that user, the requested app will sometimes launch, but I get registry and profile exceptions because the application expects things to exist that don’t yet (like an HKCU hive in the registry, which the user doesn’t have because they’ve never logged in).

I know I should be able to just ‘Elevate’ the rights of my application to the user they’re requesting, launch my new process, and then undo the elevation, but I’m unable to find a good code sample for that, and I’m not sure that it would allow running as a completely different user. Does this all make sense? I just can’t help feel like there’s a better way to do this.


UPDATE: I just tried some Impersonation code I found online, but to no avail. When used in conjunction with ProcessStartInfo, it still seems to launch processes using my current login, not the one I’ve provided, even though I’ve activated impersonation using the provided credentials.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:11:09+00:00Added an answer on May 11, 2026 at 4:11 am

    Chances are that you have to create your own ‘shell’ function using the Win32 API.

    Using the CreateProcessWithLogonW API you can create new processes under different credentials and optionally load user profile information.

    In the code snippet below if you replace

    • username – with your username
    • domain – with your domain or ‘vbNullString’
    • password – with your password
    • parameter 4 – replace 0 with ‘LOGON WITH PROFILE’ to load the specified users profile.

    See the documentation for the CreateProcessWithLogonW API for further specifics. Going this route you have full control and full responsibility for launching the application.

    Again this is just a sample and you may have to play with it a little to get it to do what you want.

     Imports System.Runtime.InteropServices  Public Module modShell      <StructLayout(LayoutKind.Sequential)> _     Public Structure STARTUPINFO         Public cb As Integer         Public lpReserved As String         Public lpDesktop As String         Public lpTitle As String         Public dwX As Integer         Public dwY As Integer         Public dwXSize As Integer         Public dwYSize As Integer         Public dwXCountChars As Integer         Public dwYCountChars As Integer         Public dwFillAttribute As Integer         Public dwFlags As Integer         Public wShowWindow As Short         Public cbReserved2 As Short         Public lpReserved2 As Integer         Public hStdInput As Integer         Public hStdOutput As Integer         Public hStdError As Integer     End Structure      <StructLayout(LayoutKind.Sequential)> _     Public Structure PROCESS_INFORMATION         Public hProcess As IntPtr         Public hThread As IntPtr         Public dwProcessId As Integer         Public dwThreadId As Integer     End Structure      Public Declare Unicode Function CreateProcessWithLogonW Lib 'Advapi32' (ByVal lpUsername As String, ByVal lpDomain As String, ByVal lpPassword As String, ByVal dwLogonFlags As Int32, ByVal lpApplicationName As String, ByVal lpCommandLine As String, ByVal dwCreationFlags As Int32, ByVal lpEnvironment As IntPtr, ByVal lpCurrentDirectory As String, ByRef si As STARTUPINFO, ByRef pi As PROCESS_INFORMATION) As Integer     Public Declare Function CloseHandle Lib 'kernel32' (ByVal hObject As IntPtr) As Integer      Public Const LOGON_WITH_PROFILE As Int32 = &H1      Public Const NORMAL_PRIORITY_CLASS As Int32 = &H20&      Public Const STARTF_USESHOWWINDOW As Int32 = &H1     Public Const SW_HIDE As Int16 = 0     Public Const SW_SHOW As Int16 = 5      Public Function Shell(ByVal strCmdLine As String, ByVal strCurrentDirectory As String) As Boolean          Dim pi As PROCESS_INFORMATION         Dim si As New STARTUPINFO          si.cb = Marshal.SizeOf(si)         si.dwFlags = STARTF_USESHOWWINDOW         si.wShowWindow = SW_SHOW          Dim result As Integer = CreateProcessWithLogonW('username', 'domain', 'password', 0, vbNullString, strCmdLine, NORMAL_PRIORITY_CLASS, IntPtr.Zero, strCurrentDirectory, si, pi)          If result <> 0 Then             Call CloseHandle(pi.hThread)             Call CloseHandle(pi.hProcess)         Else             Return False         End If          Return True      End Function  End Module  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 93k
  • Answers 93k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use a Factory pattern instead: class Oracle(object): ... class SQLite(object):… May 11, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer With XSL, the problem is you cannot change a variable… May 11, 2026 at 6:38 pm
  • Editorial Team
    Editorial Team added an answer One way to deal with this would be to use… May 11, 2026 at 6:38 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.