VB制作关机程序
我想制作一个一个那个用VB怎么做提示一下。是跳出一个关机程序然后要别人喊爷爷什么的。那个用VB怎么做呀?就是象那个vbs的。有时间限制的,最好能提供原代码,谢谢~要有输入...
我想制作一个一个 那个用VB 怎么做
提示一下。是跳出一个关机程序
然后要别人喊爷爷什么的。
那个用VB怎么做呀?
就是象那个vbs的。有时间限制的,最好能提供原代码,谢谢~ 要有输入框的, 展开
提示一下。是跳出一个关机程序
然后要别人喊爷爷什么的。
那个用VB怎么做呀?
就是象那个vbs的。有时间限制的,最好能提供原代码,谢谢~ 要有输入框的, 展开
4个回答
展开全部
新建一个工程,添加一个模块(可以把Form1这个窗体删去,这里不用窗体)。
工程属性里设启动对象为 Sub Main
在模块里输入:
Sub Main()
Dim A As String
Shell "shutdown.exe -s -t 120" '120是指120秒后关机,自己可以改
A = InputBox("快叫声爷爷,不叫就关你机!") '文字你可以自己改,这里给你做个参考
If A = "爷爷" Then
Shell "shutdown.exe -a"
End If
End Sub
工程属性里设启动对象为 Sub Main
在模块里输入:
Sub Main()
Dim A As String
Shell "shutdown.exe -s -t 120" '120是指120秒后关机,自己可以改
A = InputBox("快叫声爷爷,不叫就关你机!") '文字你可以自己改,这里给你做个参考
If A = "爷爷" Then
Shell "shutdown.exe -a"
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
'ExitWindowsEx的参数uflags,有四个对应值,分别是:
Public Const EWX_LOGOFF = 0 '退出(注销)
Public Const EWX_SHUTDOWN = 1 '关机
Public Const EWX_REBOOT = 2 '重启动
Public Const EWX_FORCE = 4 '强制关机,即不通知现在活动应用程序让其先自我关闭
Public Const TOKEN_ADJUST_PRIVILEGES = &H20
Public Const TOKEN_QUERY = &H8
Public Const SE_PRIVILEGE_ENABLED = &H2
Public Const ANYSIZE_ARRAY = 1
Type LUID
lowpart As Long
highpart As Long
End Type
Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
Declare Function GetCurrentProcess Lib "kernel32" () As Long
Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (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
Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
'这个函数就是用于NT关机中使用的
Sub AdjustTokenPrivilegesForNT()
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
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _
TOKEN_QUERY), hdlTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges hdlTokenHandle, False, tkp, _
Len(tkpNewButIgnored), tkpNewButIgnored, _
lBufferNeeded
End Sub
Sub main()
AdjustTokenPrivilegesForNT '在95/98中调用没作用,但为了和NT兼容,写上无妨
ExitWindowsEx EWX_SHUTDOWN, 0 '这里将uFlgs换成以上面标记蓝色字中所提到的四个参数之一即可
'下面为举例
'ExitWindowsEx EWX_FORCE, 0 强迫关机(就是不管有无要保存的东西而强行关闭)
'ExitWindowsEx EWX_LOGOFF, 0 退出(注销)
End Sub
'ExitWindowsEx的参数uflags,有四个对应值,分别是:
Public Const EWX_LOGOFF = 0 '退出(注销)
Public Const EWX_SHUTDOWN = 1 '关机
Public Const EWX_REBOOT = 2 '重启动
Public Const EWX_FORCE = 4 '强制关机,即不通知现在活动应用程序让其先自我关闭
Public Const TOKEN_ADJUST_PRIVILEGES = &H20
Public Const TOKEN_QUERY = &H8
Public Const SE_PRIVILEGE_ENABLED = &H2
Public Const ANYSIZE_ARRAY = 1
Type LUID
lowpart As Long
highpart As Long
End Type
Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
Declare Function GetCurrentProcess Lib "kernel32" () As Long
Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (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
Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
'这个函数就是用于NT关机中使用的
Sub AdjustTokenPrivilegesForNT()
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
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _
TOKEN_QUERY), hdlTokenHandle
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges hdlTokenHandle, False, tkp, _
Len(tkpNewButIgnored), tkpNewButIgnored, _
lBufferNeeded
End Sub
Sub main()
AdjustTokenPrivilegesForNT '在95/98中调用没作用,但为了和NT兼容,写上无妨
ExitWindowsEx EWX_SHUTDOWN, 0 '这里将uFlgs换成以上面标记蓝色字中所提到的四个参数之一即可
'下面为举例
'ExitWindowsEx EWX_FORCE, 0 强迫关机(就是不管有无要保存的东西而强行关闭)
'ExitWindowsEx EWX_LOGOFF, 0 退出(注销)
End Sub
参考资料: http://hi.baidu.com/wmsnet/blog/item/9ff6b245944cc73e869473de.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先声明API函数ExitWindowEx:
Declare Function ExitWindowEx Lib "USER32"(ByVal uFlags As Long,ByVal swReserved as Long)As long
关机是ExitWindowEx(EWX_SHUTDOWN,0)
重启是ExitWindowEx(EWX_REBOOT,0)
example:
Private Sub shut_CLick()
Dim abc as Long
Unload me
abc = ExitWindowEx(EWX_SHUTDOWN,0)
End Sub
Declare Function ExitWindowEx Lib "USER32"(ByVal uFlags As Long,ByVal swReserved as Long)As long
关机是ExitWindowEx(EWX_SHUTDOWN,0)
重启是ExitWindowEx(EWX_REBOOT,0)
example:
Private Sub shut_CLick()
Dim abc as Long
Unload me
abc = ExitWindowEx(EWX_SHUTDOWN,0)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询