Jump to content
Sign in to follow this  
BlackHoleSun

Users and processes

Recommended Posts

BlackHoleSun

Is there a way to tell what user name is running a process? I would have thought ProcessGetStats would, but it looks like it's memory stuff.

Also, if my program is launched by someone with the wrong kind of user name it asks for credentials and authorizes it on the domain. Is there anyway to restart the program as that user after authenticating without making 2 programs (one to authenticate, one as the actual program)?

Share this post


Link to post
Share on other sites
BlackHoleSun

OK I got it working. I used the _ProcessListOWNER_WTS() function to determine the ID in my full code. That determines that I should use the login GUI if it's not launched as an admin. Here is a simplified login code (I know it's not pretty):

#include <AD.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt('MustDeclareVars', 0)
Opt('GUICloseOnESC', 0)

Global $domain, $logonSrv, $config, $adConnDomain, $adConnDomain1, $adConnDomain2

_AD_Open()
$domain = $sAD_DNSDomain
$logonSrv = $sAD_HostServer
$config = $sAD_Configuration
_AD_Close()
$adConnDomain1 = StringSplit($domain, ",")
$adConnDomain2 = StringSplit($adConnDomain1[1], "=")
$adConnDomain = $adConnDomain2[2]

_Login()

Func _Login()
    ;Login GUI
    Local $guiW, $guiH
    $guiW = 180
    $guiH = 125
    $loginGUI = GUICreate("Login", $guiW, $guiH, (@DesktopWidth - $guiW) / 2, (@DesktopHeight - $guiH) / 2, $WS_BORDER + $WS_VISIBLE + $WS_MAXIMIZEBOX)
    
    ;Login Input
    Local $userLbl, $userIn, $passLbl, $passIn, $loginSub, $loginCan, $loginMsg
    $userLbl = GUICtrlCreateLabel("User Name:", 5, 5)
    $userIn = GUICtrlCreateInput("", 72, 2, 100, 20)
    $passLbl = GUICtrlCreateLabel("Password:", 5, 25)
    $passIn = GUICtrlCreateInput("", 72, 22, 100, 20, $ES_PASSWORD)
    $loginSub = GUICtrlCreateButton("&Submit", 40, 45, 50, 22)
    $loginCan = GUICtrlCreateButton("&Cancel", 90, 45, 50, 22)
    $loginMsg = GUICtrlCreateLabel("You must login with" & @CRLF & " admin credentials", 45, 70)
    
    While 1
        Switch GUIGetMsg()
            Case $loginCan
                _Exit()
                
            Case $loginSub
                $adConnUser = GUICtrlRead($userIn)
                $adConnPass = GUICtrlRead($passIn)
                GUIDelete()
                _ADConnect($adConnUser, $adConnPass)
        EndSwitch
    WEnd
EndFunc   ;==> _Login

Func _ADConnect($adConnUser, $adConnPass)
    If _AD_Open($adConnUser, $adConnPass, $domain, $logonSrv, $config) Then
        If RunAs($adConnUser, $adConnDomain, $adConnPass, 4, "path\program", "workingdir") = 0 Then ;$procName)
            MsgBox(0, "Logon", "Logon failure" & @CRLF & "Error: " & @error & ", extended: " & @extended)
            _Login()
        EndIf
    ElseIf @error <= 8 Then
        MsgBox(16, "Active Directory Functions", "The logon was not succcessful!" & @CRLF & @CRLF & "@error: " & @error & ", @extended: " & @extended)
        _Login()
    Else
        MsgBox(16, "Active Directory Functions", "The logon was not succcessful!" & @CRLF & @CRLF & "@error: " & @error & ", @extended: " & @extended & _
            @CRLF & @CRLF & "Extended error information will be displayed")
        Global $aError = _AD_GetLastADSIError()
        _ArrayDisplay($aError)
    EndIf
    _AD_Close()
    _Exit()
EndFunc   ;==> _Connect

Func _Exit()
    Exit
EndFunc   ;==> _Exit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.