Page 1 of 2 12>
Topic Options
#195144 - 2009-07-30 05:30 PM new cool project find the pcname of user and list it!
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
hey guys, here is my problem and I have the solution but I do not know how to code it...

Problem: when a user calls and us techs want to remote into their pc, the user doesnt know their pcname. we need the pcname to remote into the machine and help them.

solution:
I want to make a program that when executed it lists by branch# a list
of pcnames with the username who is localy logged on.

example

program is called findpcname.exe (using gui kix compiler)

output:

Branch 1:

PC1 rubers
PC2 bfinway
PC3 rvandyke
PC4 rsellers

Branch 2:

PC5 rmueller
PC6 rmiller
PC7 rjohnson
PC8 bbeulla


This is my what I dont know how to do:

I am using pstools shell command psloggedon -l \\pcname > found.txt
and what goes into this text file is this output below

 Quote:


Users logged on locally:
Error: could not retrieve logon time
NT AUTHORITY\LOCAL SERVICE
Error: could not retrieve logon time
NT AUTHORITY\NETWORK SERVICE
Error: could not retrieve logon time
DOMAINNAME\lrokke
Error: could not retrieve logon time
NT AUTHORITY\SYSTEM


I do not know how to extract the name beyond the domainname\?
I want to pull that name out and put it into a variable on the fly
while I am looping thru the list of pcnames? and then as I do this
it will be printing thename of pc and then next to it thename of user.
But I have no clue how to extract just the name past the domainname\
and the domainname\ is a static name and doesnt change in digits.

I know you guys have a clue on how I can do this if you could help me
thanks so much...

once I am done, i will post entire program here for others to benefit!
thank you
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195146 - 2009-07-30 06:24 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
Okay guys here is my lame attempt! it doesnt work but
maybe you can kind of see what I want the engine to do
I just want to extract the name from the line
DOMIAIN\username <-- i want to extract the username to a variable?
 Quote:

Break On
SHELL "cmd.exe /c for /F "delims=" %a in ('findstr /c:DOMAIN\ find.txt') do set FindName=%a"
$FindName = shell "cmd.exe /c echo %FindName%"
$UserName = SubStr($FindName, 10, 20)
? $UserName
sleep 30


Edited by itdaddy (2009-07-30 06:38 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195147 - 2009-07-30 08:05 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4621
Loc: The Netherlands
Reading the username from the domain\username is not so difficult is it?

You could use substr() or you could split the line on the \ and get the last element from the array you created while splitting it.

Example:
 Code:
$line = "domain\UserA"
$name = SubStr($line, 8)
? $name


or

 Code:
$line = "domain\UserA"
$split = Split($line, "\")
? $split[UBound($split)]
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195148 - 2009-07-30 08:28 PM Re: new cool project find the pcname of user and list it! [Re: Mart]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Ultimately, you can get that information with PsLoggedon.

 Code:
psloggedon DOMAIN\username

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

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
hey mart

how am I able to put the output string domain\userA into a variable
to be able to use substr? See my example it does put it to a variable
in DOS but how to do have my kix program read the DOS variable name?
I am missing something? am I clear? thanks of helping me
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195150 - 2009-07-30 09:05 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4621
Loc: The Netherlands
He Robert,

If I read it correctly it puts it in %FindName% right?
You can use DOS variables directly in kix scripts or assign them to a kix variable.

Example:
 Code:
?%FindName% + " is displayed from a DOS variable."


 Code:
$username = %FindName%
?$username + " is displayed from a kix variable."


Edited by Mart (2009-07-30 09:05 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195151 - 2009-07-30 09:06 PM Re: new cool project find the pcname of user and list it! [Re: Mart]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Okay here is my exact question left to solve.

How do I convert the text extracted from the DOS variable name (%FindName%) to a kix variable name?

See I use psloggedon to extact the data to a file like this
 Quote:

shell "cmd.exe /c psloggedon -l -x\\$Element > find.txt"
SHELL "cmd.exe /c for /F "delims=" %a in ('findstr /c:DOMAIN\ find.txt') do set FindName=%a"


I have my DOS variable name. How can I conver a DOS variable name to a kix variable name to display it?? I feel so clueless?
Thanks

this is the last missiing link...I need..Thank you for your help


Edited by itdaddy (2009-07-30 09:11 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195153 - 2009-07-30 09:09 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4621
Loc: The Netherlands
See my second example in the post above.

It puts the value of %FindName% into $username.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#195154 - 2009-07-30 09:12 PM Re: new cool project find the pcname of user and list it! [Re: Mart]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Yeah mart
sorry must have just missed your post hhaahaaha
thanks so much
this little program is really going to be cool
will post it back soon
this was the last thing I needed thanks so much
trying it now
-Robert
;\) you the man Mart !
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195157 - 2009-07-30 10:01 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
Problem Mart

I have the for command working and it does extract data
from the file find.txt and set the DOS variable to FindName
but what it doesnt do is for some reason the DOS variables
are not being read by KIX??? the % sign at the end of %FindName% is black in my color editor which tells me it doesnt work and kix gives and error
and things %FindName% is some kind of comand? what am I doing wrong?
it is exactly as it is below?

 Quote:


Break On

shell "cmd.exe /c for /F %%a in ('findstr /c:DOMAIN\ c:\find.txt') do set FindName=%%a"


? %FindName% + ' DOS variable name'

$username = %FindName%
? $username + ' is displayed from a kix variable.'


sleep 30



this gives me this? not sure why it isnt reading dos variable?
when it type SET at DOS prompt I get a bunch of variables
and for sure this one
FindName=Domain\userA

it is defined but will not pull it Not sure why kix wont read the dos var??


Edited by itdaddy (2009-07-30 10:10 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195158 - 2009-07-30 10:33 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
 Quote:

shell "cmd.exe /c for /F %%a in ('findstr /c:BULLSEYE\ c:\find.txt') do set FindName=%%a"


Like this works onthe command prompt
and then you type the word SET and it shows up
FINDNAME=DOMAIN\USerA

but for some reseason it sets it find in kix shell but
doenst retain the value of FINDNAME?
in dos take out the % to leave %a at both ends and then it works if you want to test it yourself but
man we have got to be close huh?
like I said it runs find in kix and even says
SET FINDNAME=DOMAIN\UserA
but when SET is run after in shell "cmd.exe /c SET"
it is gone. but when run in actual DOS prompt it works great???


Edited by itdaddy (2009-07-30 10:49 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195159 - 2009-07-30 10:52 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
Ultimately the best solution is a database

Have a client app that runs at logon to upload: username, PCname, serialnumber, date, time, and IP to a central DB (even MAC addr if you want to do WOL)

Then you can build a simple kixforms app (or whatever) that can read db for whatever info you need

There are a few steps, but the most involved is building your SQL server
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#195160 - 2009-07-30 11:00 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4621
Loc: The Netherlands
Ok, lets dump some of the DOS stuff.

You have an app called psloggedon that creates the found.txt text file right?

You can use the ReadFile UDF to read the entire file into memory after psloggedon created it. Then do a line by line check to see if it is the domain\username line and do some things if it is. This way you do not need to set a DOS environment variable to use the username in kix. This eliminates a point of error.

Example:
 Code:
Break on

;Read the entire file into memory. Change the path to fit your setup.
$file = ReadFile("c:\found.txt")

;Do the magic on each separate line.
For Each $line in $file
	;Check to see if the line starts with DomainName\. Change this to fit your setup.
	;Also change the 11 to match the number of characters for your domain + a \.
	If Left($line, 11) = "Domainname\"
		;Split the line on the \.
		$line = Split($line, "\")
		;Display the last element of the array you just created by splitting the line.
		? $split[UBound($split)]
	EndIf
Next


;Function	ReadFile()  
;  
;Author		Radimus  
;  
;Contributors	Lonky... This is basically his code that I trimmed down to its  
;		simplest function  
;  
;Action		Reads a file into an array  
;  
;Syntax		$array=ReadFile($file)  
;  
;Version	1.0.1  
;  
;Date           10/21/2003  
;  
;Date Revised   10-22-2003 - dimmed vars 
;  
;Parameters 	file   
;		source filename  
;  
;Remarks	Pair this with WriteFile() to read and write an entire file easily  
;  
;Returns	@error if failed  
;   
;Dependencies 	None  
;  
;KiXtart Ver	4.02  
;   
;Example(s)	$array=ReadFile('c:\file.txt')  

Function ReadFile($file)
	Dim $lf, $f, $_, $t
	$lf = Chr(10)
	$f = FreeFileHandle
	$_ = Open($f, $file)
	If @error Exit @error EndIf
	Do $t = $t + $lf + ReadLine($f) Until @error
	$_ = Close($f)
	$ReadFile = Split(SubStr($t, 2), $lf)
EndFunction
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

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

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
hey guys thanks
will look into both of those ;\) thanks for your help
;\)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195164 - 2009-07-31 08:03 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...
itdaddy -
Why are you using external programs when you can get everthing you are looking for with KiX Macro's..

@WKSTA = PC Name
@UserID = UserID

Dump it to a file, database whatever you want.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#195178 - 2009-07-31 12:35 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4242
Loc: New Jersey
 Originally Posted By: itdaddy
 Quote:

shell "cmd.exe /c for /F %%a in ('findstr /c:BULLSEYE\ c:\find.txt') do set FindName=%%a"


Like this works onthe command prompt
and then you type the word SET and it shows up
FINDNAME=DOMAIN\USerA

but for some reseason it sets it fine in kix shell but
doenst retain the value of FINDNAME?

Child processes are like teenage children.. old enough to drive but not old enough to put gas in the car. ;\)

When you run such a command from a "DOS" window, you own the resources.
SET PIE=BLUEBERRY
You now have a blueberry pie in your environment
CMD
You now have a (teenage) child process. You, being a mature adult, have shared your pie. A SET will confirm that the blueberry pie is there.
SET PIE=CHERRY
SET CAKE=CHOCOLATE
Your child eats the Blueberry pie and bakes (himself) a Cherry pie. Since the oven's hot, he bakes a chocolate cake. SET shows both in his environment.
EXIT
He leaves, heading to hang with his buds..
Look around..
SET
Hey! Where's the cake? Why do I have this old Blueberry pie and not some fresh Cherry pie? (In typical teenage fashion, you hear "Oh, did ya want some of that?" as he drives away.

Computer processes have a similar parent/child relationship (without the cost of gas). When you run a command, it establishes an environment, with a set of values. When that command runs another external command, it (the "child" process) establishes its own environment, starting with a copy of the parent process environment. The child is free to do anything it wants to its environment, knowing it won't affect its parent or any other sibling. Thus, when the child process terminates, its environment is destroyed.

The commands you enter at the command prompt are being run IN the current environment - you are not spawning a child process, so the results affect the current environment.

When you run a Kix script, it establishes an environment. You SHELL to a CMD shell to run the same commands - this creates a child environment where the environment var is created, and then destroyed when the shell exits.

Basically, what you're trying to do is not possible using environment vars. That's why there are other tools to run sub-commands and return data, such as WSHPipe(). Still, everything you want to do can be done natively from Kix.

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

Top
#195181 - 2009-07-31 04:06 PM Re: new cool project find the pcname of user and list it! [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Garygole
Glenn! Hey G and G

yeah I know I know...but I wanted to use psloggedon -l -x \\$Element > find.txt

and the use the findstr command but I realized like I think Glenn you are eluding too haha or smashing me in the face hahah
yeah I realize the variable is only good for that session and once that shell closes the variable is gone which I thin is stupid. I wonder fir windows environemntal vaariable are reinitiated each time the they load, they must be?

I just want to make it simple and then compile it with gui kix2exe and run it localy on my 2 pcs for the remote desk help so they can get pc names based off of user name in a table displayed on the screen..

i wanted to make it simple but seems more difficult that i think once I am done will post it back here for you to see. I am not done with it yet!
THANKS GLENN AND GARG FOR YOUR HELP!
-Robert ;\)
aka itdaddy
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

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

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Glenn not only did you teach me somthing but you made me hungry for blueberries and pie and made me laugh so hard great analogy!
I appreicate you knowledge...
;)I wanted something simple and effective and done from centralized location. I didnt want to run scripts on each pc which I could.
and the users change throughout the day so logon script wouldnt work.
Below is my program in crude form once I got the data was going to print on the fly this:

Location 4th ave

pcname user
pcname user

Location 8th street

pcname user
pcname user

 Quote:

Break On

$Branch = "PC1", "PC2", "PC3"


For each $Element in $Branch

shell "cmd.exe /c psloggedon -l -x \\$Element > find.txt "
shell "cmd.exe /c findstr /c:BULLSEYE\ find.txt >> findlist.txt"

Next
shell "cmd.exe /c type findlist.txt"
sleep 30


Edited by itdaddy (2009-07-31 04:12 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195183 - 2009-07-31 04:26 PM Re: new cool project find the pcname of user and list it! [Re: itdaddy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4242
Loc: New Jersey
Since you want to query remote computers from a central location, I'd suggest that "WMI is your friend..."

Look at WMIAuthentication(), WMIQuery(), and WMISysInfo() for a good starting point. If you are running the script as a domain admin, you won't need the WMIAuth UDF. WMISysInfo returns lots of info about the O/S and hardware, and could be modified to include the currently logged on users - there are two "Reserved for Future Use" values that could be used for that.

WMIQuery allows you to perform ad-hoc queries. It's the least efficient method of all the WMI-type UDFs because it instantiates a connecetion for each query, but allows you to query anything. (WMISysInfo returns 38 pieces of data in a few seconds.. making 38 individual queries with WMIQuery could take more than a minute.) It's a great UDF when you need 1-2 pieces of data, or want to prototype a more complex set of queries.

Check my web site for the most current versions of these UDFs.

Search for and install "Kix-O-Matic" for a GUI tool that will help you determine which WMI objects are appropriate for your needs, and then generate sample code.

Enjoy the pie!

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

Top
#195185 - 2009-07-31 05:42 PM Re: new cool project find the pcname of user and list it! [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Glenn is this the function i used to do the query? so I can use kix
while using the udf write?
 Quote:


Function WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root, Optional $pAuth)



so do I use the what and from parameters in the windows_32 object
how can I query a user on a remote machine. I want query a remote machine
get the local user off of it and run it thru a loop of machine names.
I have the LDAP function off of this site that works well pulling machine names from their respective OUs and then it will print something like this. I do not want it tooo complex just tthis:

Location: 4th ave

pcname1 rvandyke
pcname2 rmueller
pcname3 bmuellerc

Location: 8th street

pcname4 zmiller
pcname5 kstiller
pcname6 bbubba


something like that so I can do a visual scan of the branches and see
their name and pcname they are at...real simple but powerful results!

i just need to be pointed in right direction. I really dont know how to start your cool function wow! thanks



Edited by itdaddy (2009-07-31 05:53 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Allen) and 37 anonymous users online.
Newest Members
FlyHorton, mschwj, Barchester, Evgeniy, kvanacker
17498 Registered Users

Generated in 0.044 seconds in which 0.01 seconds were spent on a total of 14 queries. Zlib compression enabled.

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