DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: eyang11
今日帖子: 26
在线用户: 5
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 dream0 (dream0) ★☆☆☆☆ -
盒子活跃会员
2004/5/5 21:44:54
标题:
又有两个问题??????????? 浏览:988
加入我的收藏
楼主: 不好意思,我写是写完整了,但是传上去的时候好像出错了。
  user
     Registry;
procedure Tform1.button1(sender:TObject);
var 
   reg:TRegistry;
begin
   reg:=TRegistry.create;
   reg.rootkey=HKEY_CURRENT_USER;
   。。
  。。
   reg.free;
end;
 上面的一段程序有错误没有啊,不知道为什么我编译的时候老是有警告提示,说'reg'没有初始化。
  
  还有就是在win98用API函数 ExitWindowsEx(EWX_SHUTDOWN,0)即可退出系统,但在2003和XP下运行都没有反应啊,不会退出哦,这是怎么回事,怎么搞的??文字

----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/5/5 21:48:28
1楼: 1)偶看不出来
2)2003和XP下:要提升权限!

program ExitNt; 

Uses
  Windows;
{$R *.RES}

function SetPrivilege(sPrivilegeName : string;bEnabled : boolean ): boolean;
var
  TPPrev,
  TP : TTokenPrivileges;
  Token : THandle;
  dwRetLen : DWord;
begin
  Result := False;
  //opens the access token associated with a process.
  OpenProcessToken(
  GetCurrentProcess, //handle to process
  TOKEN_ADJUST_PRIVILEGES //Required to change the privileges specified in an access token.
  or TOKEN_QUERY, //Required to query the contents of an access token.
  Token);
  TP.PrivilegeCount := 1;
  //retrieves the locally unique identifier (LUID) used on a specified system to
  //locally represent the specified privilege name.
  if( LookupPrivilegeValue(
  Nil, //attempts to find the privilege name on the local system.
  PChar( sPrivilegeName ), // address of string specifying the privilege
  TP.Privileges[ 0 ].LUID ) // address of locally unique identifier
  )then
  begin
    if( bEnabled )then //Give this privileges
    begin
      TP.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;
    end
    else
    begin //NOT Give this privileges
      TP.Privileges[ 0 ].Attributes := 0;
    end;
      dwRetLen := 0;
    //enables or disables privileges in the specified access token.
    Result := AdjustTokenPrivileges(
    Token, // handle to token that contains privileges
    False, //modifies privileges
    TP, // pointer to new privilege information
    SizeOf( TPPrev ), // size, in bytes, of the TPPrev buffer
    TPPrev, // receives original state of changed privileges
    dwRetLen // receives required size of the TPPrev buffer
    );
  end;
  CloseHandle(Token);
end;
function WinExitInNT( iFlags : integer ) : boolean;
begin
  Result := True;
  if( SetPrivilege( 'SeShutdownPrivilege', True ) )then
  begin
    if( not ExitWindowsEx( iFlags, 0 ) )then
    begin
    Result := False;
    end;
  SetPrivilege( 'SeShutdownPrivilege', False )
  end
  else
  begin
// handle errors...
  Result := False;
  end;
end;
begin
  WinExitInNT(EWX_SHUTDOWN+EWX_POWEROFF);
end. 


----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/5/5 21:56:36
2楼: user
     Registry;

是不是你的笔误啊:uses吧
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 dream0 (dream0) ★☆☆☆☆ -
盒子活跃会员
2004/5/7 1:07:58
3楼: 呵呵,如果是这个user或者是users错误的话,那就不只是提示'reg'没有初始化了。放心,老兄,这一点是我写错了,程序里面没有这个错误
----------------------------------------------
-
作者:
男 sephil (NAILY Soft) ★☆☆☆☆ -
盒子中级会员
2004/5/7 1:14:24
4楼: 完整代码帖出来
----------------------------------------------
Copyright 2008 ? NAILY Soft

Click here to redirect to my home
Click here to redirect to my blog
作者:
男 dream0 (dream0) ★☆☆☆☆ -
盒子活跃会员
2004/5/9 8:05:03
5楼: 哈哈,问题被我查出来了,原来是我在一个条件成立时用了,reg.free;
然后,再段程序开头用了,try,在结尾又用了一个finally
                                             reg.free
                                            end;
我把finally后面那个reg.free删掉就消除了
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行78.125毫秒 RSS