Création d'une application 32 bits avec Delphi Je n'ai pas accès à toutes les ruches, que l'application soit exécutée sur une machine Windows win32 ou win64. Voici un lien pour l'accès par défaut: http://msdn.microsoft.com/en-us/library/aa390789(v=VS.85).aspxAccès aux 3 ruches du registre
Je veux juste créer une seule application, et non une version séparée pour 32 & 64. Je voudrais utiliser WMI et récupérer des informations de la ruche de Registre 32 bits, la Ruche de registre 64 bits et le WOW6432Node. Il y a des FLAGS à définir mais je n'arrive pas à comprendre comment envoyer les drapeaux avec un appel de requête WMI normal depuis mon application Delphi. Voici les informations sur les GALP: http://msdn.microsoft.com/en-us/library/aa393067(v=VS.85).aspx
GLibWmi & DelphiWmiCodeCreator exmple:
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 GetWin32_StartupCommandInfo;
var
objWMIService : OLEVariant;
colItems : OLEVariant;
colItem : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin;
objWMIService := GetWMIObject('winmgmts:\\localhost\root\CIMV2');
colItems := objWMIService.ExecQuery('SELECT * FROM Win32_StartupCommand','WQL',0);
oEnum := IUnknown(colItems._NewEnum) as IEnumVariant;
while oEnum.Next(1, colItem, iValue) = 0 do
begin
Writeln('');
end;
end;
CODE RÉVISÉ:
procedure GetWin32_StartupCommandInfo(aIDispatch: IDispatch);
var
objWMIService : OLEVariant;
colItems : OLEVariant;
colItem : OLEVariant;
oEnum : IEnumvariant;
iValue : LongWord;
begin;
objWMIService := aIDispatch; //GetWMIObject('winmgmts:\\localhost\root\CIMV2');
colItems := objWMIService.ExecQuery('SELECT * FROM Win32_StartupCommand','WQL',0);
oEnum := IUnknown(colItems._NewEnum) as IEnumVariant;
while oEnum.Next(1, colItem, iValue) = 0 do
begin
with Form1.lst1 do begin
items.Add(Format('Caption="%s"; Location="%s"',[colItem.Caption,colItem.Location]));// String
{items.Add(Format('Command %s',[colItem.Command]));// String
items.Add(Format('Description %s',[colItem.Description]));// String
items.Add(Format('Location %s',[colItem.Location]));// String
items.Add(Format('Name %s',[colItem.Name]));// String
items.Add(Format('SettingID %s',[colItem.SettingID]));// String
items.Add(Format('User %s',[colItem.User]));// String
items.Add(Format('UserSID %s',[colItem.UserSID]));// String
}
items.Add('');
end;
end;
end;
function MyConnectWMI(wmiHost:string; var Services: ISWbemServices):Boolean;
const
STR_CIM2_ROOT ='root\CIMV2';
STR_EMPTY = '';
var
NVS: SWbemNamedValueSet;
providerArchitecture : OleVariant;
requiredArchitecture : OleVariant;
Locator : ISWbemLocator; //CoSWbemLocator;
begin
try
providerArchitecture := 32; // or 64
requiredArchitecture := true;
NVS := CoSWbemNamedValueSet.Create();
NVS.Add('__ProviderArchitecture', providerArchitecture , 0);
NVS.Add('__RequiredArchitecture', requiredArchitecture , 0);
// Create the Location object
Locator := CoSWbemLocator.Create();
// Connect to the WMI service, with the root\cimv2 namespace
Services := Locator.ConnectServer(wmiHost,
STR_CIM2_ROOT, {user}STR_EMPTY, {password}STR_EMPTY,
STR_EMPTY,STR_EMPTY, 0, NVS);
Result := True;
except
Result := False;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
aServices: ISWbemServices;
begin
if MyConnectWMI('localhost', aServices) then
GetWin32_StartupCommandInfo(aServices);
end;
Je l'ai à travailler, mais seulement lorsque le providerArchitecture est fixé à 64 ans, si je l'ai fixé à 32 je reçois une erreur de EOleException: « Load Provider Fail » . Je cours Win7 64Bit avec Delphi 2010. – Logman
CHeck dessus dans mon article original dans la section RÉVISÉE. Le code se bloque lorsque "ExecQuery" est exécuté et non lorsque je crée la connexion. – Logman
Ce sera aux fournisseurs. Win32_StartupCommand est fourni par le fournisseur Win32 et non par le fournisseur de registre. Cette page http://msdn.microsoft.com/en-us/library/aa394570%28v=VS.85%29.aspx liste les fournisseurs. Le fournisseur de registre mentionne deux versions sur des plates-formes 64 bits. – vickd