求一个vb代码,检测CPU占用率,连续5分钟低于50%,则休眠
求一个vb脚本,检测CPU占用率,连续5分钟低于50%,则休眠。情况是这个样子的,本人有两台渲染服务器,由于长时间开机感觉很耗电,故打算在服务器在闲时自动休眠,需要用的时...
求一个vb脚本,检测CPU占用率,连续5分钟低于50%,则休眠。
情况是这个样子的,本人有两台渲染服务器,由于长时间开机感觉很耗电,故打算在服务器在闲时自动休眠,需要用的时候在客户机上直接远程唤醒就行了,远程唤醒已经解决了,不过服务器自动休眠解决不了,想到用VB脚本,自己对编程又不懂,只能上百的来求助各位大神,无比感谢! 展开
情况是这个样子的,本人有两台渲染服务器,由于长时间开机感觉很耗电,故打算在服务器在闲时自动休眠,需要用的时候在客户机上直接远程唤醒就行了,远程唤醒已经解决了,不过服务器自动休眠解决不了,想到用VB脚本,自己对编程又不懂,只能上百的来求助各位大神,无比感谢! 展开
展开全部
建议你直接在电源选项里面设定比如20分钟无操作就休眠这样的。
ps: 服务器无工作的时候功率不高,没必要休眠之类的。并且休眠之后再唤醒很可能有各种问题的。
ps: 服务器无工作的时候功率不高,没必要休眠之类的。并且休眠之后再唤醒很可能有各种问题的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用的什么操作系统啊?
一般操作系统自带休眠功能啊
Shell "Rundll32.exe PowrProf.dll, SetSuspendState"试试这个
以下为一个取得CPU使用率的类,侵删
Option Explicit
' ╭════════════════╮
' ║ E动天下—VB专业源码网 ║
' ╭════════┤ 网站:http://www.2e3.org ├═════════╮
' ║ ╰════════════════╯ ║
' ║ 人人为我,我为人人 ║
' ║ ║
' ║ E动天下vb专业源码网汉化收藏整理 ║
' ║ ║
' ║ 网 站:http://www.2e3.org/ ║
' ║ ║
' ║ e-mail :admin@2e3.org ║
' ║ ║
' ║ QQ :83892778 ║
' ║ ║
' ║ 如果您有新的、好的代码可以提供给E动天下上发布,让大家学习哦! ║
' ║ ║
' ║ ║
' ║-----更多精彩源码,尽在E动天下(www.2e3.org),欢迎您的到来------------║
' ║ ║
' ║ ╭════════════════════╮ ║
' ║ ║ ║ ║
' ╰═══════┤ E动天下—VB专业源码网(www.2e3.org) ├══════╯
' ║ ║
' ╰════════════════════╯
Private Declare Function NtQuerySystemInformation Lib "ntdll" (ByVal dwInfoType As Long, lpStructure As Any, ByVal dwSize As Long, ByVal dwReserved As Long) As Long
Private Const SYSTEM_BASICINFORMATION = 0&
Private Const SYSTEM_PERFORMANCEINFORMATION = 2&
Private Const SYSTEM_TIMEINFORMATION = 3&
Private Const NO_ERROR = 0
Private Type SYSTEM_PERFORMANCE_INFORMATION
liIdleTime As Currency 'Idle
dwSpare(0 To 75) As Long
End Type
Private Type SYSTEM_BASIC_INFORMATION
dwUnknown1 As Long
uKeMaximumIncrement As Long
uPageSize As Long
uMmNumberOfPhysicalPages As Long
uMmLowestPhysicalPage As Long
uMmHighestPhysicalPage As Long
uAllocationGranularity As Long
pLowestUserAddress As Long
pMmHighestUserAddress As Long
uKeActiveProcessors As Long '活动处理器
bKeNumberProcessors As Byte '处理器个数
bUnknown2 As Byte
wUnknown3 As Integer
End Type
Private Type SYSTEM_TIME_INFORMATION
liKeBootTime As Currency '启动时间
liKeSystemTime As Currency
liExpTimeZoneBias As Currency
uCurrentTimeZoneId As Long
dwReserved As Long
End Type
Private lidOldIdle As Currency '上次空闲时间
Private liOldSystem As Currency '上次系统时间
Private sbSysBasicInfo As SYSTEM_BASIC_INFORMATION
Public Function GetCPUUsage() As Long
Dim spSysPerforfInfo As SYSTEM_PERFORMANCE_INFORMATION
Dim stSysTimeInfo As SYSTEM_TIME_INFORMATION
Dim curIdle As Currency
Dim curSystem As Currency
GetCPUUsage = -1
If NtQuerySystemInformation(SYSTEM_TIMEINFORMATION, stSysTimeInfo, Len(stSysTimeInfo), 0&) <> NO_ERROR Then Exit Function
If NtQuerySystemInformation(SYSTEM_PERFORMANCEINFORMATION, spSysPerforfInfo, Len(spSysPerforfInfo), 0&) <> NO_ERROR Then Exit Function
curIdle = spSysPerforfInfo.liIdleTime - lidOldIdle
curSystem = stSysTimeInfo.liKeSystemTime - liOldSystem
If curSystem <> 0 Then curIdle = (curIdle / curSystem) * 100
GetCPUUsage = CLng(100 - curIdle / sbSysBasicInfo.bKeNumberProcessors)
lidOldIdle = spSysPerforfInfo.liIdleTime
liOldSystem = stSysTimeInfo.liKeSystemTime
End Function
Private Sub Class_Initialize()
Dim stSysTimeInfo As SYSTEM_TIME_INFORMATION
Dim spSysPerforfInfo As SYSTEM_PERFORMANCE_INFORMATION
If NtQuerySystemInformation(SYSTEM_BASICINFORMATION, sbSysBasicInfo, Len(sbSysBasicInfo), 0&) <> NO_ERROR Then Exit Sub
If NtQuerySystemInformation(SYSTEM_TIMEINFORMATION, stSysTimeInfo, Len(stSysTimeInfo), 0&) <> NO_ERROR Then Exit Sub
If NtQuerySystemInformation(SYSTEM_PERFORMANCEINFORMATION, spSysPerforfInfo, LenB(spSysPerforfInfo), ByVal 0&) <> NO_ERROR Then Exit Sub
lidOldIdle = spSysPerforfInfo.liIdleTime
liOldSystem = stSysTimeInfo.liKeSystemTime
End Sub
一般操作系统自带休眠功能啊
Shell "Rundll32.exe PowrProf.dll, SetSuspendState"试试这个
以下为一个取得CPU使用率的类,侵删
Option Explicit
' ╭════════════════╮
' ║ E动天下—VB专业源码网 ║
' ╭════════┤ 网站:http://www.2e3.org ├═════════╮
' ║ ╰════════════════╯ ║
' ║ 人人为我,我为人人 ║
' ║ ║
' ║ E动天下vb专业源码网汉化收藏整理 ║
' ║ ║
' ║ 网 站:http://www.2e3.org/ ║
' ║ ║
' ║ e-mail :admin@2e3.org ║
' ║ ║
' ║ QQ :83892778 ║
' ║ ║
' ║ 如果您有新的、好的代码可以提供给E动天下上发布,让大家学习哦! ║
' ║ ║
' ║ ║
' ║-----更多精彩源码,尽在E动天下(www.2e3.org),欢迎您的到来------------║
' ║ ║
' ║ ╭════════════════════╮ ║
' ║ ║ ║ ║
' ╰═══════┤ E动天下—VB专业源码网(www.2e3.org) ├══════╯
' ║ ║
' ╰════════════════════╯
Private Declare Function NtQuerySystemInformation Lib "ntdll" (ByVal dwInfoType As Long, lpStructure As Any, ByVal dwSize As Long, ByVal dwReserved As Long) As Long
Private Const SYSTEM_BASICINFORMATION = 0&
Private Const SYSTEM_PERFORMANCEINFORMATION = 2&
Private Const SYSTEM_TIMEINFORMATION = 3&
Private Const NO_ERROR = 0
Private Type SYSTEM_PERFORMANCE_INFORMATION
liIdleTime As Currency 'Idle
dwSpare(0 To 75) As Long
End Type
Private Type SYSTEM_BASIC_INFORMATION
dwUnknown1 As Long
uKeMaximumIncrement As Long
uPageSize As Long
uMmNumberOfPhysicalPages As Long
uMmLowestPhysicalPage As Long
uMmHighestPhysicalPage As Long
uAllocationGranularity As Long
pLowestUserAddress As Long
pMmHighestUserAddress As Long
uKeActiveProcessors As Long '活动处理器
bKeNumberProcessors As Byte '处理器个数
bUnknown2 As Byte
wUnknown3 As Integer
End Type
Private Type SYSTEM_TIME_INFORMATION
liKeBootTime As Currency '启动时间
liKeSystemTime As Currency
liExpTimeZoneBias As Currency
uCurrentTimeZoneId As Long
dwReserved As Long
End Type
Private lidOldIdle As Currency '上次空闲时间
Private liOldSystem As Currency '上次系统时间
Private sbSysBasicInfo As SYSTEM_BASIC_INFORMATION
Public Function GetCPUUsage() As Long
Dim spSysPerforfInfo As SYSTEM_PERFORMANCE_INFORMATION
Dim stSysTimeInfo As SYSTEM_TIME_INFORMATION
Dim curIdle As Currency
Dim curSystem As Currency
GetCPUUsage = -1
If NtQuerySystemInformation(SYSTEM_TIMEINFORMATION, stSysTimeInfo, Len(stSysTimeInfo), 0&) <> NO_ERROR Then Exit Function
If NtQuerySystemInformation(SYSTEM_PERFORMANCEINFORMATION, spSysPerforfInfo, Len(spSysPerforfInfo), 0&) <> NO_ERROR Then Exit Function
curIdle = spSysPerforfInfo.liIdleTime - lidOldIdle
curSystem = stSysTimeInfo.liKeSystemTime - liOldSystem
If curSystem <> 0 Then curIdle = (curIdle / curSystem) * 100
GetCPUUsage = CLng(100 - curIdle / sbSysBasicInfo.bKeNumberProcessors)
lidOldIdle = spSysPerforfInfo.liIdleTime
liOldSystem = stSysTimeInfo.liKeSystemTime
End Function
Private Sub Class_Initialize()
Dim stSysTimeInfo As SYSTEM_TIME_INFORMATION
Dim spSysPerforfInfo As SYSTEM_PERFORMANCE_INFORMATION
If NtQuerySystemInformation(SYSTEM_BASICINFORMATION, sbSysBasicInfo, Len(sbSysBasicInfo), 0&) <> NO_ERROR Then Exit Sub
If NtQuerySystemInformation(SYSTEM_TIMEINFORMATION, stSysTimeInfo, Len(stSysTimeInfo), 0&) <> NO_ERROR Then Exit Sub
If NtQuerySystemInformation(SYSTEM_PERFORMANCEINFORMATION, spSysPerforfInfo, LenB(spSysPerforfInfo), ByVal 0&) <> NO_ERROR Then Exit Sub
lidOldIdle = spSysPerforfInfo.liIdleTime
liOldSystem = stSysTimeInfo.liKeSystemTime
End Sub
追问
win10 win7都有 windows自带的休眠不好用 判断空闲时间是以鼠标键盘输入为准 作为服务器 基本不配鼠标和键盘 而且渲染是后台进行的,就只能判断CPU的使用率来确认电脑是否空闲,休眠
命令昨天已经做成bat了,但是需要前置条件判断持续空闲时间,再自动运行
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
算半休眠状态
追问
是休眠啊 用wakemeonlan唤醒 批处理wakemeonlan /wakeup 192.168.1.X唤醒服务器
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询