当前位置:首页 > 代码 > 正文

vb取消关机代码(vbs关机代码怎么关)

admin 发布:2022-12-19 22:50 186


今天给各位分享vb取消关机代码的知识,其中也会对vbs关机代码怎么关进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

VB在窗口建立一个按钮,求把这个按钮按下去即可关闭计算机的代码

vb6.0实现关机的简单代码:Shell "shutdown -s -t 5" '执行这代码后,5秒内关机Shell "shutdown -a" '取消关机Shell "shutdown -r -t 5" '执行这代码后,5秒内关机并重启

关于shutdown的参数,在运行中输入cmd,回车后在窗口中输入shutdown help

vb6调用关机对话框:

Private Declare Function SHShutDownDialog Lib "shell32" Alias "#60" (ByVal YourGuess As Long) As Long '声明

Private Sub Form_Click()

SHShutDownDialog 0 '调用

End Sub

求VB取消关机代码

Module1.bas:Public Declare Function SetWindowLong Lib "user32" _

Alias "SetWindowLongA" _

(ByVal hwnd As Long, _

ByVal nIndex As Long, _

ByVal dwNewLong As Long) _

As LongPublic Declare Function GetWindowLong Lib "user32" _

Alias "GetWindowLongA" _

(ByVal hwnd As Long, _

ByVal nIndex As Long) _

As LongPublic Declare Function CallWindowProc Lib "user32" _

Alias "CallWindowProcA" _

(ByVal lpPrevWndFunc As Long, _

ByVal hwnd As Long, _

ByVal Msg As Long, _

ByVal wParam As Long, _

ByVal lParam As Long) _

As Long

'定义常数

Public Const GWL_WNDPROC = (-4)'全局变量,存放控件标志性数据

Public preWinProc As Long

Public m_AllowExit As Boolean '是否可以退出windowsPublic Function wndproc(ByVal hwnd As Long, ByVal Msg As Long, _

ByVal wParam As Long, ByVal lParam As Long) As Long

'截取下来的消息存放在msg参数中

If (m_AllowExit = False) And (Msg = 17) Then

Form1.List1.AddItem "有程序试图关闭Windows!"

Else

'如果不是需要处理的消息,则将之送回原来的程序.

wndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)

End If

End Function

------------------------------------------------------------------------------------------------------------modMain.bas:Option ExplicitPrivate Type tagInitCommonControlsEx

lngSize As Long

lngICC As Long

End Type

Private Declare Function InitCommonControlsEx Lib "comctl32.dll" (iccex As tagInitCommonControlsEx) As Boolean

Private Const ICC_USEREX_CLASSES = H200

Private Declare Sub InitCommonControls Lib "comctl32.dll" ()

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" ( _

ByVal lpLibFileName As String) As Long

Public Declare Function FreeLibrary Lib "kernel32" ( _

ByVal hLibModule As Long) As LongPublic m_hMod As LongPublic Sub Main()

'设置工程属性,启动对象为main

On Error Resume Next Dim iccex As tagInitCommonControlsEx

With iccex

.lngSize = LenB(iccex)

.lngICC = ICC_USEREX_CLASSES

End With

InitCommonControlsEx iccex

m_hMod = LoadLibrary("shell32.dll")

InitCommonControls ' now start the application

On Error GoTo 0

Form1.Show '显示主窗体

End Sub

-----------------------------------------------------------------------------------------------------------------------------------form1:Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Sub Check1_Click()

If Check1.Value = 1 Then

m_AllowExit = False '不允许退出windows

Else

m_AllowExit = True '允许退出windows

End If

End SubPrivate Sub Command1_Click()

List1.Clear

End Sub

Private Sub Form_Load()

m_AllowExit = False

SubClass Me.hwnd

ShowWindow Me.hwnd, 7

End SubPrivate Sub Form_Unload(Cancel As Integer)

EndSubClass Me.hwnd

End SubPrivate Sub SubClass(wnd As Long)

Dim ret As Long

'记录Window Procedure的地址

preWinProc = GetWindowLong(wnd, GWL_WNDPROC)

'开始截取消息,并将消息交给wndproc过程处理

ret = SetWindowLong(wnd, GWL_WNDPROC, AddressOf wndproc)

End SubPrivate Sub EndSubClass(wnd As Long)

Dim ret As Long

'取消消息截取,结束子分类过程.

ret = SetWindowLong(wnd, GWL_WNDPROC, preWinProc)

End Sub

VB强制中断关机代码

说实话,楼主用的肯定是XP以上版本了。如果楼主用2000这个命令就没用了,因为2000里面没有shutdown命令。如果一定要用其实也没那么复杂

之前的代码也可以简化

比如shell

"shutdown

-s

-t

30"

之后取消就用shell

"shutdown

-a"就好,当然楼主只是在自己电脑上玩玩那可以这么弄,如果想run

everywhere的话要用API,需要可以加我237393775.我们一起讨论研究!

VB自动关机代码是什么?

Option Explicit

Private Sub Command1_Click() '关机

Shell "cmd.exe /c shutdown -s -t 6000" '6000秒后关几

End Sub

Private Sub Command2_Click() '取消关机

Shell "cmd.exe /c shutdown -a"

End

End Sub

怎么用VB编写关机、重启、注销的功能(注:非强制,功能与单击开始菜单里的一样!)

Sub 关机()

    Shell "shutdown -s"  '电脑将在一分钟之后关机,cmd输入shutdown -a 取消关机

End Sub

Sub 重启()

    Shell "shutdown -r"  '电脑将在一分钟之后重启,cmd输入shutdown -a 取消重启

End Sub

Sub 注销()

    Shell "logoff"   '电脑将立即注销

End Sub

VB关机程序代码

'ok添加两个按钮,把下面代码直接复制粘贴进代码输入框把原来的代码全部覆盖,f5就可以了。

privatesubform_load()

command1.caption="关机"

command2.caption="重启"

privatesubcommand1_click()

shell"cmd/c""shutdown-s-t0"

endsub'关机代码,0代表时间,就是几秒后关机

privatesubcommand2_click()

shell"cmd/c""shutdown-r-t0"

endsub'重启代码

关于vb取消关机代码和vbs关机代码怎么关的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/28541.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载