Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.07.16;
Скачать: CL | DM;

Вниз

WMI - самое начало.   Найти похожие ветки 

 
GrBob   (2006-06-26 13:25) [0]

Какую библиотеку нужно подключить, чтобы вот это заработало. Во всех экземплах WMI на Делфи предлагают использовать библоитеку типов и соответствующие компоненты, с которыми уже и работать, но мне нужно, чтобы заработал именно этот код (с минимальными правками синтаксиса, багов и пр.) ;)

function TServiceControlFm.StartApplication(strServer: string; const Command: string): boolean;
var
 ObjWMI: OleVariant;
 ObjProcess,ProcessID: OleVariant;
 ObjConfig: OleVariant;
 Error: OleVariant;
begin
 Result:=False;
 ObjWMI:=GetObject("Winmgmts:{impersonationLevel=impersonate}!"+strServer+"\root\cimv2");
 ObjProcess:= objWMI.Get("Win32_Process");
 ObjConfig:=objWMI.Get("Win32_ProcessStartup").SpawnInstance_;
 ObjConfig.ShowWindow:=SW_NORMAL;
 Error:=ObjProcess.Create(Command,ObjConfig,ProcessID);
 if Error = 0 then
  begin
    Caption:=IntToStr(ProcessID);
    Sleep(300);
    Result:=True;
    SetForegroundWindow(MainForm.Handle);
  end
  else
    MessageBox(0, PChar("Не удалось запустить приложение."),
               PChar(MainForm.Caption), MB_OK);
end;


Заранее всем спасибо за любой, более менее относящийся к теме, ответ :)


 
novill ©   (2006-06-26 14:45) [1]

1. Почему  вы обращаетесь к функции GetObject, как будто вы в вижуал бейсике находитесь?


 
GrBob   (2006-06-26 16:02) [2]

Вот и я так же думаю. Но в этом коде нет ни одной моей строчки, а синтаксис на VB прям скажем не похож. Нашел его в архиве какого-то форума за 2003 или 2004 год, где люди его с серьезным видом обсуждали. Но я подобного описания функции GetObject не нашел, решил, что это какая-то из неизвестных мне библиотек, и задал вопрос.


 
novill ©   (2006-06-26 16:15) [3]

Стоило посмотреть о чем говорят
Открываете и windows SDK (bkb MSDN) и читаете

Provider::GetObject
The GetObject method is called by WMI to retrieve an instance of a class.

Note  The Provider class is part of the WMI Provider Framework. The Provider Framework classes are obsolete and not recommended. See Using WMI for the preferred ways to write a WMI COM provider or a WMI provider that uses the .NET Framework System.Management namespaces.

HRESULT GetObject(
 CInstance* pInstance,
 long lFlags,
 CFrameworkQuery& Query
);

Parameters
pInstance
Pointer to a CInstance object to be filled in by the framework provider.
lFlags
Bitmask of flags with information about the GetObject operation. This is the value specified by the client in the IWbemServices::GetObject method.
The following flags are handled by (and filtered out) by WMI:

WBEM_FLAG_USE_AMENDED_QUALIFIERS
WBEM_FLAG_RETURN_WBEM_COMPLETE
WBEM_FLAG_RETURN_IMMEDIATELY
Query
Query object that indicates the set of properties to be populated, as requested by a call to Provider::GetObject.
A provider can realize a significant performance gain by filling in only these requested property values. The provider determines which properties are requested by using CFrameworkQuery::IsPropertyRequired. Otherwise, the provider must fill in all property values.

Return Values
The default framework provider implementation of this method returns WBEM_E_PROVIDER_NOT_CAPABLE to the calling method. The IWbemServices::GetObject method lists the common return values, although you can choose to implement any COM return value.

Remarks
WMI often invokes GetObject in response to a client call to IWbemServices::GetObject. The WMI version of Provider::GetObject provides an instance with only the key properties populated. In contrast, an implemented framework provider must fill in all other properties. The following describes a common override of GetObject:

Determine which instance WMI requested by reading the key properties with a Get method from CInstance, such as CInstance::GetCHString.
Populate the rest of the properties of the instance using the many Set methods of the CInstance class, such as CInstance::SetByte or CInstance::SetStringArray.

Requirements



Страницы: 1 вся ветка

Текущий архив: 2006.07.16;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.038 c
10-1122298976
Max4
2005-07-25 17:42
2006.07.16
Excel


15-1150456037
aka
2006-06-16 15:07
2006.07.16
about Com


6-1134736695
SPACE!!
2005-12-16 15:38
2006.07.16
Клт.-Серв. приложение на WinSock с большим количеством клиентов.


4-1144150645
Stanislav
2006-04-04 15:37
2006.07.16
Остановка параллельных процессов


6-1141907554
Sysanin
2006-03-09 15:32
2006.07.16
Отправка сообщения удалёному компу