Page 1 of 1

PureBasic and WMI

Posted: Mon Apr 26, 2004 11:45 pm
by sabre
Hi - I am a new user to Purebasic actually bought it a while back but never really used it until now. I need to make a little utility which I can do really easy in Vbscript and WMI but wanted to make it in Purebasic if it is possbile?

Does anybody know if I can use WMI or similar to grab the following info from a PC:

1. Workstation: name, make, model, Serial #
2. Operating System: Type, version
3. Processor, Speed
4. Memory: total
5. Drives: C: total and free
6. Installed software

Then save the results as a text file and automatically load it as an attachment in their email program most likely outlook/outlook express.

Any help or pointers to some sample source code would be greatly appreciated. I am new to PB so pardon my questions.

Thanks so much in advance.

Posted: Tue Apr 27, 2004 6:56 am
by bingo
8)
use this userlib ...
http://www.purearea.net/pb/download/use ... ontrol.zip
to run pb-program with "embeded" vbs-script !

Thanks

Posted: Tue Apr 27, 2004 4:04 pm
by sabre
Thanks Bingo!! Can this be used in a commercial project?

Posted: Wed May 12, 2004 8:29 am
by bingo
a other (directly) way ...

use "CoCreateInstance" to connect WMI like:
http://msdn.microsoft.com/library/en-us ... espace.asp

who can translate this in PB (make a sample) ?

"embedded" vbs without userlib ...

Posted: Sat Jul 10, 2004 10:26 am
by bingo
without userlib :lol:

thanks to aXend viewtopic.php?t=11031 for interface - generator !

vbs "tmp.vbs" to call any wmi ...

Code: Select all

strComputer = "." 
soft = "" 
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set colSoftware = objWMIService.ExecQuery  ("Select * from Win32_Product") 
For Each objSoftware in colSoftware 
soft = soft & objSoftware.Description & chr(10) & chr(13) 
Next
embedded script ... and read (EVAL()) any variable

Code: Select all

Structure Variant 
    Type.w 
    Reserved1.w 
    Reserved2.w    
    Reserved3.w 
    String.l 
EndStructure 

#VT_BSTR = 8 
x.Variant\Type = #VT_BSTR 

DataSection 
meine_vbs: 
  IncludeBinary "tmp.vbs" 
  Data.b 0 
EndDataSection 

Procedure.l Ansi2Uni(ansi.s) 
  size.l=MultiByteToWideChar_(#CP_ACP,0,ansi,-1,0,0) 
  Dim unicode.w(size) 
  MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), size) 
  ProcedureReturn @unicode()  
EndProcedure 

Procedure.s Uni2Ansi(*Unicode.l) 
  size.l = WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, #Null, #Null, #Null, #Null) 
  ansi.s=Space(size) 
  WideCharToMultiByte_(#CP_ACP, 0, *Unicode, -1, @ansi, size, #Null, #Null) 
  ProcedureReturn ansi  
EndProcedure 

Enumeration ; ScriptControlStates 
  #Initialized = 0 
  #Connected = 1 
EndEnumeration 

; DispInterfaces 

Interface IScriptProcedure Extends IDispatch 
  get_Name(a) 
  get_NumArgs(a) 
  get_HasReturnValue(a) 
EndInterface 

Interface IScriptProcedureCollection Extends IDispatch 
  get__NewEnum(a) 
  get_Item(a,b,c,d,e) 
  get_Count(a) 
EndInterface 

Interface IScriptModule Extends IDispatch 
  get_Name(a) 
  get_CodeObject(a) 
  get_Procedures(a) 
  AddCode(a) 
  Eval(a,b) 
  ExecuteStatement(a) 
  Run(a,b,c) 
EndInterface 

Interface IScriptModuleCollection Extends IDispatch 
  get__NewEnum(a) 
  get_Item(a,b,c,d,e) 
  get_Count(a) 
  Add(a,b,c) 
EndInterface 

Interface IScriptError Extends IDispatch 
  get_Number(a) 
  get_Source(a) 
  get_Description(a) 
  get_HelpFile(a) 
  get_HelpContext(a) 
  get_Text(a) 
  get_Line(a) 
  get_Column(a) 
  Clear() 
EndInterface 

Interface IScriptControl Extends IDispatch 
  get_Language(a) 
  put_Language(a) 
  get_State(a) 
  put_State(a) 
  put_SitehWnd(a) 
  get_SitehWnd(a) 
  get_Timeout(a) 
  put_Timeout(a) 
  get_AllowUI(a) 
  put_AllowUI(a) 
  get_UseSafeSubset(a) 
  put_UseSafeSubset(a) 
  get_Modules(a) 
  get_Error(a) 
  get_CodeObject(a) 
  get_Procedures(a) 
  _AboutBox() 
  AddObject(a,b,c) 
  Reset() 
  AddCode(a) 
  Eval(a,b) 
  ExecuteStatement(a) 
  Run(a,b,c) 
EndInterface 

CoInitialize_(0) 
If CoCreateInstance_(?CLSID_ScriptControl,0,1,?IID_IScriptControl,@Object.IScriptControl) = 0 

object\reset() 
object\put_Language(Ansi2Uni("vbscript")) 
object\AddCode(Ansi2Uni(PeekS(?meine_vbs))) 
; 
object\Eval(Ansi2Uni("soft"),@x) 
meine_variX.s = UCase(uni2ansi(x\String)) 
; 
object\reset() 
; 
object\release() 

EndIf 
CoUninitialize_() 

MessageRequester("vbs variable",meine_variX,#PB_MessageRequester_Ok) 

DataSection 
  CLSID_ScriptControl: 
  Data.l $0e59f1d5 
  Data.w $1fbe,$11d0 
  Data.b $8f,$f2,$00,$a0,$d1,$00,$38,$bc 
    
  IID_IScriptControl: 
  Data.l $0e59f1d3 
  Data.w $1fbe,$11d0 
  Data.b $8f,$f2,$00,$a0,$d1,$00,$38,$bc 
EndDataSection
no problems if 'msscript.ocx' present and register (default in me/2000/xp)