Results 1 to 12 of 12

Thread: Run As Different User

  1. #1

    Thread Starter
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Run As Different User

    Hi,

    I would like to run my program as different user. Let's say I have following code which will open Run dialog:
    VB Code:
    1. Private Declare Function SHRunDialog Lib "shell32" Alias "#61" (ByVal hwnd As Long, ByVal I_dont_know_1 As Long, ByVal I_dont_know_2 As Long, ByVal dTitle As String, ByVal dPrompt As String, ByVal uFlags As Long) As Long
    2.  
    3. Private Sub Form_Load()
    4.     SHRunDialog hwnd, 0, 0, "", "", 2
    5.     Unload Me
    6. End Sub
    If we double click the executable of this program it will run in current windows user. I want to run this with different user. To do that normally we right click on exe file and click run as. Then we will enter the user name and password.

    I would like to automate this process some how.

    Thanks in advance.
    Attached Images Attached Images  
    CS

  2. #2

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Run As Different User

    This seems to work, but using the console and sendkeys..
    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    2.  
    3. Private Sub Command1_Click()
    4.     Shell "runas.exe /profile /user:[B]administrator[/B] notepad.exe"
    5.     Sleep (1000) 'Wait for runas.exe to load
    6.     SendKeys ("[B]password[/B]" & "{ENTER}")
    7. End Sub
    in bold user and password, if you enter correct values there notepad will open

  4. #4
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: Run As Different User

    ok - below is a class that will let you emulate other windows accounts

    clsNMC
    VB Code:
    1. 'See attached file (note the file is a text file as i dont have vb on this comp)

    and you will need to do this to impersonate the user:

    VB Code:
    1. Dim cNMC As New clsNMC
    2. cNMC.User_Impersonate "User", "Password", "." '.=local windows account (domain)
    this will make your prog have that users access to files etc

    you can also run another prog as another user by:
    VB Code:
    1. Dim cNMC As New clsNMC
    2. cNMC.User_RunAs "User", "Password",".","c:\windows\explorer.exe"
    Attached Files Attached Files

  5. #5
    Addicted Member
    Join Date
    Aug 2007
    Posts
    140

    Re: Run As Different User

    I faced some errors thru the defining of that code , Ps advice me how to can I define it

  6. #6
    New Member
    Join Date
    Dec 2020
    Posts
    2

    Re: Run As Different User

    I tried to import this class into my project, and I'm getting a million errors. Anyone using this has a successful version I could use?

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,177

    Re: Run As Different User

    Import? Is this a VBA project you are talking about? For VBA7 compatibility all API declares has to be first converted to the new x86+x64 compatible format.

    Btw, here is the final version of this class: https://github.com/Planet-Source-Cod...ter/clsNMC.cls

    cheers,
    </wqw>

  8. #8
    New Member
    Join Date
    Dec 2020
    Posts
    2

    Re: Run As Different User

    This is a vb solution/project (visual studio) doing something very simple, but since I don't always having the rights to a network drive I need, I wanted to try to run the vb executable as a different user.

  9. #9
    Lively Member
    Join Date
    Nov 2020
    Posts
    67

    Re: Run As Different User

    Quote Originally Posted by bushmobile View Post
    The link seem to be wrong, and go to another page...

  10. #10
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,738

    Re: Run As Different User

    Quote Originally Posted by Shoshana Michel View Post
    This is a vb solution/project (visual studio) doing something very simple, but since I don't always having the rights to a network drive I need, I wanted to try to run the vb executable as a different user.
    Then you are using VB.Net, the given sample is for VB6

  11. #11
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,676

    Re: Run As Different User

    Quote Originally Posted by LeoFar View Post
    The link seem to be wrong, and go to another page...
    It is no longer valid because it was posted on year 2006.
    There is a stored version here and a new page here.

  12. #12
    Lively Member
    Join Date
    Nov 2020
    Posts
    67

    Re: Run As Different User

    Quote Originally Posted by Eduardo- View Post
    It is no longer valid because it was posted on year 2006.
    There is a stored version here and a new page here.
    Thank.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width