Page 1 of 1 1
Topic Options
#203739 - 2011-11-16 12:18 AM Current Logged in User
indi Offline
Just in Town

Registered: 2011-11-15
Posts: 1
Loc: california, USA
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

Top
#203740 - 2011-11-16 12:34 AM Re: Current Logged in User [Re: indi]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Have you tried the built in macros?

? @UserID

Top
#203741 - 2011-11-16 12:35 AM Re: Current Logged in User [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
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

Top
#203742 - 2011-11-16 01:08 AM Re: Current Logged in User [Re: ShaneEP]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
How are you running the code with alternate credentials? (GPO,Runas,Runnas,Sunar, etc)
Top
#203743 - 2011-11-16 04:30 AM Re: Current Logged in User [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
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

Top
#203786 - 2011-11-17 10:27 PM Re: Current Logged in User [Re: Allen]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
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
_________________________
Christophe

Top
#204087 - 2012-01-17 06:57 PM Re: Current Logged in User [Re: ChristopheM]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
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

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 539 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.139 seconds in which 0.096 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org