Page 1 of 2 12>
Topic Options
#116172 - 2004-03-16 01:19 PM Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Hey kix gurus,

I have problem running WMIQuery against XP clients on domain B, from domain A. I think its because the permissions. when I running WMIQuery from Domain A to a client on Domain B I dont get any output, while its working if I run query to a client on domain A. I have domain admin account for Domain B. I need to know how to execute WMIQuery from Domain A using the admin account for domain B.

Im ruunig win2000 + Kix 4.22 and Kixforms 2.3.0.42

Any ideas?

BR /C
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116173 - 2004-03-16 01:40 PM Re: Using specific account to run WMIQuery
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
If you don't have a working trust relationship, and the user credentials between the domains are not identical, it should fail with Access Denied.

Download the latest WMIQuery revision and try adding the user credentials (DOMAINB\user passwd) to the UDF call.

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

Top
#116174 - 2004-03-16 03:19 PM Re: Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
trust relationship works fine, but No output!
What im doing worng?

$sIP = "196.168.0.20" ; (or client host name)
$sUserID = "DomainB\Admin"
$sUserPW = "passwd"

$users=WMIQuery('UserName','Win32_ComputerSystem',$sIP,$sUserID,$sUserPW)

? $users

Function WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root, Optional $sUserID, Optional $sUserPW)
Dim $sQuery, $objEnum, $sValue, $TMP, $SystemSet, $, $objInstance, $objLocator

$sComputer = Trim(Join(Split($sComputer,'\'),''))
If NOT $sComputer OR $sComputer = @wksta
$sComputer = '.'
EndIf
If NOT $root
$root = '\root\cimv2'
EndIf
$sQuery = 'Select ' + $sWhat + ' From '+ $sFrom
If $sWhere AND $x
$sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'"
EndIf
If $sUserID AND $sUserPW AND $sComputer <> '.'
$objLocator = CreateObject('WbemScripting.SWbemLocator')
If @ERROR OR NOT $objLocator Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$SystemSet = $objLocator.ConnectServer($sComputer, $root, $sUserID, $sUserPW)
If @ERROR OR NOT $SystemSet Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
$SystemSet.Security_.ImpersonationLevel = 3
Else
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root)
If @ERROR OR NOT $SystemSet Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
EndIf
$objEnum = $SystemSet.ExecQuery($sQuery)
If @ERROR OR NOT $objEnum Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf
For Each $objInstance in $objEnum
$=Execute(Chr(36) + 'sValue = ' + Chr(36) + 'objInstance.' + $sWhat)
If VarType($sValue) & 8192
$tmp = $tmp +'|' + Join($sValue,'|')
Else
$tmp = $tmp +'|' + $sValue
EndIf
Next
$WMIQuery = Split(SubStr($tmp,2),'|')
Exit Val("&"+Right(DecToHex(@ERROR),4))
EndFunction
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116175 - 2004-03-16 03:24 PM Re: Using specific account to run WMIQuery
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
you are missing the commas for the additional optional parameters thet you aren't using.

WMIQuery($sWhat,$sFrom,$sComputer,,,,$sUserID,$sUserPW)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#116176 - 2004-03-16 03:34 PM Re: Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
WMIQuery($sWhat,$sFrom,$sComputer,,,,$sUserID,$sUserPW)

Not working either :-(
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116177 - 2004-03-16 03:47 PM Re: Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
What about this fnWMIAuthentication() ?
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116178 - 2004-03-16 04:03 PM Re: Using specific account to run WMIQuery
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
what erre msg is it returning
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#116179 - 2004-03-16 04:15 PM Re: Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
No error... no value returns...hummm getting realy confused..
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116180 - 2004-03-16 04:54 PM Re: Using specific account to run WMIQuery
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Soemthing will get returned or displayed. So, put more error checking into the script and use DEBUG ON to step through the code.
_________________________
There are two types of vessels, submarines and targets.

Top
#116181 - 2004-03-16 04:59 PM Re: Using specific account to run WMIQuery
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
try it against the local machine without creds, then with creds, the a remote machine in your domain, and then outside the domain

it will return an error code, check that
it returns values in arrays, chaek that
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#116182 - 2004-03-17 04:00 AM Re: Using specific account to run WMIQuery
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
The wmi authentication was integrated with the query last month. no need for a separate authentication call.

Personally, I like to add little print statements - even just " '.' " every couple of lines to see the progress. Even better is printing out vars and major decision points - not so much to debug the UDF (this should already be done) but to debug the arguments I'm passing to it and to make sure it's interpreting the data correctly!

I'd follow Radimus' recommendations - start close and work your way more complex.

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

Top
#116183 - 2004-03-17 10:50 AM Re: Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Glenn how do i do that "print statements - even just " '.' " every couple of lines to see the progress"

Can you provide an example please?
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116184 - 2004-03-17 01:35 PM Re: Using specific account to run WMIQuery
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Like this:

Code:
  
; $System defines local machine (null) or remote server name
$System = SNVerify($HostName)
$System ? ; <-----<<



If KeyExist($System + $RegSoft + 'Windows NT') <> 0
'NT' ? ; <-----<<
$SClass = '' ; no "D" prefix
$NT = ' NT' ; " NT" required in Windows registry path

Else
'Desktop' ? ; <------<<
$SClass = 'D' ; "D" prefix for desktop systems
$NT = '' ; no NT in Windows registry path
$OS_Sp = 0 ; service pack level (none)
$OS_Role = 'Workstation' ; Workstation role

EndIf
'.' ? ; <-----<<




Note the variable printouts, messages, and '.' output. The '.' is useful for long processes and iterations, just to know something is happening, or to determine how far the script has progressed.

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

Top
#116185 - 2004-03-18 02:31 PM Re: Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
I get this "-2147352567"
Do u know what it means ?
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116186 - 2004-03-18 03:24 PM Re: Using specific account to run WMIQuery
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
No - your information is without context!

The point of the exercise is to place meaningful print statements in the code you're debugging so you can see if you are providing the correct input, and it is being interpreted correctly. Sometimes a UDF will expect a number and you pass it a string (because it ends in a space).. I like to print numbers between other chars - like
"X=" $X "!" ?
With the trailing "!", you can see if there are spaces before or after the number contained in $X.

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

Top
#116187 - 2004-03-18 03:26 PM Re: Using specific account to run WMIQuery
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You should also use @SERROR to translate the error number and any of the error UDFs to translate COM errors to Win32 errors.
_________________________
There are two types of vessels, submarines and targets.

Top
#116188 - 2004-03-18 04:44 PM Re: Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
What about this one then?

-2147352567
COM exception error "ConnectServer" (SWbemLocator - Invalid parameter
) [-2147352567/80020009]
The storage control block address is invalid.

This is getting to complex for me :-(
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116189 - 2004-03-18 05:42 PM Re: Using specific account to run WMIQuery
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Works Fine

Code:
 Break On


$sWhat = "UserName"
$sFrom = "Win32_ComputerSystem"
$sIP = "196.168.0.20" ; (or client host name)
$sUserID = "DomainB\Admin"
$sUserPW = "passwd"



? WMIQuery($sWhat, $sFrom,$sComputer,$sWhere,$x,$root,$sUserID,$sUserPW)[0]



Beware that if you running this remotely with admin rights you will need to look at array element [1], as [0] will be the username you are running the process with.

Another Way would be:

Code:
For $object = 0 to Ubound(WMIQuery($sWhat, $sFrom,$sComputer,$sWhere,$x,$root,$sUserID,$sUserPW))

? 'UserName: '+WMIQuery($sWhat, $sFrom,$sComputer,$sWhere,$x,$root,$sUserID,$sUserPW)[$Object]
? 'Array Element: '+$Object
Next



OR

Code:
If Ubound(WMIQuery($sWhat, $sFrom,$sComputer,$sWhere,$x,$root,$sUserID,$sUserPW)) >0

? 'UserName: '+WMIQuery($sWhat, $sFrom,$sComputer,$sWhere,$x,$root,$sUserID,$sUserPW)[1]
Else
? 'UserName: '+WMIQuery($sWhat, $sFrom,$sComputer,$sWhere,$x,$root,$sUserID,$sUserPW)[0]
EndIf



Rich


Edited by Richard Farthing (2004-03-18 06:02 PM)

Top
#116190 - 2004-03-18 06:28 PM Re: Using specific account to run WMIQuery
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Richard thanx for feedback, but no success for me :-(
The array element [1], gives me nothing and [0] will return the username im running the process with.
Also same phenomen as above.
Running this on any client on the same domain as I am log on to, works fine. But If I do query to any client on another domain give me nothing.
This even I define domain admin username and passwd for target domain.
Problem persist :-(
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#116191 - 2004-03-18 06:31 PM Re: Using specific account to run WMIQuery
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Is WMI security on the other domain's computers set up to allow access from your domain?
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 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 1057 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.081 seconds in which 0.03 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