Page 2 of 2 <12
Topic Options
#195217 - 2009-08-02 08:21 AM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
What is the value that you will read.
Where is what WMI field to find it in.

Get a WMI Browser and you will see what is meant by these values.

As Glenn stated, search for the KiX-O-Matic it will expose the WMI objects to you so you know exactly what to type in the paramaters.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#195224 - 2009-08-03 04:34 PM Re: new cool project find the pcname of user and list it! [Re: Gargoyle]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
GARGOYLE
thanks
yeah I jut got kixomatic working last week. wow what a super toool
willl post when I am done...what I am doing
thanks for your help...
those UDFs are way nice interfacing with WMI wow!
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195234 - 2009-08-03 08:49 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
$arrUserNames = WMIQuery('UserName','Win32_ComputerSystem',$ComputerName)
If Not @ERROR
$username=$arrUserNames[0]
EndIf
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#195255 - 2009-08-04 11:07 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Hello everyone. I want to share with you what I have been trying to do.
Okay, I am a network admin, and when we have users who call up and need us to remote into their pc, we do not know their PC name? Some we do but there is too many to memorize. So if the employee would tell us which location they were at, all I have to do is click on my program and witing seconds, it would bring up pcname and user name in a nice display.
Okay I have gone thru working with WMI which on the network is very very slow in responding...so I have been trying to use the PSTOOLS command
"psloggedon" and the LDAP function you guys recommended to me. I love the LDAP function mixed with the shell command "psloggedon" pstool...this has proven the fastest way to bring up PC names and local logged on user..
I can locate the user and their pcname within seconds. I wanted to use the WMI and it did work after help from you guys. But it just wasnt working as fast as the below script..IT is still in it rough but it does work and fast. Plus after I am done I am going to use kix2exe gui to package it up into and EXE which I really love. Thank you all for you help..you are too cool!

now I can located a local logged on user and their pcname within seconds...





 Quote:

Break On


;*************declare and fill arrays here*****************************
Dim $Branch1, $Branch2, $Branch3, $Branch4
;fnLDAPQuery(WHAT, Optional FROM, Optional FILTER, Optional ORDER BY, Optional SCOPE, Optional USER, Optional PASSWORD)
$Branch1 = fnLDAPQuery('Name','GC://OU=Computers,OU=Forth,OU=funnycu,dc=funnycu,dc=priv','(&(objectClass=Computer)(Name=*))')
$Branch2 = fnLDAPQuery('Name','GC://OU=Computers,OU=Eighth,OU=funnycu,dc=funnycu,dc=priv','(&(objectClass=Computer)(Name=*))')
$Branch3 = fnLDAPQuery('Name','GC://OU=Computers,OU=Rd1,OU=funnycu,dc=funnycu,dc=priv','(&(objectClass=Computer)(Name=*))')
$Branch4 = fnLDAPQuery('Name','GC://OU=Computers,OU=Dr2,OU=funnycu,dc=funnycu,dc=priv','(&(objectClass=Computer)(Name=*))')


;*************Looping Engine ***************************************

For each $Element in $Branch1
$Count = $Count + 1

? 'Please wait...Looking for users and PC Names......'
shell "cmd.exe /c ping -n 1 $Element > hide.txt"

IF @ERROR = 0
$rc = RedirectOutput("findPC2.txt", 0)
? $Element
$rc = RedirectOutput("")
shell "cmd.exe /c psloggedon -l -x \\$Element > findPC1.txt"
shell "cmd.exe /c findstr /c:DOMAINNAME\ U:\findPC1.txt >> U:\findPC2.txt"
ENDIF

Next
shell "cmd.exe /c type findPC2.txt"
;?' '
? $Count
Sleep 60
shell "cmd.exe /c xcopy clean1.txt findPC1.txt /y"
shell "cmd.exe /c xcopy clean2.txt findPC2.txt /y"

;*********************************************************************
; LDAP function
;*********************************************************************

Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,Optional $User,Optional $Pswd)
Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R
$sQ="<"+Iif($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),$From)+">;"+$Filter+";"+Iif(VarType($What)>8192,Join($What,','),$What)+";"+Iif($Scope<>"base" AND $Scope<>"onelevel","subtree",$Scope)
$oCon=CreateObject("ADODB.Connection")
$oCon.Provider="ADsDSOObject"
$oCon.Properties("Encrypt Password").Value=1
$oCon.Properties("ADSI Flag").Value=1
If $User AND $Pswd
$oCon.Properties("User ID").Value=$User
$oCon.Properties("Password").Value=$Pswd
EndIf
$oCon.Open("Active Directory Provider")

$oCMD=CreateObject("ADODB.Command")
$oCMD.ActiveConnection=$oCon
$oCMD.CommandText=$sQ
$oCMD.Properties("Page Size").Value=1000
$oCMD.Properties("Timeout").Value=30
$oCMD.Properties("Cache Results").Value=0

If InStr($OrderBy,"distinguishedName")
$oRS=CreateObject("ADODB.Recordset")
$oRS.CursorLocation=3
$oRS.Sort=$OrderBy
$oRS.Open($sQ,$oCon,0,1,1)
Else
If $OrderBy
$oCMD.Properties("Sort On").Value=$OrderBy
EndIf
$oRS=$oCMD.Execute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF AND $oRS.EOF Exit @ERROR EndIf

$aR = $oRS.GetRows()
Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
For $R=0 to Ubound($aR,2)
For $C=0 to Ubound($aR,1)
$aFR[$R,$C]=$aR[$C,$R]
Next
Next
$fnLDAPQuery=$aFR
EndFunction



Edited by itdaddy (2009-08-04 11:15 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195264 - 2009-08-05 12:00 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
Hi Robert,

An alternative direction, how about just writing a small kix program using the "@" macros and pushing it to everyone's desktop. You could then just have people click on that icon when you call and they can have all the information you need. If you have kixforms on all the systems you can gui it. If not, you could pop the results in a message box, or just a command window with a sleep command at the end.

Regards,

Brad

Top
#195274 - 2009-08-05 05:30 PM Re: new cool project find the pcname of user and list it! [Re: BradV]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Another alternative would be to write the information to a database that you then execure a query against. All still able to be done in KiX.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#195315 - 2009-08-06 01:44 PM Re: new cool project find the pcname of user and list it! [Re: Gargoyle]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
it is very simple to write a code section to write basic info to DB, you can collect basic stuff like:

Serno, userid, wksta, ipaddr, macaddr, make, model, date, etc.

that would provide a very basic and functional inventory.. and would run in about 3 seconds when added you your logon script... less if your script allready collected that data, the writing to the sql db is very quick...

Then you make a tool that queries the DB to some sort of lookup
"select * from InvTable where Userid='xxxxxx' and date='@date'"

Since you could have the MACaddr, you could do WOL...
Since you have serno and model, it becomes an inventory...

etc
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#195317 - 2009-08-06 02:35 PM Re: new cool project find the pcname of user and list it! [Re: Radimus]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
Another option is to have a standard for naming workstations. Where I work every workstation has a bar code attached to it (on the front). The workstation names are derived from the barcode (as long as the installer did his/her job properly). So, when someone calls in, ask the the workstation barcode and 99% of the time you now have the workstation name. No coding involved. \:\)
Top
#195319 - 2009-08-06 03:22 PM Re: new cool project find the pcname of user and list it! [Re: BradV]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
@Brad - You and I must work in the same place as we do exactly the same thing. In fact to open a HelpDesk ticket, they must provide that barcode.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#195335 - 2009-08-07 06:36 AM Re: new cool project find the pcname of user and list it! [Re: Gargoyle]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
We just renamed every PC on the domain to the serialnumber, easily due to a magic script I wrote and packaged2exe

we also put bginfo on each machine that paints the @wksta onto the top right of the wallpaper to help those that can't read the label on the box
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#195353 - 2009-08-07 08:20 PM Re: new cool project find the pcname of user and list it! [Re: Radimus]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Yep, didn't use script to do it but is a matter of course to name with serial number and use BGINFO on all workstations. Set to show IP, OS, SP, USER, LogonTime, CPU, Memory, Up Since, Free Space

Then a shortcut to a batch that run it from the startup group. I used to put it in the Registry but I forget what happened but some update or setting Microsoft did a while back broke it so I quit using the Registry. It might work there again now as its been a while since I've reviewed it as the startup group has been working well now for years.

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.063 seconds in which 0.025 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