WMI Reader

Share your advanced PureBasic knowledge/code with the community.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

WMI Reader

Post by doctorized »

This is a small program I made. It shows data from every WMI class.
Get it from: http://kc2000labs.shadowtavern.com/pb/z ... r_4.41.zip
Last edited by doctorized on Sat Jan 14, 2017 12:07 pm, edited 1 time in total.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: WMI Reader

Post by srod »

Nice. Could be useful.

Thanks. :)
I may look like a mule, but I'm not a complete ass.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: WMI Reader

Post by doctorized »

This app deals with a small problem. Procedure bstr2string is not returning right letters with
ascii 184 to 255. Any suggestions?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: WMI Reader

Post by srod »

Try :

Code: Select all

Procedure bstr2string (bstr)
  Shared result.s
  result = PeekS(bstr, -1, #PB_Unicode)
  ProcedureReturn @result
EndProcedure
When converting to/from Ansi/Unicode you should use combinations of PokeS() and PeekS() because these will take the current Ansi code-page into account etc. Your methods of poking individual 16-bit values will not do this and will produce incorrect results (as you discovered) for character codes in excess of 127 (Ascii).
I may look like a mule, but I'm not a complete ass.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: WMI Reader

Post by doctorized »

srod wrote:Try :

Code: Select all

Procedure bstr2string (bstr)
  Shared result.s
  result = PeekS(bstr, -1, #PB_Unicode)
  ProcedureReturn @result
EndProcedure
Thanx a lot again! The problem got solved. I made a small change to accept a bigger range of custom WMI classes to run.
(Now it can run expresions like: 'Select Caption from Win32_cdromdrive')
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: WMI Reader

Post by netmaestro »

Very fine contribution! Code is useful and well explained, thanks so much for this. 8)
BERESHEIT
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: WMI Reader

Post by doctorized »

netmaestro wrote:Very fine contribution! Code is useful and well explained, thanks so much for this. 8)
I believe that "knowledge is for everyone and must be for free". Enjoy!
User avatar
bingo
Enthusiast
Enthusiast
Posts: 210
Joined: Fri Apr 02, 2004 12:21 pm
Location: germany/thueringen
Contact:

Re: WMI Reader

Post by bingo »

:D thanks from germany!
["1:0>1"]
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: WMI Reader

Post by doctorized »

If I compile my code in Unicode then it fails to run, MessageRequester "unable to call IWbemLocator::ConnectServer" pops up.
Does anyone know why? It must have to do with the "root\cimv2" string that is passed as variable but how can it be fixed?

Edit
PROBLEM SOLVED.
See the new code that supports unicode and non-unicode compilation.
Post Reply