Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
procedure TForm1.Button2Click(Sender: TObject);
// start service
var
WbemLocator: ISWbemLocator;
WbemServices: ISWbemServices;
ObjectSet: ISWbemObjectSet;
InParam: ISWBemObject;
tempobj: OleVariant;
InProcess: ISWBemObject;
RowENum: IENumVariant;
outstmt: string;
begin
WBemLocator := WMIStart;
WBemServices := WMIConnect(WBemLocator, '', '', '');
outstmt := 'Select caption from Win32_Service where caption = ''' +
ComboBox1.Items[ComboBox1.Itemindex] + '''';
ObjectSet := WMIExecQuery(WbemServices, outstmt);
WMIRowFindFirst(ObjectSet, RowENum, tempobj);
InProcess := IUnknown(tempobj) as ISWbemobject;
InParam := InProcess.ExecMethod_('StartService', nil, 0, nil);
end;
unit regunit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
activex, wmiserv, WbemScripting_TLBa, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
WBEMLocator: SWBEMLocator;
WBEMServices: ISWBEMServices;
regobject: ISWBemObject;
InParam, OutParam: ISWBemObject;
InProp: ISWBemProperty;
outv: Olevariant;
begin
WBEMLocator := WMIStart;
WBemServices := WMIRegConnect(WBEMLocator, '', '', '');
WMIGetMethodInfo(WBEMServices, regobjstring, 'GetExpandedStringValue',
regobject, InParam);
WMISetValue(InParam, 'hDefKey', HKEY_CURRENT_USER);
WMISetValue(InParam, 'sSubKeyName', 'Control Panel\Desktop');
WMISetValue(InParam, 'sValueName', 'Wallpaper');
OutParam := regobject.ExecMethod_('GetExpandedStringValue', InParam, 0, nil);
// output value is SValue
InProp := OutParam.Properties_.Item('sValue', 0);
outv := InProp.Get_Value;
ShowMessage(outv); // the value of the registry key
end;
end.
const
regobjstring = 'StdRegProv';
function WMIRegConnect(WBemLocator: ISWBemLocator; Server, account, password: string): ISWBemServices;
// connects to the default area
begin
Result := nil;
try
Result := WBEMLocator.ConnectServer(Server, 'root\default', '', Account,
Password, '', 0, nil);
except
on EOleException do
raise EOleException.Create('incorrect credentials. WMI connection failed.', 1, '', '', 0);
end;
CoSetProxyBlanket(Result, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
nil,
wbemAuthenticationLevelCall, wbemImpersonationLevelImpersonate,
nil, EOAC_NONE);
end;
procedure WMIGetMethodInfo(srv: ISWbemServices; objname, method: string; var regobject, inparms: ISWBemObject);
// gets method info and parms, this is useful if an object method is *NOT* tied to a specific record.
begin
regobject := srv.Get(objname, 0, nil);
InParms := regobject.Methods_.Item(method, 0).InParameters;
end;
procedure WMISetValue(InParam: ISWBemObject; keyvalue: string; invalue: OleVariant);
// sets a parm value. Calls my modified set_value.
// remove the @ if you wish to make the default call.
begin
InParam.Properties_.Item(keyvalue, 0).Set_Value(@InValue);
end;