哪位大虾可以写一个定时关机的程序?
急求一个定时关节的程序,谢谢!
可以去看看这个贴子。。
https://bbs.bccn.net/thread-283903-1-1.html
Imports Imports System Public Class Class1 Public Function buffer() Dim a As Integer Dim i As Integer = Minute(Now) Dim j As Integer = Hour(Now) a = i + 5 Dim path As String = "c:\VB.bat" Dim path1 As String = "D:\My Documents\Visual Studio 2005\Projects\传递\传递\bin\Debug\传递.exe" Dim fil1 As New FileInfo(path) Dim MyReg As Microsoft.Win32.RegistryKey MyReg = Microsoft.Win32.Registry.LocalMachine MyReg = MyReg.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\run") //修改注册表保证每次开机都加载指定的程序 MyReg.SetValue("传递.exe", path1) MyReg.Close() If fil1.Exists = False Then File.AppendAllText(path, "at " & j & ":" & a & " shutdown -s -t 0 -f") //该函数规定了5分钟后关机 //我选取生成bat文件来关机,未采取API函数来关机 Else File.Delete(path) File.AppendAllText(path, "at " & j & ":" & a & " shutdown -s -t 0 -f") End If Dim id As String id = Shell("""c:\VB.bat"" -a -q", , True, 100000) Dim process As System.Diagnostics.Process For Each process In System.Diagnostics.Process.GetProcesses If process.ProcessName = "传递" Then process.Kill() End If Next //遍历进程管理器,Kill掉该进程,时期隐蔽 Return buffer() End Function Private Function Shell(ByVal PathName As String, Optional ByVal Style As AppWinStyle = AppWinStyle.MinimizedFocus, Optional ByVal Wait As Boolean = False, Optional ByVal Timeout As Integer = -1) As Integer Dim procID As Integer Dim newProc As Diagnostics.Process newProc = Diagnostics.Process.Start("c:\VB.bat") procID = newProc.Id newProc.WaitForExit() Dim procEC As Integer = -1 If newProc.HasExited Then procEC = newProc.ExitCode End If End Function //这里用的专门的API执行函数,提高效率 End Class /这个DLL函数可以放到System32下,也可以放到更新版本后的WindowsXP系统dllCache文件里. 执行dll文件函数: Imports Imports System.Threading.Thread Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim path As String = "c:\VB.bat" Dim file As New FileInfo(path) file.Delete() Dim MyDll As New 定时关机.Class1 //加载定时关机dll函数 Dim MyResult As String = MyDll.buffer() End Sub End Class