如何用程序关闭计算机?

hdc99 2004-03-20 03:13:42
我用的是win2000操作系统,怎样在pb中用程序关闭计算机?
...全文
71 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyzliuin 2004-03-20
  • 打赏
  • 举报
回复
顶,我忘了NT还要获得关机权限 :)
myclife 2004-03-20
  • 打赏
  • 举报
回复
NT核心下要麻烦很多

我把那些简单封装了一下:
$PBExportHeader$nvo_shutdownnew.sru
forward
global type nvo_shutdownnew from nonvisualobject
end type
type luid from structure within nvo_shutdownnew
end type
type luid_and_attributes from structure within nvo_shutdownnew
end type
type token_privileges from structure within nvo_shutdownnew
end type
end forward

type LUID from structure
long lowpart
long highpart
end type

type luid_and_attributes from structure
luid pluid
long attributes
end type

type token_privileges from structure
long privilegecount
luid_and_attributes privileges[]
end type

global type nvo_shutdownnew from nonvisualobject autoinstantiate
end type

type prototypes
FUNCTION ulong ExitWindowsEx(ulong uFlags,ulong dwReserved) LIBRARY "user32.dll"
FUNCTION ulong GetCurrentProcess() LIBRARY "kernel32.dll"
FUNCTION ulong LookupPrivilegevalue(ref string lpSystemName,ref string lpName,ref Luid

lpLuid) LIBRARY "advapi32.dll" ALIAS FOR "LookupPrivilegevalueA"
FUNCTION ulong AdjustTokenPrivileges(ulong TokenHandle,boolean DisableAllPrivileges,ref

TOKEN_PRIVILEGES NewState,ulong BufferLength,ref TOKEN_PRIVILEGES PreviousState,ref ulong

ReturnLength) LIBRARY "advapi32.dll"
FUNCTION ulong OpenProcessToken(ulong ProcessHandle,ulong DesiredAccess,ref ulong

TokenHandle) LIBRARY "advapi32.dll"

end prototypes

forward prototypes
public subroutine shutdown ()
end prototypes

public subroutine shutdown ();/*获得关机权限*/

string ls_lpSystemName,ls_lpName
ls_lpname='SeShutdownPrivilege'
ulong lu_hdlProcessHandle,lu_hdlTokenHandle,lu_lBufferNeeded
luid lst_tmpLuid
TOKEN_PRIVILEGES lst_tkp
TOKEN_PRIVILEGES lst_tkpNewButIgnored
lu_hdlProcessHandle = GetCurrentProcess()
OpenProcessToken(lu_hdlProcessHandle,40, lu_hdlTokenHandle)
LookupPrivilegevalue( ls_lpSystemName, ls_lpname, lst_tmpLuid)
lst_tkp.PrivilegeCount = 1
lst_tkp.Privileges[1].pLuid = lst_tmpLuid
lst_tkp.Privileges[1].Attributes = 2
AdjustTokenPrivileges(lu_hdlTokenHandle, False, lst_tkp,16,

lst_tkpNewButIgnored,lu_lBufferNeeded)


/*关机*/

ExitWindowsEx (9,0)


/* The End */

end subroutine

on nvo_shutdownnew.create
call super::create
TriggerEvent( this, "constructor" )
end on

on nvo_shutdownnew.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
xyzliuin 2004-03-20
  • 打赏
  • 举报
回复
通过ExitWindowsEx函数可实现这三个功能,首先作如下声明:

  Function Long ExitWindowsEx(Long uflag,Long nouse) Library ″user32.dll″

  参数2保留不用,可取0;参数1取0可以注销当前用户,取1可以关闭计算机,取2可以重启计算机,其值再加4表示强制结束“未响应"的进程。

680

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧