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:别克在线编程
猜你喜欢
- 2022-12-242019新款马自达_太原新款马自达6现车到店
- 2022-12-242019马自达3昂克赛拉_测评报告一:车载系统昂克赛拉、mg5硬件系统表现较好,福克斯较差(转载)
- 2022-12-23别克excell_第八章 神秘后援
- 2022-12-23保时捷欧曼_欧曼整体橱柜怎么样?
- 2022-12-23保时捷欧曼_欧曼6和欧曼9前四后八载货有什么区别?
- 2022-12-23奥迪a1怎么样_诱惑不是一点点 奥迪a1迷人小红提车作业(转)(转载)
- 热门文章
-
- 2019新款马自达_太原新款马自达6现车到店
- 2019马自达3昂克赛拉_测评报告一:车载系统昂克赛拉、mg5硬件系统表现较好,福克斯较差(转载)
- 别克会员卡_会员卡充值后人去店空,韩国李勋美发沙龙这家店你去过吗?
- 本福特数值_血糖高真的要吃药吗?什么数值下不用吃?(转载)
- 本福特数值_夏代的中国人知道的圆周率的数值达到了什么样的精度?
- 别克微信号_怎样把别人微信号添加到自己的微信上
- 别克偷油_老鼠偷油的故事
- 保时捷欧曼_欧曼整体橱柜怎么样?
- 别克新款军微_[旅途交流]卖车三十六计:一汽大众釜vs上海通用(转载)
- civic_请问我的civic 1.6l的用什么润滑油比较好?
- 2008年马自达6_两厢马自达2出售价格?
- 本田幼兽50_【地瓜新聞】日前台中警局逮3嫌躲山區豬舍夜間製毒 警查獲50公原料
- 570雷克萨斯油耗_雷克萨斯告诉你空调和油耗的关系
- 别克28万_[人文地理]5500万巨资打造超级美秀 媲美世姐视觉盛宴28日开演
- 保时捷画稿_《疾风之刃》同名漫画预计要年底才看得到,从曝光的画稿看品质还不错
- 标签列表
-
- 别克倒车影像有开关吗 (10)
- 本丰田车标 (10)
- 别克福特哪个好 (11)
- h6哈弗手动档多少钱 (10)
- 别克阅朗买了就后悔 (13)
- 10年斯巴鲁森林人 (10)
- 07款斯巴鲁森林人 (16)
- 11捷豹xf (11)
- 标致rcz报价 (14)
- 保时捷亦庄 (11)
- 15年日产轩逸 (11)
- 2017款斯柯达明锐棕色 (10)
- 宝骏和别克 (12)
- ct5凯迪拉克价格表 (11)
- 别克七新款 (11)
- qx56英菲尼迪汽车 (11)
- 2017款25s别克车评测 (11)
- 本田英菲尼迪 (12)
- 7图丰田 (14)
- 06款沃尔沃xc90 (14)
- 12款斯巴鲁xv (12)
- 保时捷兰博基尼 (11)
- 保时捷海安 (11)
- 别克车首保多少公里 (11)
- 15座丰田考斯特价格 (13)
- 最新文章