code works with button1, but doesnt send via socket

boycoder
boycoder used Ask the Experts™
on
It works on my local machine via button1, however i can't figure out the string i need to send and recieve.


function _VarToStr(const V: variant): string;
    var
    Vt: integer;
    begin
    Vt := VarType(V);
        case Vt of
          varSmallint,
          varInteger  : Result := IntToStr(integer(V));
          varSingle,
          varDouble,
          varCurrency : Result := FloatToStr(Double(V));
          varDate     : Result := VarToStr(V);
          varOleStr   : Result := WideString(V);
          varBoolean  : Result := VarToStr(V);
          varVariant  : Result := VarToStr(Variant(V));
          varByte     : Result := char(byte(V));
          varString   : Result := String(V);
          varArray    : Result := VarArrayToStr(Variant(V));
        end;
    end;

var
i : integer;
begin
    Result := '[';
     if (VarType(vArray) and VarArray)=0 then
       Result := _VarToStr(vArray)
    else
    for i := VarArrayLowBound(vArray, 1) to VarArrayHighBound(vArray, 1) do
     if i=VarArrayLowBound(vArray, 1)  then
      Result := Result+_VarToStr(vArray[i])
     else
      Result := Result+'|'+_VarToStr(vArray[i]);

    Result:=Result+']';
end;

function VarStrNull(const V:OleVariant):string; //avoid problems with null strings
begin
  Result:='';
  if not VarIsNull(V) then
  begin
    if VarIsArray(V) then
       Result:=VarArrayToStr(V)
    else
    Result:=VarToStr(V);
  end;
end;


function GetWMIObject(const objectName: String): IDispatch; //create the Wmi instance
var
  chEaten: Integer;
  BindCtx: IBindCtx;
  Moniker: IMoniker;
begin
  OleCheck(CreateBindCtx(0, bindCtx));
  OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker));
  OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result));
end;



procedure  GetAntiVirusProductInfo;
var
 objWMIService : OLEVariant;
 colItems      : OLEVariant;
 colItem       : OLEVariant;
 oEnum         : IEnumvariant;
 iValue        : LongWord;
begin;
 objWMIService := GetWMIObject('winmgmts:\\localhost\root\SecurityCenter2');

 colItems      := objWMIService.ExecQuery('SELECT * FROM AntiVirusProduct','WQL',0);
 oEnum         := IUnknown(colItems._NewEnum) as IEnumVariant;
 while oEnum.Next(1, colItem, iValue) = 0 do
 begin
   Writeln(Format('displayName                    %s',[VarStrNull(colItem.displayName)]));// String
   Writeln(Format('instanceGuid                   %s',[VarStrNull(colItem.instanceGuid)]));// String
   Writeln(Format('pathToSignedProductExe         %s',[VarStrNull(colItem.pathToSignedProductExe)]));// String
   Writeln(Format('pathToSignedReportingExe       %s',[VarStrNull(colItem.pathToSignedReportingExe)]));// String
   Writeln(Format('productState                   %s',[VarStrNull(colItem.productState)]));// Uint32
   Writeln('');
 end;
end;



////SENDING INFO BACK TO MY CLIENT ///
   COMMAND_GETAV:
     begin
      GetAntiVirusProductInfo;

        SENDCOMMAND(COMMAND_GETAV,(GetAntiVirusProductInfo)socket);
        END;



///recieivng from server///

 COMMAND_GETAV:            Writeln(Edata); 
/// im sure this needs to be Writein(GetAntiVirusProductInfo);
// ??

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Freelance Project Manager
Top Expert 2010
Commented:
here you go
Function GetAntivirusProductInfoAsString:String;
var
 objWMIService : OLEVariant;
 colItems      : OLEVariant;
 colItem       : OLEVariant;
 oEnum         : IEnumvariant;
 iValue        : LongWord;
begin;
 objWMIService := GetWMIObject('winmgmts:\\localhost\root\SecurityCenter2');
 colItems      := objWMIService.ExecQuery('SELECT * FROM AntiVirusProduct','WQL',0);
 oEnum         := IUnknown(colItems._NewEnum) as IEnumVariant;
 Result:='';
 while oEnum.Next(1, colItem, iValue) = 0 do
  begin
   Result:=Result+Format('displayName                    %s',[VarStrNull(colItem.displayName)]))+#13#10; // add ret line
   Result:=Result+Format('instanceGuid                   %s',[VarStrNull(colItem.instanceGuid)]))+#13#10;
   Result:=Result+Format('pathToSignedProductExe         %s',[VarStrNull(colItem.pathToSignedProductExe)]))+#13#10;
   Result:=Result+Format('pathToSignedReportingExe       %s',[VarStrNull(colItem.pathToSignedReportingExe)]))+#13#10;
   Result:=Result+Format('productState                   %s',[VarStrNull(colItem.productState)]))+#13#10;
   Result:=Result+#13#10; // add an empty line at end of each block
  end;
end;

////SENDING INFO BACK TO MY CLIENT ///
   COMMAND_GETAV:
     begin
      SENDCOMMAND(COMMAND_GETAV,GetAntiVirusProductInfoAsString,socket);
     end;
     
///recieivng from server///
   COMMAND_GETAV: Write(Edata);

Open in new window

Author

Commented:
CHEERS fror help mate, but on

   Result:=Result+Format('displayName                    %s',[VarStrNull(colItem.displayName)]))+#13#10; // add ret line

it gives,

comining signed and unsigned types - widend both operands

Author

Commented:
fixed it ithink 2 secs
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Author

Commented:
outstanding work mate, i cant thankyou enough. may i make another question and you can show me in the same way how to trasnfer a file across, is it the same method?

again, your work is outstanding !!!!!

Author

Commented:
Nothing this guy doesnt know!

Author

Commented:
just a quick Q, instead of recievng the text in the dos,
if i make the format,

COMMAND_GETAV:                 flatlistbox1.items.add(edata) ;

How can i format the listbox so it brings the data back on new lines like in the cmd screen ?
Emmanuel PASQUIERFreelance Project Manager
Top Expert 2010

Commented:
Get the data in a TStringList (it will separate the lines according to line returns characters) and add that to the listbox

Var
 StrList:TStringList;
begin
...
 COMMAND_GETAV:
  begin
   StrList:=TStringList.Create;
   StrList.Text:=EData;
   flatListBox1.Items.AddString(StrList);
   StrList.Free;
  end;

Open in new window

Author

Commented:
undeclared identifer, addstring..
what should i declare mate?

Author

Commented:
flatListBox1.Items:=(StrList);

its ok i did this way mate. cheers!!
Emmanuel PASQUIERFreelance Project Manager
Top Expert 2010

Commented:
Sorry, it was AddStrings

But assigning is the same as it calls AddStrings (and does also a few things not necessary here)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial