as lan112233
Newbie | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Добрый день. кто бы смог написать скрип который при удачном пинге выполнял бы определенную команду, как только комп перестает быть доступен(выключается) выполняется другая программа. В сети два комп, главный и ноут. На главном периодически запускается торрент который отъедает весь канал. В наличии есть скрипт который следит за определенный процессом( в данном случае это опера) и как только этот процесс найдет выполняется команда для снижения скорости. Как только выключается опера выполняется другая команда для восстановления. Можно ли в этот скрипт дописать строки чтоб кроме как слежения за процессом было слежением и за доступностью сетевого комп. Вот содержимое скрипта. Код: 'Версия 1.5 (Final) 'Настройки''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Const InstallPath = "C:\Program Files\uTorrent\" ' - путь к папке, где лежит "utspeed.exe" [Str] Public Const MonitorProcess = "opera.exe" ' - название отслеживаемого процесса [Str] Public Const Mode = 0 ' - режимы: 0 - лимиты, 1 - расписание, 2 - ipfilter [0/1/2] Public Const FileNameOn = "UT Limiter [on].vbs" ' - имя файла при включенном скрипте [Str] Public Const FileNameOff = "UT Limiter [off].vbs" ' - имя файла при выключенном скрипте [Str] Public Const DownloadDefault = 60 ' - нормальная скорость скачки [кб/c] Public Const UploadDefault = 60 ' - нормальная скорость отдачи [кб/c] Public Const DownloadLimit = 5 ' - ограничение скорости скачки при обнаруж. процесса [кб/c] Public Const UploadLimit = 20 ' - ограничение скорости отдачи при обнаруж. процесса [кб/c] Public Const IdleTime = 15 ' - время простоя до частичного восстановл. скорости [сек.] Public Const IdleDownSpeed = 50 ' - скорость скачки во время простоя [кб/c] Public Const IdleUpSpeed = 50 ' - скорость отдачи во время простоя [кб/c] Public Const AwayTime = 50 ' - время отсутствия до полного восстановл. скорости [сек.] Public Const AwayDownSpeed = 50 ' - скорость скачки во время отсутствия [кб/c] Public Const AwayUpSpeed = 50 ' - скорость отдачи во время отсутствия [кб/c] 'Инициализация''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' IsLimited = 2 Set objShell = CreateObject("Shell.Application") Set Fso = CreateObject("Scripting.FileSystemObject") Set f = Fso.GetFile(Wscript.ScriptFullName) Set oAutoIt = WScript.CreateObject("AutoItX3.Control") If Fso.FileExists(InstallPath & "utspeed.exe") = false then Msgbox "Сначала укажите путь к папке! ", vbInformation + vbOKOnly, "UT Limiter" ExitScript End if If f.Name = FileNameOn then ExitScript else f.Name = FileNameOn End if 'Мониторинг'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Do If oAutoIt.ProcessExists(MonitorProcess) then IsLimited = SetLimitsTrue(IsLimited) else IsLimited = SetLimitsFalse(IsLimited) End if If Fso.FileExists(FileNameOn) = false then IsLimited = SetLimitsFalse(IsLimited) ExitScript End if PrevMpos = 0 Do while oAutoIt.ProcessExists(MonitorProcess) and oAutoIt.ProcessExists("utorrent.exe") If Fso.FileExists(FileNameOn) = false then IsLimited = SetLimitsFalse(IsLimited) ExitScript End if CurMpos = oAutoIt.MouseGetPosX StartTime = Timer Do while CurMpos = PrevMpos If Timer - StartTime > IdleTime then IsLimited = SetIdleLimits(IsLimited) End if If Timer - StartTime > AwayTime then IsLimited = SetAwayLimits(IsLimited) End if Wscript.Sleep 200 CurMpos = oAutoIt.MouseGetPosX Loop If IsLimited = 3 or IsLimited = 4 then IsLimited = SetLimitsTrue(IsLimited) End if PrevMpos = CurMpos Wscript.Sleep 500 Loop Wscript.Sleep 500 Loop 'Функции''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function SetLimitsTrue (IsLimited) If IsLimited <> 1 and Mode = 0 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/max_dl_rate " & DownloadLimit & " /max_ul_rate " & UploadLimit, InstallPath oAutoIt.ProcessWaitClose "utspeed.exe" IsLimited = 1 End if If IsLimited <> 1 and Mode = 1 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/sched_enable 1", InstallPath oAutoIt.ProcessWaitClose "utspeed.exe" IsLimited = 1 End if If IsLimited <> 1 and Mode = 2 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/ipfilter.enable 1", InstallPath oAutoIt.ProcessWaitClose "utspeed.exe" IsLimited = 1 End if SetLimitsTrue = IsLimited End Function Function SetLimitsFalse (IsLimited) If IsLimited <> 0 and Mode = 0 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/max_dl_rate " & DownloadDefault & " /max_ul_rate " & UploadDefault, InstallPath oAutoIt.ProcessWaitClose "utspeed.exe" IsLimited = 0 End if If IsLimited <> 0 and Mode = 1 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/sched_enable 0", InstallPath oAutoIt.ProcessWaitClose "utspeed.exe" IsLimited = 0 End if If IsLimited <> 0 and Mode = 2 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/ipfilter.enable 0", InstallPath oAutoIt.ProcessWaitClose "utspeed.exe" IsLimited = 0 End if SetLimitsFalse = IsLimited End Function Function SetIdleLimits (IsLimited) If IsLimited <> 3 and IsLimited <> 4 and Mode = 0 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/max_dl_rate " & IdleDownSpeed & " /max_ul_rate " & IdleUpSpeed, InstallPath oAutoIt.ProcessWaitClose "utspeed.exe" IsLimited = 3 End if SetIdleLimits = IsLimited End Function Function SetAwayLimits (IsLimited) If IsLimited <> 4 and Mode = 0 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/max_dl_rate " & AwayDownSpeed & " /max_ul_rate " & AwayUpSpeed, InstallPath oAutoIt.ProcessWaitClose "utspeed.exe" IsLimited = 4 End if If IsLimited <> 4 and Mode = 1 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/sched_enable 0", InstallPath IsLimited = 4 End if If IsLimited <> 4 and Mode = 2 and oAutoIt.ProcessExists("utorrent.exe") then objShell.ShellExecute "utspeed.exe", "/ipfilter.enable 0", InstallPath IsLimited = 4 End if SetAwayLimits = IsLimited End Function Function ExitScript on error resume next f.Name = FileNameOff Wscript.Quit End Function |
|