indi
(Just in Town)
2011-11-16 12:18 AM
Current Logged in User

Hello everyone,

I am trying to deploy software to workstations depending on AD userID.
- when i ran this code with domain admin account credentials, it shows UserID of Domain Admin not my UserID(Currently logged in ID)
- When i run this code using my credentials, it shows my UserID

Should i use other code, or look in registry for currently logged in user and use that value to verify AD information.

Thanks for Help


$oADSysInfo = CreateObject("ADSystemInfo")
$strUser = $oADSysInfo.UserName
$oUser = GetObject("LDAP://" + $strUser)
$strsAMAccountName = $oUser.sAMAccountName
?$strsAMAccountName


ShaneEP
(MM club member)
2011-11-16 12:34 AM
Re: Current Logged in User

Have you tried the built in macros?

? @UserID


ShaneEP
(MM club member)
2011-11-16 12:35 AM
Re: Current Logged in User

Also check out this thread for the newest .chm version of the manual. It contains all of the built-in commands/functions/macros...

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=202858


AllenAdministrator
(KiX Supporter)
2011-11-16 01:08 AM
Re: Current Logged in User

How are you running the code with alternate credentials? (GPO,Runas,Runnas,Sunar, etc)

AllenAdministrator
(KiX Supporter)
2011-11-16 04:30 AM
Re: Current Logged in User

Explorer.exe should be running in the context as the user you are looking for. Please try this and see if works for you. I would appreciate you replying with your results.

? GetProcessOwner("explorer.exe")
 
Function GetProcessOwner($Exename, optional $remotepc) dim $sc,$processes,$process if $remotepc="" $remotepc="." endif $sc = CreateObject("ScriptControl") $sc.language = "VBScript" $Processes = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $remotepc + "\root\cimv2").ExecQuery("Select * from Win32_Process where Name='" + $exename + "'") For Each $Process in $Processes $sc.addobject('vbProcess',$Process) $sc.addcode('Return = VbProcess.GetOwner(strNameOfUser)') $sc.run $GetProcessOwner=$sc.codeobject.strNameofUser next Endfunction


ChristopheM
(Hey THIS is FUN)
2011-11-17 10:27 PM
Re: Current Logged in User

Look at the code below :
 Code:
Function ShowProcessOwner($Exename, optional $remotepc)
  dim $objWMIService, $objProcess, $objItem, $objOutParams

  if $remotepc=""
    $remotepc="."
  endif

  $objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
  $objProcess = $objWMIService.ExecQuery("Select * from Win32_Process where Name='" + $exename + "'")

  For Each $objItem in $objProcess
    ;-- get the process owner --
    $objOutParams = $objWMIService.ExecMethod( $objitem.path_, "getOwner" )

    "owner       : " $objOutParams.domain + "\" + $objOutParams.user ?
  Next
Endfunction


this is a full WMI solution


AllenAdministrator
(KiX Supporter)
2012-01-17 06:57 PM
Re: Current Logged in User

I finally had a minute to revisit this. I took ChristopheM's version, tweaked it a bit and posted to UDFs.

GetProcessOwner() -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=204086&Main=204086#Post204086