Page 1 of 1 1
Topic Options
#195237 - 2009-08-04 04:58 PM help! looping a wmi kix? wt??
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Hey guys what am I doing wrong?
I want to have my code loop thru and array...how do I do that with wmi?
I am looking for the wmi object that can give me pcname and locally loggedon person...man is it hard to find these attributes that match the object class???help do you guys know which object class has the pcname and locally logged on person? that is all I need grrrr help!

 Quote:


Break On
$Branch = "emsr8", "emsr7"

For each $Element in $Branch
$strComputer = $Element
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Account",,48)
For each $objItem in $colItems
"Caption: " + $objItem.Caption ?
"Description: " + $objItem.Description ?
"Domain: " + $objItem.Domain ?
"InstallDate: " + $objItem.InstallDate ?
"LocalAccount: " + $objItem.LocalAccount ?
"Name: " + $objItem.Name ?
"SID: " + $objItem.SID ?
"SIDType: " + $objItem.SIDType ?
"Status: " + $objItem.Status ?
?
Next
Next




_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195238 - 2009-08-04 06:47 PM Re: help! looping a wmi kix? wt?? [Re: itdaddy]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
That class won't give you that information. Try this:

 Code:
For each $Element in $Branch
   $objWMIService = GetObject("winmgmts:\\" + $Element + "\root\cimv2")
   $colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
   For each $objItem in $colItems
     "PC Name: " + $objItem.Name ?
     "UserName: " + $objItem.UserName ?
     ?
   Next
Next


Edited by eriqjaffe (2009-08-04 06:49 PM)

Top
#195239 - 2009-08-04 08:45 PM Re: help! looping a wmi kix? wt?? [Re: eriqjaffe]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
eriqjaffe

thanks you finally someone who knows what I need haha

hey I tried it and it is not working? I am using

wkix32.exe test1.kix
and it is not runing. I added

$Branch = "pc1", "pc2"

what am i doing wrong. did you test it yourself? does it work for you?
thank you
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195240 - 2009-08-04 08:57 PM Re: help! looping a wmi kix? wt?? [Re: eriqjaffe]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
This works but when I put in a pcname that is not the machine I am running
this on, I get an error something ')' is not correct? blah blah
I want to run this on a one machine and I want to have arrays
like
$Branch = "pc1", "pc2", "pc3"

how can I get to work in the below code??????
runnning it locally it works fine but I want to run remmote PCnames thru
an array?
 Quote:


I Guess the question to ask is "Can I run remote pcnames through this code in a for each next loop to access the remote pcname and local user name?
or does this work only for local pcnames? If I use the local pc name it works, but if I put in a pcname that is not the local machine name, it erros out? what am I doing wrong /???anyone thanks







 Quote:


Break On


$Element = "LOCALPCNAME"

$objWMIService = GetObject("winmgmts:\\" + $Element + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)

For each $objItem in $colItems
"PC Name: " + $objItem.Name ?
"UserName: " + $objItem.UserName ?
?
Next
sleep 20


 Quote:


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

Top
#195241 - 2009-08-04 09:04 PM Re: help! looping a wmi kix? wt?? [Re: itdaddy]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
Not sure why it's not working for you. The following:

 Code:
$Branch = @WKSTA,"PC1","PC2"

For each $Element in $Branch
   $objWMIService = GetObject("winmgmts:\\" + $Element + "\root\cimv2")
   $colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
   For each $objItem in $colItems
     "PC Name: " + $objItem.Name ?
     "UserName: " + $objItem.UserName ?
     ?
   Next
Next


gives me the following output:

 Code:
PC Name: ERIQJ
UserName: DOMAIN\eriqj

PC Name: PC1
UserName: DOMAIN\amandak

PC Name: PC2
UserName: DOMAIN\juanc


Edited by eriqjaffe (2009-08-04 09:05 PM)

Top
#195242 - 2009-08-04 09:18 PM Re: help! looping a wmi kix? wt?? [Re: eriqjaffe]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
OMG I need to run it on a DOmain admin machine with domain admin
rights. duh!
Itw works yeah youa re a genius!

dude you are a genius it owrk perfect ;\) yeahooooooooooooo
thank you thankyou
as soon as I ran it on our DC it work fantatsic yeah!
you the man!
-robert
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195243 - 2009-08-04 09:28 PM Re: help! looping a wmi kix? wt?? [Re: eriqjaffe]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
hey I am using kix2exe gui and is there a wkix2exe?? i get compile errors
i want to package thsi program as an exe?
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#195244 - 2009-08-04 09:36 PM Re: help! looping a wmi kix? wt?? [Re: itdaddy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4370
Loc: New Jersey
You should not need to run it from your DC. In fact, you should not run anything from your DC, for the sake of network security.

When you run admin scripts, you need to invoke them with admin rights. I've defined an environment variable called SUID on my workstation that contains the account name for my admin-privelege account. (ie SUID=SuperGlenn). Then, I have a little batch file called SUW.BAT that contains the following code:
 Code:
RunAs /profile /user:%SUID% cmd.exe
Opening a command prompt and typing SUW prompts me for my admin password. Once entered, it opens a new command prompt window with network admin rights, from where I can run any of my admin scripts.

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

Top
#195246 - 2009-08-04 10:07 PM Re: help! looping a wmi kix? wt?? [Re: itdaddy]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
 Originally Posted By: itdaddy
hey I am using kix2exe gui and is there a wkix2exe?? i get compile errors
i want to package thsi program as an exe?
You can choose whether you want to use kix32 or wkix32 in the kix2exe gui (look under "KiXtart Processor"). Just make sure that the wkix32 executable is in the \bin\kix path wherever you have kix2exe.

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
0 registered and 228 anonymous users online.
Newest Members
karimKix, NicoK, Kelly001, MichaelK72, Janneman
17775 Registered Users

Generated in 0.057 seconds in which 0.021 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