zoukankan
html css js c++ java
VB.NET 2005重启/关机程序
Imports
System.Runtime.InteropServices
Imports
Microsoft.VisualBasic
Public
Class Form1
Class
Form1
<
DllImport(
"
kernel32.dll
"
, ExactSpelling:
=
True
)
>
_
'
调用系统参数
Friend
Shared
Function GetCurrentProcess()
Function
GetCurrentProcess()
As
IntPtr
End Function
<
DllImport(
"
advapi32.dll
"
, ExactSpelling:
=
True
, SetLastError:
=
True
)
>
_
Friend
Shared
Function OpenProcessToken()
Function
OpenProcessToken(
ByVal
h
As
IntPtr,
ByVal
acc
As
Integer
,
ByRef
phtok
As
IntPtr)
As
Boolean
End Function
<
DllImport(
"
advapi32.dll
"
, SetLastError:
=
True
)
>
_
Friend
Shared
Function LookupPrivilegeValue()
Function
LookupPrivilegeValue(
ByVal
host
As
String
,
ByVal
name
As
String
,
ByRef
pluid
As
Long
)
As
Boolean
End Function
<
DllImport(
"
advapi32.dll
"
, ExactSpelling:
=
True
, SetLastError:
=
True
)
>
_
Friend
Shared
Function AdjustTokenPrivileges()
Function
AdjustTokenPrivileges(
ByVal
htok
As
IntPtr,
ByVal
disall
As
Boolean
,
ByRef
newst
As
TokPriv1Luid,
ByVal
len
As
Integer
,
ByVal
prev
As
IntPtr,
ByVal
relen
As
IntPtr)
As
Boolean
End Function
<
DllImport(
"
user32.dll
"
, ExactSpelling:
=
True
, SetLastError:
=
True
)
>
_
Friend
Shared
Function ExitWindowsEx()
Function
ExitWindowsEx(
ByVal
flg
As
Integer
,
ByVal
rea
As
Integer
)
As
Boolean
End Function
Friend
Const
SE_PRIVILEGE_ENABLED
As
Integer
=
&
H2
Friend
Const
TOKEN_QUERY
As
Integer
=
&
H8
Friend
Const
TOKEN_ADJUST_PRIVILEGES
As
Integer
=
&
H20
Friend
Const
SE_SHUTDOWN_NAME
As
String
=
"
SeShutdownPrivilege
"
Friend
Const
EWX_LOGOFF
As
Integer
=
&
H0
'
注销计算机
Friend
Const
EWX_SHUTDOWN
As
Integer
=
&
H1
'
关闭计算机
Friend
Const
EWX_REBOOT
As
Integer
=
&
H2
'
重新启动计算机
Friend
Const
EWX_FORCE
As
Integer
=
&
H4
'
关闭所有进程,注销计算机
Friend
Const
EWX_POWEROFF
As
Integer
=
&
H8
Friend
Const
EWX_FORCEIFHUNG
As
Integer
=
&
H10
<
StructLayout(LayoutKind.Sequential, Pack:
=
1
)
>
_
'
引用参数
Friend
Structure TokPriv1Luid
Structure
TokPriv1Luid
Public
Count
As
Integer
Public
Luid
As
Long
Public
Attr
As
Integer
End Structure
Private
Shared
Sub DoExitWin()
Sub
DoExitWin(
ByVal
flg
As
Integer
)
Dim
xc
As
Boolean
'
判断语句
Dim
tp
As
TokPriv1Luid
Dim
hproc
As
IntPtr
=
GetCurrentProcess()
'
调用进程值
Dim
htok
As
IntPtr
=
IntPtr.Zero
xc
=
OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES
Or
TOKEN_QUERY, htok)
tp.Count
=
1
tp.Luid
=
0
tp.Attr
=
SE_PRIVILEGE_ENABLED
xc
=
LookupPrivilegeValue(
Nothing
, SE_SHUTDOWN_NAME, tp.Luid)
xc
=
AdjustTokenPrivileges(htok,
False
, tp,
0
, IntPtr.Zero, IntPtr.Zero)
xc
=
ExitWindowsEx(flg,
0
)
End Sub
Public
Shared
Sub Reboot()
Sub
Reboot()
DoExitWin((EWX_FORCE
Or
EWX_REBOOT))
'
重新启动计算机
End Sub
Public
Shared
Sub PowerOff()
Sub
PowerOff()
DoExitWin((EWX_FORCE
Or
EWX_POWEROFF))
'
关闭计算机
End Sub
Public
Shared
Sub LogoOff()
Sub
LogoOff()
DoExitWin((EWX_FORCE
Or
EWX_LOGOFF))
'
注销计算机
End Sub
查看全文
相关阅读:
Javascript中的Math.max()和Math.min()
附件预览项目采坑记
移动设备后台的理解
网络是怎么连接的?(进阶一)
Git建立本地分支和远程分支的映射关系
springboot使用redis实现发布与订阅
centos下安装配置mongodb
vue循环时设置多选框禁用状态,v-for
谷歌浏览器postman插件安装,亲测可用
element-ui 无法对绑定表单的对象中的对象属性进行验证
原文地址:https://www.cnblogs.com/ding0910/p/1047813.html
最新文章
Java学习之==>常用字符串方法
Java学习之==>注释、数据类型、变量、运算符
HTTP协议概述
Nginx正向代理、反向代理、负载均衡及性能优化
Tomcat-8 性能监控及调优
MySQL练习题
监控项
RabbitMQ安装手册
扫二维码连wifi
TestLink安装手册
热门文章
SmokePing安装手册
markdown图床
Linux系统内核参数优化
自建YUM仓库
docker基本操作
Function.prototype.call.apply()方法
js之重写原型对象
js原型继承题目
javascript闭包的用处
javascript设计模式和开发实践(阶段一)
Copyright © 2011-2022 走看看