新建一个简单无窗口的程序—作用在于检测你的主程序是否结束,如果结束就将它重启。
然后在主程序的关闭消息中启动这个程序即可。
要不就做个后台一直运行,监测你的主程序是否结束,如果结束就启动它,一般都这样做。
CmdStartCTIProc(ApplicationExecutablePath, "cmd params");//放到捕获事件的处理代码后,重启程序,需要时加上重启的参数。
C#实现启动远程计算机的原理是"视窗管理规范"。就是所谓的"WMI"(Windows Management Instrumentation)。Windows 管理规范 (WMI) 支持通过 Internet 管理系统的结构。
如果程序需要重启只需要在捕获的事件处理时启动当前应用程序的代码即可。参考如下:
//重启程序,需要时加上重启的参数
SystemDiagnosticsProcessStartInfo cp = new SystemDiagnosticsProcessStartInfo();
cpFileName = ApplicationExecutablePath;
cpArguments = "cmd params";
cpUseShellExecute = true;
SystemDiagnosticsProcessStart(cp);
Call Shell ("shutdown -l -f")'注销
Call Shell ("shutdown -s -f")'关闭
Call Shell ("shutdown -r -f")'重启
或设定状态
SetSuspendState
是否支持休眠
IsPwrHibernateAllowed
是否支持待机
IsPwrSuspendAllowed看MSDN的Power Management部分ColdMooon 1主要过程
'在窗体内
'放置一个时间控件,两个标签控件和一个文体框控件,和两个单选按钮,两个命令按钮Option Explicit
Dim txtTime '保存输入时间
Dim nowTime '保存实时时间
Dim oldTime '保存开始定时时间Private Sub Form_Load()mecaption="定时关机"melabel1caption="关机时间:"
meOption1caption="在指定时间关机(时间格式:00:00:00)"
meOption2caption="延迟指定的时间关机"
mecommand1caption="确定"
mecommand2caption="取消"
MeText1 = GetSetting("ShutDownWindows", "Options", "ShutDownTime", "1:00")
me!timer1interval=1000End Sub
Private Sub Command1_Click()
oldTime = Time
If Not IsDate(Text1Text) Then '用IsData函数判断输入的时间格式
MsgBox "你所输入的不是时间格式,请修改!", , "Wrong"
ElseIf Option1Value Then
txtTime = TimeValue(Text1Text)
Timer1Enabled = True '启动定时器
MeWindowState = 1 '最小化窗体
MeCaption = "定时关机-启动"
ElseIf Option2Value Then
MeWindowState = 1
MeCaption = "定时关机-暂停"
End If
End SubPrivate Sub Command2_Click()Unload MeEnd Sub
Private Sub Form_Unload(Cancel As Integer)SaveSetting "ShutDownWindows", "Options", "ShutDownTime", MeText1End SubPrivate Sub Timer1_Timer()
nowTime = Time
Melabel2Caption = Time
If Option1Value Then
If DateDiff("s", nowTime, txtTime) <= 0 And DateDiff("s", nowTime, txtTime) >= -60 Then '用DateDiff函数判断是否到时间了
ShutDownPC True
Timer1Enabled = False
End If
End If
End Sub '在标准模块内
Private Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_POWEROFF = 8 '此参数在VB自带API浏览器并未提供,值得注意,如果没有此参数在Win2kServer会死在关机屏幕下
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const ANYSIZE_ARRAY = 1
Private Const VER_PLATFORM_WIN32_NT = 2Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String 128
End TypeType LUID
LowPart As Long
HighPart As Long
End TypeType LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End TypeType TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End TypePrivate Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (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
Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
'Detect if the program is running under Windows NT 检测是否为NT
Public Function IsWinNT() As Boolean
Dim myOS As OSVERSIONINFO
myOSdwOSVersionInfoSize = Len(myOS)
GetVersionEx myOS
IsWinNT = (myOSdwPlatformId = VER_PLATFORM_WIN32_NT)
End Function
'set the shut down privilege for the current application 为当前应用程序设置关机权限
Private Sub EnableShutDown()
Dim hProc As Long
Dim hToken As Long
Dim mLUID As LUID
Dim mPriv As TOKEN_PRIVILEGES
Dim mNewPriv As TOKEN_PRIVILEGES
hProc = GetCurrentProcess()
OpenProcessToken hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken
LookupPrivilegeValue "", "SeShutdownPrivilege", mLUID
mPrivPrivilegeCount = 1
mPrivPrivileges(0)Attributes = SE_PRIVILEGE_ENABLED
mPrivPrivileges(0)pLuid = mLUID
' enable shutdown privilege for the current application 赋予当前应用程序关机权限
AdjustTokenPrivileges hToken, False, mPriv, 4 + (12 mPrivPrivilegeCount), mNewPriv, 4 + (12 mNewPrivPrivilegeCount)
End Sub
' Shut Down PC 关闭PC
Public Sub ShutDownPC(Force As Boolean)
Dim ret As Long
Dim Flags As Long
Flags = EWX_SHUTDOWN Or EWX_POWEROFF
If Force Then Flags = Flags + EWX_FORCE
If IsWinNT Then EnableShutDown
ExitWindowsEx Flags, 0
End Sub
'Restart PC 重起PC
Public Sub RebootPC(Force As Boolean)
Dim ret As Long
Dim Flags As Long
Flags = EWX_REBOOT
If Force Then Flags = Flags + EWX_FORCE
If IsWinNT Then EnableShutDown
ExitWindowsEx Flags, 0
End Sub
'Log off the current user 注消(登出)当前用户
Public Sub LogOff(Force As Boolean)
Dim ret As Long
Dim Flags As Long
Flags = EWX_LOGOFF
If Force Then Flags = Flags + EWX_FORCE
ExitWindowsEx Flags, 0
End Sub
'自动开机说明:(以CMOS Setup Utility - Copyright (C) 1984-2001 Award Software 为例)
'开机按Delete键进入CMOS Setup程序
'把选择移到Power Management Setup(电源管理设置), 按回车
'然后把选择移到Resume by Alarm,按PageDown键选择Enable
'移到下一行把Date(of Month) Alarm 设为0
'移到下一行把Time(hh:mm:ss) Alarm 设为[自己的开机时间],例如:8:0:0(早上8点开机) 我复制的 希望对楼主有帮助
刑事案件重审程序的规定,根据《 刑事诉讼法 》第二百五十六条规定,人民法院按照 审判监督程序 重新审判的案件,由原审人民法院审理的,应当另行组成合议庭进行。如果原来是第一审案件,应当依照 第一审程序 进行审判,所作的判决、裁定,可以上诉、抗诉;如果原来是第二审案件,或者是上级人民法院提审的案件,应当依照 第二审程序 进行审判,所作的判决、裁定,是终审的判决、裁定。人民法院开庭审理的再审案件,同级人民检察院应当派员出席法庭。《刑事诉讼法》第二百五十六条人民法院按照审判监督程序重新审判的案件,由原审人民法院审理的,应当另行组成合议庭进行。如果原来是第一审案件,应当依照第一审程序进行审判,所作的判决、裁定,可以上诉、抗诉;如果原来是第二审案件,或者是上级人民法院提审的案件,应当依照第二审程序进行审判,所作的判决、裁定,是终审的判决、裁定。人民法院开庭审理的再审案件,同级人民检察院应当派员出席法庭。
以上就是关于如何在delphi中重启程序!全部的内容,包括:如何在delphi中重启程序!、“C# WinForm ”如何实现程序重启、如何编写自动重启程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)