Commit e63d51ce3e30a56842e31af45f0c1198d9300d99
1 parent
bd50634a
Exists in
master
Adição de coleta de software através do Registro do Windows
git-svn-id: http://svn.softwarepublico.gov.br/svn/cacic/cacic/trunk/agente-windows@1439 fecfc0c7-e812-0410-ae72-849f08638ee7
Showing
1 changed file
with
84 additions
and
0 deletions
Show diff stats
gercols/gercols.dpr
@@ -599,6 +599,86 @@ begin | @@ -599,6 +599,86 @@ begin | ||
599 | Result := FormatFloat('##0.00', (iResult / 100.0)); | 599 | Result := FormatFloat('##0.00', (iResult / 100.0)); |
600 | end; | 600 | end; |
601 | 601 | ||
602 | +// Funcao que le os valores de software instalados no Registro do Windows | ||
603 | +Function DisplayKeys(const Key: string; const Depth: Integer): String; | ||
604 | +var | ||
605 | + i: Integer; | ||
606 | + SubKeys: TStringList; | ||
607 | + Registry: TRegistry; | ||
608 | + SubRegistry: TRegistry; | ||
609 | + saida: String; | ||
610 | +begin | ||
611 | + Registry := TRegistry.Create; | ||
612 | + SubRegistry := TRegistry.Create; | ||
613 | + Registry.RootKey := HKEY_LOCAL_MACHINE; | ||
614 | + if Registry.OpenKeyReadOnly(Key) then begin | ||
615 | + Try | ||
616 | + SubKeys := TStringList.Create; | ||
617 | + Try | ||
618 | + Registry.GetKeyNames(SubKeys); | ||
619 | + // Abre a tag com o nome da chave | ||
620 | + saida := '[SoftwareList]'; | ||
621 | + | ||
622 | + // Adiciona o pai | ||
623 | + SubRegistry.RootKey := HKEY_LOCAL_MACHINE; | ||
624 | + | ||
625 | + for i := 0 to SubKeys.Count-1 do begin | ||
626 | + //Writeln(StringOfChar(' ', Depth*2) + SubKeys[i]); | ||
627 | + //DisplayKeys(Key + '\' + SubKeys[i], Depth+1); | ||
628 | + // Essa linha coloca o valor da tag do registro | ||
629 | + saida := saida + '[Software][IDSoftware]' + SubKeys[i] + '[/IDSoftware]'; | ||
630 | + | ||
631 | + // Abre a tag do registro | ||
632 | + //Names := TStringList.Create; | ||
633 | + SubRegistry.OpenKeyReadOnly(Key + '\' + SubKeys[i]); | ||
634 | + | ||
635 | + // Agora coloca o valor do registro dentro da tag | ||
636 | + saida := saida + '[DisplayName]' + SubRegistry.ReadString('DisplayName') + '[/DisplayName]'; | ||
637 | + saida := saida + '[DisplayVersion]' + SubRegistry.ReadString('DisplayVersion') + '[/DisplayVersion]'; | ||
638 | + saida := saida + '[URLInfoAbout]' + SubRegistry.ReadString('URLInfoAbout') + '[/URLInfoAbout]'; | ||
639 | + saida := saida + '[Publisher]' + SubRegistry.ReadString('Publisher') + '[/Publisher]'; | ||
640 | + | ||
641 | + // Fecho o registro e a tag | ||
642 | + SubRegistry.CloseKey; | ||
643 | + //SubRegistry.Free; | ||
644 | + | ||
645 | + // Fecha a tag do registro | ||
646 | + saida := saida + '[/Software]'; | ||
647 | + | ||
648 | + // Chamada recursiva para tags que possuem valores internos | ||
649 | + DisplayKeys(Key + '\' + SubKeys[i], Depth+1); | ||
650 | + end; | ||
651 | + | ||
652 | + // Fecha a tag do software | ||
653 | + saida := saida + '[/SoftwareList]'; | ||
654 | + Finally | ||
655 | + SubKeys.Free; | ||
656 | + End; | ||
657 | + Finally | ||
658 | + Registry.CloseKey; | ||
659 | + Registry.Free; | ||
660 | + End; | ||
661 | + Result := saida; | ||
662 | + end; | ||
663 | +end; | ||
664 | + | ||
665 | +// Procedimento que chama a lista de softwares do Sistema Operacional | ||
666 | +Function SoftwareList: String; | ||
667 | +var | ||
668 | + strChave: String; | ||
669 | + outString: String; | ||
670 | +begin | ||
671 | + // Esse registro é onde vamos buscar a chave do SO | ||
672 | + strChave := '\Software\Microsoft\Windows\CurrentVersion\Uninstall'; | ||
673 | + | ||
674 | + // Passo aqui o registro e a profundidade dos campos que quero ver | ||
675 | + outString := DisplayKeys(strChave, 3); | ||
676 | + | ||
677 | + // Retorno uma string com todas as tags coletadas do registro | ||
678 | + Result := outString; | ||
679 | +end; | ||
680 | + | ||
681 | + | ||
602 | procedure executeGerCols; | 682 | procedure executeGerCols; |
603 | var boolFound : boolean; | 683 | var boolFound : boolean; |
604 | var strActionDefinition, | 684 | var strActionDefinition, |
@@ -624,6 +704,7 @@ var strActionDefinition, | @@ -624,6 +704,7 @@ var strActionDefinition, | ||
624 | strRetorno, | 704 | strRetorno, |
625 | strTeServidor, | 705 | strTeServidor, |
626 | strTripa, | 706 | strTripa, |
707 | + tstrColetaSoftware, | ||
627 | strValorChavePerfis : String; | 708 | strValorChavePerfis : String; |
628 | 709 | ||
629 | intAux4, | 710 | intAux4, |
@@ -1343,6 +1424,9 @@ Begin | @@ -1343,6 +1424,9 @@ Begin | ||
1343 | Inc(intTotalExecutedCollects); | 1424 | Inc(intTotalExecutedCollects); |
1344 | strClassesAndProperties := objCacic.getValueFromTags('ClassesAndProperties',strActionDefinition); | 1425 | strClassesAndProperties := objCacic.getValueFromTags('ClassesAndProperties',strActionDefinition); |
1345 | 1426 | ||
1427 | + objCacic.writeDebugLog('executeGerCols: Executando coleta de Software -> '); | ||
1428 | + tstrColetaSoftware := SoftwareList; | ||
1429 | + | ||
1346 | objCacic.writeDebugLog('executeGerCols: strClassesAndProperties -> "' + strClassesAndProperties + '"'); | 1430 | objCacic.writeDebugLog('executeGerCols: strClassesAndProperties -> "' + strClassesAndProperties + '"'); |
1347 | tstringsClasses := objCacic.explode(objCacic.getValueFromTags('Classes',strClassesAndProperties),','); | 1431 | tstringsClasses := objCacic.explode(objCacic.getValueFromTags('Classes',strClassesAndProperties),','); |
1348 | 1432 |