Page 1 of 1 1
Topic Options
#109302 - 2003-12-01 11:02 AM where is my user ?
Bruno Offline
Fresh Scripter

Registered: 2001-08-08
Posts: 37
Loc: France (Europe)
Hello,

There is a script I do it to find a user.
You must have the command NTNAME (and RCMD + RCMDSVC) to run.
I need RCMD+RCMDSVC to query a distant network.
You must give a DC controleur name where RCMSSVC is running and NTNAME must be installed on the path of it.
NTNAME could be found in http\\www.jsiinc.com
Change the variable $dc with the name of the DC.

Code:
Break on

? "Where is my user ?"
?

:bcl

$dc="DC002"

? "Username (q to quit): "
Gets $user

If Ucase($user)="Q" GoTo end EndIf

If $user = @USERID
?
?
? "But it's you ! You still on " +@WKSTA
Else

? "Searching in local..."
$pc=ntname($user,"local")

If $pc =""
? "Searching on $dc..."
$pc=ntname($user, $dc)
EndIf
?
?
If $pc=""
? "$user not found !"
Else
? "$user find on $pc from $dc"
EndIf
EndIf
?
?

GoTo bcl

:end
?
?
? "That's Fini !"
?
?
Sleep 1

;*****************************************************************************************

Function ntname($user,$dc)

$tempfile="%temp%\ntname.txt"

If $dc ="local"
Shell '%comspec% /c ntname.exe $user > '+$tempfile
$=Open(3, $tempfile) = 0
$ntname = ReadLine(3)
$=Close (3)
Else
Shell '%comspec% /c rcmd \\$dc ntname.exe $user > '+$tempfile
$=Open(3, $tempfile) = 0
$x = ReadLine(3)
$x = ReadLine(3)
$ntname = ReadLine(3)
$=Close (3)
EndIf

Del $tempfile

EndFunction


_________________________
There is no stupid question. Whoever seeks is never stupid because he will know ...
Bruno

Top
#109303 - 2003-12-01 11:53 PM Re: where is my user ?
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
What OS's are you running this on ???

Because if you are using windows 2000 or XP, I would use WMI to check what use is logged onto what machine.

I will redo your script with WMI & KiXForms.

Don't worry if you don't use it, been learning VB.Net since the board was down, and don't use KiX for any work projects now. But I still love doing KiX

Thanks

Rich


Top
#109304 - 2003-12-02 12:41 AM Re: where is my user ?
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Try this out I haven't done no testing, will do tomorrow.

Sorry for the layout, PostPrep does not seem to be working. :-(

Code:
 
; *********************************************************************************
; * Script Name: Find User *
; * Creator: Richard Farthing - Queen Elizabeth Hospital NHS Trust *
; * Date: 1/09/03 *
; * Requirments FileOwner Function, KiXforms v2.3.0 Beta 3, *
; * KiXtart 4.22 Beta 1 *
; *********************************************************************************


Break On ; Break On to allow user to break out

;**********************************************************************************************************
;Checking that KiXtart Forms DLL is Registered
$sid = ReadValue("HKEY_CLASSES_ROOT\Kixtart.Form\CLSID", "")
If NOT ReadValue("HKEY_CLASSES_ROOT\CLSID\$sid\InprocServer32", "ThreadingModel") = "Both"
MessageBox("KiXtart Forms Register DLL Failed, Please contact the IMT Helpdesk on x6049",
"Fin User - KiXtart Forms DLL Register Failed", 0)
Exit 1
EndIf

;**********************************************************************************************************
;Create Object to KiXtart Form
$FORM = CreateObject("Kixtart.Form")

;**********************************************************************************************************
;Main Form

$FORM.Caption = "Find User !!"
$FORM.ScaleHeight = 93
$FORM.ScaleWidth = 250
$FORM.FontSize = 8
$FORM.Center

;**********************************************************************************************************
;Current Directory Label

$lblUserName = $FORM.Label
$lblUserName.Text = "Type in your User Name you wish to search for: "
$lblUserName.Left = 5
$lblUserName.Top = 10
$lblUserName.Width = 380
$lblUserName.Height = 20
$lblUserName.FontSize = 8
$lblUserName.FONTNAME = "Arial"
$lblUserName.Enabled = 0

$UserNameButton = $FORM.CommandButton("Search User")
$UserNameButton.Left = 155
$UserNameButton.Top = 35
$UserNameButton.Width = 75
$UserNameButton.Height = 20
$UserNameButton.FontSize = 8
$UserNameButton.FONTNAME = "Arial"
$UserNameButton.OnClick = "MainFunction()"

$UserNameBox = $FORM.TextBox
$UserNameBox.Left = 15
$UserNameBox.Top = 35
$UserNameBox.Width = 120
$UserNameBox.Height = 20
$UserNameBox.FontSize = 8
$UserNameBox.FONTNAME = "Arial"

$ResultText = $FORM.Label
$ResultText.Left = 5
$ResultText.Top = 65
$ResultText.Width = 210
$ResultText.Height = 20
$ResultText.FontSize = 8
$ResultText.FONTNAME = "Arial"


;**********************************************************************************************************
;Objects within Main Form

$FORM.Show ; Show Form

While $FORM.Visible
$=Execute($FORM.DoEvents)
Loop

Exit 1

;***********************************************************************************************************
;Call Functions & UDF's ****
;***********************************************************************************************************

Function MainFunction()


$UserNameBox.Enabled = 0
$UserNameBox.BackColor = $Form.BackColor
$UserNameBox.Text = Ucase($UserNameBox.Text)
$UserNameButton.Enabled = 0
$Domain="QEH-TR"

Select

Case $UserNameBox.Text = @USERID
$ResultText.ForeColor = Green
$ResultText.Text = "Are You Mad, '"+@USERID+"' is you!!"

Case $UserNameBox.Text = ""
$ResultText.Text = "The User Name field cannot be left blank !!"
$ResultText.ForeColor = Red

Case 1 $ResultText.Text = "Searching for User Name....."
$ResultText.ForeColor = Blue
$rc=fnWMILoggedIn(3,$Domain,$sDomainUser,$sDomainPass)

Select

Case Ubound($rc) = +1
$ResultText.Text = $rc

Case $rc = ""
$ResultText.Text = "User Name cannot be found"
$ResultText.ForeColor = Red

Case 1
For Each $Object In $rc
If $Object = $UserNameBox.Text
$ResultText.Text = $Object
EndIf
Next


EndSelect

EndSelect

Sleep 3

$ResultText.Text = ""
$UserNameButton.Enabled = 1
$UserNameBox.Enabled = 1
$UserNameBox.Text = ""
$UserNameBox.BackColor = "White"
$ResultText.ForeColor = Black

EndFunction

Function fnWMILoggedin(optional $iMode, optional $sComputerName, optional $sUserName, optional $sPassword)
Dim $objLocator, $objWBEM, $sUserNames, $sNameSpace, $sName
Dim $objAdsFso, $objSystem, $sCompName, $objAdsSession

$fnWMILoggedin=''

$iMode=Val($iMode)

$sNameSpace = 'root\CIMV2'

; check to see whether we're connecting to a local or remote computer
$sComputerName=Trim($sComputerName)
Select
Case $sComputerName=@WKSTA
$sCompName=$sComputerName
$sComputerName='.'
Case $sComputerName
$sCompName=$sComputerName
Case 1
$sCompName=@WKSTA
$sComputerName='.'
EndSelect

Select
Case $sUserName AND $sComputerName<>'.'
; create locator object for connection to a remote computer
$objLocator = CreateObject('WbemScripting.SWbemLocator')
If @ERROR
Exit @ERROR
EndIf
; create an credentialed (username/password provided) connection to a remote computer
$objWBEM=$objLocator.ConnectServer($sComputerName,$sNameSpace,$sUserName,$sPassword)
If @ERROR
Exit @ERROR
EndIf
; set the impersonation level
$objWBEM.Security_.ImpersonationLevel = 3
If @ERROR
Exit @ERROR
EndIf
Case 1
;set the impersonation level
$objWBEM=GetObject('winmgmts:{impersonationLevel=impersonate}!\\'+$sComputerName+'\'+$sNameSpace)
If @ERROR
Exit @ERROR
EndIf
EndSelect

If $iMode=0 OR ($iMode & 1)
$objSystem = $objWBEM.ExecQuery('Select UserName from Win32_ComputerSystem')
For Each $sName In $objSystem
If $sName.UserName
ReDim preserve $sUserNames[Ubound($sUserNames)+1]
$sUserNames[Ubound($sUserNames)] = $sName.UserName
EndIf
Next
EndIf

If ($iMode & 2)
$objSystem = $objWBEM.ExecQuery("Select StartName from Win32_Service WHERE State='Running' AND StartName<>'LocalSystem'")
For Each $sName In $objSystem
ReDim preserve $sUserNames[Ubound($sUserNames)+1]
If Left($sName.StartName,2)='.\'
If $sCompName
$sUserNames[Ubound($sUserNames)] = Ucase($sCompName)+SubStr($sName.StartName,2)
Else
$sUserNames[Ubound($sUserNames)] = Ucase(@WKSTA)+SubStr($sName.StartName,2)
EndIf
Else
$sUserNames[Ubound($sUserNames)] = $sName.StartName
EndIf
Next
EndIf

If ($iMode & 4) OR ($iMode & 8)
$objAdsFSO = GetObject('WinNT://'+$sCompName+'/LanmanServer')
For Each $objAdsSession In $objAdsFSO.Sessions
$sName=$objAdsSession.User
Select
Case $sName=''
; inter-server connection
Case Right($sName,1)='$' AND ($iMode & 8) AND AScan($sUserNames,$sName)=-1
ReDim preserve $sUserNames[Ubound($sUserNames)+1]
$sUserNames[Ubound($sUserNames)]=Ucase(Left($sName,Len($sName)-1))
Case Right($sName,1)<>'$' AND ($iMode & 4) AND AScan($sUserNames,$sName)=-1
ReDim preserve $sUserNames[Ubound($sUserNames)+1]
If NOT InStr($sName,'\')
$sUserNames[Ubound($sUserNames)]=$sCompName+'\'+$sName
Else
$sUserNames[Ubound($sUserNames)]=$sName
EndIf
EndSelect
Next
$objAdsFSO = 0
EndIf

$objWBEM=0
$objLocator=0

If Ubound($sUserNames)=0
$sUserNames=$sUserNames[0]
EndIf

$fnWMILoggedin=$sUserNames
Exit @ERROR
EndFunction



Top
#109305 - 2003-12-02 03:57 PM Re: where is my user ?
DJ Ballistic Offline
Starting to like KiXtart

Registered: 2003-02-21
Posts: 185
In this code where do you specify the domain controller to query to find the user? I run the script as is and it just doesn't seem to be able to find any users on my network.
Top
#109306 - 2003-12-10 11:29 PM Re: where is my user ?
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
At least in this line:

Code:

$Domain="QEH-TR"



you should change QEH-TR to your domainname.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#109307 - 2003-12-15 10:59 AM Re: where is my user ?
Bruno Offline
Fresh Scripter

Registered: 2001-08-08
Posts: 37
Loc: France (Europe)
I use windows 2000 (wmi are installed)
Kixforms is resgistred
$domain is set to my domain name.
I could not get any result. Users are not found...
_________________________
There is no stupid question. Whoever seeks is never stupid because he will know ...
Bruno

Top
#109308 - 2003-12-15 12:16 PM Re: where is my user ?
Bruno Offline
Fresh Scripter

Registered: 2001-08-08
Posts: 37
Loc: France (Europe)
Here a review of your code Richard with my touch.
I forget wmi to run it on each platforms.

Code:
 
Break on

;Checking that KiXtart Forms DLL is Registered
$sid = ReadValue("HKEY_CLASSES_ROOT\Kixtart.Form\CLSID", "")
If NOT ReadValue("HKEY_CLASSES_ROOT\CLSID\$sid\InprocServer32", "ThreadingModel") = "Both"
MessageBox("KiXtart Forms Register DLL Failed, Please contact the IMT Helpdesk on x6049",
"Find User - KiXtart Forms DLL Register Failed", 0)
Exit 1
EndIf

;***********************************
;Create Object to KiXtart Form
$FORM = CreateObject("Kixtart.Form")

;***********************************
;Main Form

$FORM.Caption = "Find User (review)!!"
$FORM.ScaleHeight = 150
$FORM.ScaleWidth = 250
$FORM.FontSize = 8
$FORM.Center

;*******************************
;Current Directory Label

$lblUserName = $FORM.Label
$lblUserName.Text = "Type in your User Name you wish to search for: "
$lblUserName.Left = 5
$lblUserName.Top = 10
$lblUserName.Width = 380
$lblUserName.Height = 20
$lblUserName.FontSize = 8
$lblUserName.FONTNAME = "Arial"
$lblUserName.Enabled = 1

$UserNameButton = $FORM.CommandButton("Search User")
$UserNameButton.Left = 155
$UserNameButton.Top = 35
$UserNameButton.Width = 75
$UserNameButton.Height = 20
$UserNameButton.FontSize = 8
$UserNameButton.FONTNAME = "Arial"
$UserNameButton.OnClick = "MainFunction()"
$UserNameButton.default=1

$UserNameBox = $FORM.TextBox
$UserNameBox.Left = 15
$UserNameBox.Top = 35
$UserNameBox.Width = 120
$UserNameBox.Height = 20
$UserNameBox.FontSize = 8
$UserNameBox.FONTNAME = "Arial"

$ResultText = $FORM.Textbox
$ResultText.Left = 15
$ResultText.Top = 75
$ResultText.Width = 210
$ResultText.Height = 20
$ResultText.FontSize = 8
$ResultText.FONTNAME = "Arial"
$ResultText.enabled = 1
$ResultText.backcolor = 255,255,100

$quitbutton = $FORM.CommandButton("Exit")
$quitbutton.Left = 80
$quitbutton.Top = 125
$quitbutton.Width = 75
$quitbutton.Height = 20
$quitbutton.FontSize = 8
$quitbutton.FONTNAME = "Arial"
$quitbutton.OnClick = "Quit"


;*******************************
;Objects within Main Form

$FORM.Show ; Show Form

While $FORM.Visible
$=Execute($FORM.DoEvents)
Loop

Exit 1

;******************************

Function MainFunction()

$rdc="bas01"
$ResultText.ForeColor = 0.0.0
$user=$UserNameBox.text

If $user=""
$ResultText.Text = "The User Name field cannot be left blank !!"
$ResultText.ForeColor = 255.0.0
Exit
EndIf

If $user = @USERID
$ResultText.Text = "Are You Mad, '"+@USERID+"' is you!!"
$ResultText.ForeColor = 255.0.0
Exit
EndIf

$ResultText.Text ="Searching in local..."
$pc=ntname($user,"local")

If $pc =""
$ResultText.Text ="Searching on $rdc..."
$pc=ntname($user, $rdc)
EndIf

If $pc=""
$ResultText.Text = "User Name cannot be found."
$ResultText.ForeColor = 255.0.0
Else
$ResultText.Text = "$user found on $pc"
$ResultText.ForeColor = 0.0.0
EndIf

EndFunction

;***************************

Function ntname($user,$dc)

$tempfile="%temp%\ntname.txt"

If $dc ="local"
Shell '%comspec% /c ntname.exe $user > '+$tempfile
$=Open(3, $tempfile) = 0
$ntname = ReadLine(3)
$=Close (3)
Else
Shell '%comspec% /c rcmd \\$dc ntname.exe $user > '+$tempfile
$=Open(3, $tempfile) = 0
$x = ReadLine(3)
$x = ReadLine(3)
$ntname = ReadLine(3)
$=Close (3)
EndIf

Del $tempfile

EndFunction

_________________________
There is no stupid question. Whoever seeks is never stupid because he will know ...
Bruno

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1229 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.058 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

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