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
查看全文
相关阅读:
How to Build Office Developer Tools Projects with TFS Team Build 2012
查看hyper-v主机mac地址
“Stamping” PDF Files Downloaded from SharePoint 2010
PostgreSQL体系基本概念
PostgreSQL 安装
HDFS+MapReduce+Hive+HBase十分钟快速入门
光照计算公式
游戏中的碰撞
数组
扑克牌概率
原文地址:https://www.cnblogs.com/ding0910/p/1047813.html
最新文章
站立会议第一天
团队编程_任务分配
学习进度条
音乐播放器之音频播放
音乐播放器之加载我的音乐
音乐播放器后台之歌曲读取
uwp版的音乐播放器练手
音乐播放器页面之汉堡菜单
Bash On Windows的学习
Java学习笔记--JDK动态代理
热门文章
Java学习笔记--反射API
Java学习笔记--脚本语言支持API
Java学习笔记--异常描述
Interoperability between Java and SharePoint 2013 on Premises
How does Web Analytics works under sharePoint 2010
沙盒代码执行请求被拒绝,因为沙盒代码主机服务太忙,无法处理请求。
Creating External Lists From Code
How to Use Telnet to Test SMTP Communication
Step by step configuration of Outgoing Emails from SharePoint to Microsoft Online
转载 BCS 的好文章 1
Copyright © 2011-2022 走看看