#195144 - 2009-07-30 05:30 PM
new cool project find the pcname of user and list it!
|
itdaddy
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
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
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?
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
|
|
|
|
#195148 - 2009-07-30 08:28 PM
Re: new cool project find the pcname of user and list it!
[Re: Mart]
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
Ultimately, you can get that information with PsLoggedon.
psloggedon DOMAIN\username
|
Top
|
|
|
|
#195151 - 2009-07-30 09:06 PM
Re: new cool project find the pcname of user and list it!
[Re: Mart]
|
itdaddy
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
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
|
|
|
|
#195157 - 2009-07-30 10:01 PM
Re: new cool project find the pcname of user and list it!
[Re: itdaddy]
|
itdaddy
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?
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
Starting to like KiXtart
Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
|
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
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
|
Top
|
|
|
|
#195178 - 2009-07-31 12:35 PM
Re: new cool project find the pcname of user and list it!
[Re: itdaddy]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
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!
|
Top
|
|
|
|
#195182 - 2009-07-31 04:08 PM
Re: new cool project find the pcname of user and list it!
[Re: Glenn Barnas]
|
itdaddy
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
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
|
|
|
|
#195185 - 2009-07-31 05:42 PM
Re: new cool project find the pcname of user and list it!
[Re: Glenn Barnas]
|
itdaddy
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?
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 262 anonymous users online.
|
|
|