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
查看全文
相关阅读:
SQL 存储过程返回值
C# Winform 大全开发手册
关于如何计划学习(转载自 知行合一)
MVC中CRUD
Web驱动变迁(从WebForm 到MVC)
activiti 流程发起人控制
[Python Study Notes]Socket模拟ssh执行cmd并记录遇到的问题
[Python Study Notes]异常处理
[Python Study Notes]正则表达式
[Python Study Notes]字符串操作
原文地址:https://www.cnblogs.com/ding0910/p/1047813.html
最新文章
【SQLSERVER】递归查询算法实例
【SQLSERVER】如何找出字符串中的数字
【SQLSERVER】索引的维护优化
【SAP BI】BW如何连接SQLSERVER数据库
【SQLSERVER】服务挂起解决办法
【SQLSERVER】如何设置权限用户
【SQLSERVER】从数据库文件mdf中拆分ndf的方法和利弊
IPython使用学习笔记
python数据分析入门学习笔记
单例模式与静态变量在PHP中
热门文章
API 接口规范
处理器体系结构
python链表的实现
linux操作系统使用中的一些总结
python用特殊方法定制类(不全)
python字符串格式和编码与解码问题
python中的id
cx_Oracle连接数据库总结
selenium主要功能封装
自定义消息弹出框的一个很不错的实例
Copyright © 2011-2022 走看看