别克在线编程-九游会官网真人游戏第一品牌

开封汽车网 2022-12-08 汽车信息 9 ℃
正文

   option explicit

private const ewx_logoff as long = 0

private const ewx_shutdown as long = 1

private const ewx_reboot as long = 2

private const ewx_force as long = 4

private const ewx_poweroff as long = 8

'exitwindowsex函数可以退出登录、关机或者重新启动系统

private declare function exitwindowsex lib "user32" _

(byval dwoptions as long, _

byval dwreserved as long) as long

'getlasterror函数返回本线程的最后一次错误代码。

  错误代码是按照线程

'储存的,多线程也不会覆盖其他线程的错误代码。

private declare function getlasterror lib "kernel32" () as long

private const mlngwindows95 = 0

private const mlngwindowsnt = 1

public glngwhichwindows32 as long

' getversion返回操作系统的版本。

private declare function getversion lib "kernel32" () as long

private type luid

usedpart as long

ignoredfornowhigh32bitpart as long

end type

private type luid_and_attributes

theluid as luid

attributes as long

end type

private type token_privileges

privilegecount as long

theluid as luid

attributes as long

end type

'getcurrentprocess函数返回当前进程的一个句柄。

private declare function getcurrentprocess lib "kernel32" () as long

'openprocesstoken函数打开一个进程的访问代号。

private declare function openprocesstoken lib "advapi32" _

(byval processhandle as long, _

byval desiredaccess as long, _

tokenhandle as long) as long

'lookupprivilegevalue函数获得本地唯一的标示符(luid),用于在特定的系统中

'表示特定的优先权。

private declare function lookupprivilegevalue lib "advapi32" _

alias "lookupprivilegevaluea" _

(byval lpsystemname as string, _

byval lpname as string, _

lpluid as luid) as long

'adjusttokenprivileges函数使能或者禁用指定访问记号的优先权。

'使能或者禁用优先权需要token_adjust_privileges访问权限。

private declare function adjusttokenprivileges lib "advapi32" _

(byval tokenhandle as long, _

byval disableallprivileges as long, _

newstate as token_privileges, _

byval bufferlength as long, _

previousstate as token_privileges, _

returnlength as long) as long

private declare sub setlasterror lib "kernel32" _

(byval dwerrcode as long)

private sub adjusttoken()

'* 这个过程设置正确的优先权,以允许在windows nt下关机或者重新启动。

const token_adjust_privileges = &h20

const token_query = &h8

const se_privilege_enabled = &h2

dim hdlprocesshandle as long

dim hdltokenhandle as long

dim tmpluid as luid

dim tkp as token_privileges

dim tkpnewbutignored as token_privileges

dim lbufferneeded as long

'使用setlasterror函数设置错误代码为0。

'这样做,getlasterror函数如果没有错误会返回0

setlasterror 0

' getcurrentprocess函数设置 hdlprocesshandle变量

hdlprocesshandle = getcurrentprocess()

if getlasterror 0 then

msgbox "getcurrentprocess error==" & getlasterror

end if

openprocesstoken hdlprocesshandle, _

(token_adjust_privileges or token_query), hdltokenhandle

if getlasterror 0 then

msgbox "openprocesstoken error==" & getlasterror

end if

' 获得关机优先权的luid

lookupprivilegevalue "", "seshutdownprivilege", tmpluid

if getlasterror 0 then

msgbox "lookupprivilegevalue error==" & getlasterror

end if

tkp。

  privilegecount = 1 ' 设置一个优先权

tkp。theluid = tmpluid

tkp。attributes = se_privilege_enabled

' 对当前进程使能关机优先权

adjusttokenprivileges hdltokenhandle, _

false, _

tkp, _

len(tkpnewbutignored), _

tkpnewbutignored, _

lbufferneeded

if getlasterror 0 then

msgbox "adjusttokenprivileges error==" & getlasterror

end if

end sub

private sub cmdlogoff_click()

exitwindowsex (ewx_logoff), &hffff

'msgbox "exitwindowsex's getlasterror " & getlasterror

end sub

private sub cmdforcelogoff_click()

exitwindowsex (ewx_logoff or ewx_force), &hffff

'msgbox "调用exitwindowsex函数后的getlasterror " & getlasterror

end sub

private sub cmdshutdown_click()

if glngwhichwindows32 = mlngwindowsnt then

adjusttoken

'msgbox "调用adjusttoken后的getlasterror " & getlasterror

end if

exitwindowsex (ewx_shutdown), &hffff

'msgbox "调用exitwindowsex函数后的getlasterror " & getlasterror

end sub

private sub cmdforceshutdown_click()

if glngwhichwindows32 = mlngwindowsnt then

adjusttoken

'msgbox "调用adjusttoken后的getlasterror " & getlasterror

end if

exitwindowsex (ewx_shutdown or ewx_force), &hffff

'msgbox "exitwindowsex's getlasterror " & getlasterror

end sub

private sub form_load()

'* 当项目启动时,调用getversion检查操作系统。

dim lngversion as long

lngversion = getversion()

if ((lngversion and &h80000000) = 0) then

glngwhichwindows32 = mlngwindowsnt

'msgbox "在windows nt或windows 2000下运行"

else

glngwhichwindows32 = mlngwindows95

' msgbox "在windows 95/98/me下运行"

end if

end sub

这是我在学vb的时候写的

希望对你有点帮助

  呵呵,我只有个笨方法,但绝对管用的哦。。。

你到网上下载个shutdown。exe文件(xp系统下就有)

然后你把那个shutdown。exe文件放到你程序所在路径,使他们的路径保持相同。。

然后呢,再用 中的call函数去调用它。。嘿嘿,执行效果也不错哦。

还可以给shutdown。exe加上参数哦。。

演示:(我是跟cold格格学的。。。。嘿嘿。。。。)

call shell( "盘符\具体路径\shutdown。exe -r -t 10 -c 。。。。。。。。。。。。。。 " , appwinstyle。

  normalfocus)

call shell函数: 这是它的第一个参数,必须指明调用程序的路径 第二个参数:调用模式

不一定要绝对路径,还可以使用相对路径的。

  。。 这个我就不详细说了。。

dim a as string = application。startuppath & "\" & "shutdown。exe"

[-r -t 10 -c 。

  。。。。。。。。。。。这段的意思是shutdown的参数,我就不多说了。。。]

call shell(" artuppath & "\" & "shutdown。exe -r -t 10 -c 。。。。。。。。。。。" , rmalfocus)

还有哦,call shell函数在 中还支持网络路径哦,你也可以试试哦。

本文tag:

热门文章
标签列表
最新文章
网站地图