Results 1 to 5 of 5

Thread: How to run an app NOT as administrator?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    1

    Exclamation How to run an app NOT as administrator?

    I have a headache now. I searched answers on google for days but no help at all. Here it is:

    There is an app (A) running as administrator. I use A to run another app (B) by clicking a button on A.
    B gets administrative rights from A after it is started.
    But I want B run NOT as administrator. Any help?

    I don't need code. I just want to know how. Thanks in advance!

  2. #2
    Addicted Member
    Join Date
    Oct 2012
    Posts
    137

    Re: How to run an app NOT as administrator?

    from what i understand you maybe creating a trojan bot aka rat-remote admin

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: How to run an app NOT as administrator?

    what? where do you get THAT from?


    anyways, normally the request goes the other way around... it has to do with thread ownership and inheriting from the parent... is there a reason to run thread B as the context user, rather than the elevated admin?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: How to run an app NOT as administrator?

    You could do that by using this code:

    Module code
    vb Code:
    1. 'Controls user program elevation
    2. Option Explicit
    3.  
    4. Private Const BCM_SETSHIELD As Long = &H160C&
    5.  
    6. Private Declare Sub InitCommonControls Lib "comctl32" ()
    7.  
    8. Private Declare Function IsUserAnAdmin Lib "shell32" () As Long
    9.  
    10. Private Declare Function SendMessage Lib "user32" _
    11.     Alias "SendMessageA" ( _
    12.     ByVal hWnd As Long, _
    13.     ByVal wMsg As Long, _
    14.     ByVal wParam As Long, _
    15.     ByRef lParam As Any) As Long
    16.  
    17. Private Declare Function ShellExecute Lib "shell32" _
    18.     Alias "ShellExecuteA" ( _
    19.     ByVal hWnd As Long, _
    20.     ByVal lpOperation As String, _
    21.     ByVal lpFile As String, _
    22.     ByVal lpParameters As String, _
    23.     ByVal lpDirectory As String, _
    24.     ByVal nShowCmd As VbAppWinStyle) As Long
    25.  
    26. Private mblnIsElevated As Boolean
    27. Private objForm As Object
    28.  
    29. Public Function IsElevated() As Boolean
    30.     IsElevated = mblnIsElevated
    31. End Function
    32.  
    33. Public Sub OperationRequiringElevation(ByRef Params As Variant)
    34.     MsgBox "Insert logic here for: " & vbNewLine _
    35.          & Join(Params, vbNewLine)
    36. End Sub
    37.  
    38. Public Sub RequestOperation( _
    39.     ByVal hWnd As Long, _
    40.     ByVal Focus As VbAppWinStyle, _
    41.     ByRef Params As Variant)
    42.  
    43.     ShellExecute hWnd, "runas", App.EXEName & ".exe", _
    44.                  Join(Params, " "), CurDir$(), Focus
    45. End Sub
    46.  
    47. Public Sub SetShield(ByVal hWnd As Long)
    48.     SendMessage hWnd, BCM_SETSHIELD, 0&, 1&
    49. End Sub
    50.  
    51. Private Sub Main()
    52.     If Len(Command$()) > 0 Then
    53.         'Assume we've been run elevated to execute an operation
    54.         'specified as a set of space-delimited strings.
    55.         OperationRequiringElevation Split(Command$(), " ")
    56.                   'unload all forms
    57.                    For Each objForm In Forms
    58.                    Unload objForm
    59.                    Set objForm = Nothing
    60.                    Next objForm
    61.                       Else
    62.         mblnIsElevated = IsUserAnAdmin()
    63.         InitCommonControls
    64.         load
    65.     End If
    66. End Sub

    vb Code:
    1. 'Detect user elevation (could probably go in the first module too)
    2. Option Explicit
    3.  
    4. Public Sub load()
    5. Dim ff, Params As Variant
    6.  
    7.        Params = Array(App.EXEName, "By Nightwalker83", "http://aaronspehr.net/")
    8.     If IsElevated() Then
    9.         OperationRequiringElevation Params
    10.     Else
    11.         RequestOperation frmMain.hWnd, vbHide, Params
    12.     End If
    13.          frmMain.Show
    14. End Sub

    You also need:

    A form called "frmMain"
    2 bas files
    Set the Startup Object as "Sub Main"

    For the second project just comment out:

    vb Code:
    1. Dim ff, Params As Variant
    2.  
    3.        Params = Array(App.EXEName, "By Nightwalker83", "http://aaronspehr.net/")
    4.     If IsElevated() Then
    5.         OperationRequiringElevation Params
    6.     Else
    7.         RequestOperation frmMain.hWnd, vbHide, Params
    8.     End If

    and

    vb Code:
    1. Public Sub OperationRequiringElevation(ByRef Params As Variant)
    2.     MsgBox "Insert logic here for: " & vbNewLine _
    3.          & Join(Params, vbNewLine)
    4. End Sub
    5.  
    6. Public Sub RequestOperation( _
    7.     ByVal hWnd As Long, _
    8.     ByVal Focus As VbAppWinStyle, _
    9.     ByRef Params As Variant)
    10.  
    11.     ShellExecute hWnd, "runas", App.EXEName & ".exe", _
    12.                  Join(Params, " "), CurDir$(), Focus
    13. End Sub
    14.  
    15. OperationRequiringElevation Split(Command$(), " ")
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to run an app NOT as administrator?

    I don't think there is any technique provided for an elevated process to spawn a standard user process.

    There are workarounds that involve playing with security tokens, starting a scheduled task, calling CreateprocessAsUser(), etc. But normally this isn't done.

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