低碳生活――从屏保开始

为了响应党中央号召,低碳环保,特奉献一段屏保代码,该代码是利用修改注册表中屏保键值的原理而作,所以需要第二次重启后才生效,So最后增加了一段可选择性重启的代码。如果是利用组策略下发,最好去掉从'reboot or not之后的代码,避免引起不必要的麻烦。

Const HKEY_CURRENT_USER = &H80000001

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

strKeyPath = "Control Panel\Desktop"

strValueName = "ScreenSaveActive"
strValue = "1"
oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "ScreenSaveTimeOut"
strValue = "300"
oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "SCRNSAVE.EXE"
strValue = "%systemroot%\system32\logon.scr"
oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

strValueName = "ScreenSaverIsSecure"
strValue = "1"
oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

'Reboot or not
strReboot = MsgBox("Do you want to reboot computer?", vbYesNo, "Warning!")
 If strReboot = vbNo Then
 Wscript.Quit
 End If

'==Reboot Computer==
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Reboot()
Next

你可能感兴趣的:(职场,休闲,5分钟屏保)