Page 1 of 1 1
Topic Options
#207874 - 2013-10-07 07:45 PM Compare Current logged in user against an csv file.
jenefa Offline
Fresh Scripter

Registered: 2013-02-01
Posts: 15
Loc: USA
Hello,
I have need to compare the current logged in user with a csv file which has multiple columns of data. The first column of the CSV file will have the name of the user.
1) How do i get the name of the current logged in user ?

Any pointers or help is greatly appreciated.

Top
#207875 - 2013-10-07 08:02 PM Re: Compare Current logged in user against an csv file. [Re: jenefa]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
go to http://www.kixtart.org click on command reference and look at the macros... @csd, @inwin and all that stuff.

but seriously, you mean the fullname?
_________________________
!

download KiXnet

Top
#207876 - 2013-10-07 08:31 PM Re: Compare Current logged in user against an csv file. [Re: jenefa]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Making a few assumptions but something like this should do the trick.

 Code:
Break on

$rc = Open(1, "c:\somecsvfile.csv", 2)
$line = ReadLine(1)

While @ERROR = 0 And $found <> "yes"
	$line = Split($line, ";")
	If $line[0] = @USERID
		? "Yippie Ka Yee.... found it!"
		$found = "yes"
	EndIf
	$line = ReadLine(1)
Loop

$rc = Close(1)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#207877 - 2013-10-07 08:43 PM Re: Compare Current logged in user against an csv file. [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
If you're looking at remote workstations, you can try something like this:
 Code:
$RemoteHost = 'workstation27'
$ActiveUserID = WMIQuery('UserName', 'Win32_ComputerSystem', $RemoteHost)[0]
You can then enumerate the CSV file and determine if $ActiveUserID matches anything.

Some helpful UDFs available here on KORG (latest from my web site resources page):
FILEIO()
$aFileData = FileIO('file.csv', 'R') will read the entire file into the $aFileData array.
$aFileData = FileIO('file.csv, 'W', $aFileData) will write the updated array back to the file and reload the array with the new file content.

CSV()
$aRecord = CSV($aFileData[$I]) will take the CSV data from the array and convert it to an array.
$aFileData[$I] = CSV($aRecord) converts the array back to proper CSV format.

So - once you have $ActiveUserID - either remote as shown above or local via @USERID, you can use this to match the user ID and get the associated fields.

 Code:
$ActiveUserID = WMIQuery('UserName', 'Win32_ComputerSystem', $RemoteHost)[0]
$aFileData = FileIO('file.csv', 'R')

For $I = 0 to UBound($aFileData)
  $aRecord = CSV($aFileData[$I])
  If $aRecord[0] = $ActiveUserID
    'Have a match in record ' $I @CRLF

    ; do stuff here for a matched record...

    $I = UBound($aFileData) + 1            ; stop checking records
  EndIf
Next
Glenn

BTW - Welcome to KORG!
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207878 - 2013-10-07 08:46 PM Re: Compare Current logged in user against an csv file. [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Mart - CSV uses commas, not semicolons. ;\)

The CSV format is a bit more complex than this example shows, as you may need to take quoted fields into account which contain embedded commas!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207879 - 2013-10-07 10:09 PM Re: Compare Current logged in user against an csv file. [Re: Mart]
jenefa Offline
Fresh Scripter

Registered: 2013-02-01
Posts: 15
Loc: USA
Thank you so much. @USERID solved my issue with getting the current logged in user.
Top
#207880 - 2013-10-07 10:38 PM Re: Compare Current logged in user against an csv file. [Re: jenefa]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I WAS RIGHT!!!!

rtfm.
_________________________
!

download KiXnet

Top
#207881 - 2013-10-07 10:50 PM Re: Compare Current logged in user against an csv file. [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Hahaha
Top
#207884 - 2013-10-08 03:45 PM Re: Compare Current logged in user against an csv file. [Re: ShaneEP]
jenefa Offline
Fresh Scripter

Registered: 2013-02-01
Posts: 15
Loc: USA
Ok, next step for me, i need to check for 2 conditions.
1) If current user is found in 2nd column of the csv file
2) if 1st column of the csv file is user not group.

Is my code on the correct logic

While $found <> "yes"
$results = AScan($asharepart2, @USERID)
If $results = @USERID
IF $aSharegrouporUser[2ndarrayrows] = "user"
$found = "yes"
EndIF
EndIf
$2ndArrayrows = $2ndArrayrows + 1
Loop

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
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.113 seconds in which 0.05 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