我有Windows服务器,我曾经通过远程桌面连接,但是如果我让它闲置就被锁定,而且我无法改变远程桌面选项的超时,所以我想写一个批处理文件或 vbscript 或 powershell ,它们将在Windows服务器中运行并自行刷新(F5)或鼠标单击或鼠标移动,每5分钟一次。< / p>
server 2008 R2 entreprise 64-bit
答案 0 :(得分:1)
试试这个vbscript:
Option Explicit
If AppPrevInstance() Then
MsgBox "There is an existing proceeding !" & VbCrLF &_
CommandLineLike(WScript.ScriptName),VbExclamation,"There is an existing proceeding !"
WScript.Quit
Else
Dim Ws
set Ws = createobject("Wscript.Shell")
Do
Ws.Sendkeys "{F5}"
Pause 5 '==> To sleep for 5 minutes
Loop
End If
'**************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'**************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'**************************************************************************
Sub Pause(min)
Wscript.Sleep(min*1000*60)
End sub
'**************************************************************************