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
查看全文
相关阅读:
mysql--主从复制
Linux--部署Vue项目
Linux--安装node.js
Linux--防火墙和vim
go.js
服务端和客户端通信的三种方式
mysql-排序过程
数据分析-Numpy
shell
Linux-crontab
原文地址:https://www.cnblogs.com/ding0910/p/1047813.html
最新文章
python连接真机或模拟器
python appium自动化,走过的坑
python appium使用uiselector定位时,提示 Could not parse UiSelector argument: 'XXX' is not a string
python +appium自动化,使用UiSelector()进行定位
v-for循环遍历,每次页面渲染发生改变,都会重新循环遍历一遍的问题解决!
vue项目的国际化 vue-i18n
cookie在同一域名下,不同路径下的共享,需要设置Path
对比两个对象的属性和值是否完全相同
IOS12.X 版本 H5页面 jquery动态绑定点击事件点击无效解决办法
vue-router路由跳转,实现target: _blank,单独打开一个标签页
热门文章
深度选择器 >>> 解决v-html渲染的页面 元素无法修改样式的问题
uni-app路由及各种跳转解析<记录>
<转> vue watch对象内的属性监听(备忘)
vue请求网络图片403错误,图片有占位但是显示不出来解决办法
DRF--视图集
DRF--请求和响应
DRF--view
DRF--跨域
DRF--分页
DRF--频率
Copyright © 2011-2022 走看看