D
delphiinfomail
Unregistered / Unconfirmed
GUEST, unregistred user!
我用Delphi写了一个简单的组件来读注册表中的键值,可是怎么都不能读出。有谁知道什么原因吗?
unit Unit1;
interface
uses
ComObj,windows, ActiveX, AspTlb, AspReg_TLB, StdVcl, registry;
type
TAspRegister = class(TASPObject, IAspRegister)
private
s: string;
protected
procedure OnEndPage
safecall;
procedure OnStartPage(const AScriptingContext: IUnknown)
safecall;
function Get_Read: WideString
safecall;
end;
implementation
uses ComServ;
procedure TAspRegister.OnEndPage;
begin
inherited OnEndPage;
end;
procedure TAspRegister.OnStartPage(const AScriptingContext: IUnknown);
var
Reg: TRegistry;
begin
inherited OnStartPage(AScriptingContext);
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('Software/Microsoft/Windows/CurrentVersion/Explorer', False) then
s := Reg.ReadString('Logon User Name')
else
s := 'wrong.';
finally
Reg.CloseKey;
Reg.Free;
end;
end;
function TAspRegister.Get_Read: WideString;
begin
result := s;
end;
initialization
TAutoObjectFactory.Create(ComServer, TAspRegister, Class_AspRegister,
ciMultiInstance, tmApartment);
end.
unit Unit1;
interface
uses
ComObj,windows, ActiveX, AspTlb, AspReg_TLB, StdVcl, registry;
type
TAspRegister = class(TASPObject, IAspRegister)
private
s: string;
protected
procedure OnEndPage
safecall;
procedure OnStartPage(const AScriptingContext: IUnknown)
safecall;
function Get_Read: WideString
safecall;
end;
implementation
uses ComServ;
procedure TAspRegister.OnEndPage;
begin
inherited OnEndPage;
end;
procedure TAspRegister.OnStartPage(const AScriptingContext: IUnknown);
var
Reg: TRegistry;
begin
inherited OnStartPage(AScriptingContext);
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_CURRENT_USER;
if Reg.OpenKey('Software/Microsoft/Windows/CurrentVersion/Explorer', False) then
s := Reg.ReadString('Logon User Name')
else
s := 'wrong.';
finally
Reg.CloseKey;
Reg.Free;
end;
end;
function TAspRegister.Get_Read: WideString;
begin
result := s;
end;
initialization
TAutoObjectFactory.Create(ComServer, TAspRegister, Class_AspRegister,
ciMultiInstance, tmApartment);
end.