Almost a fifth of cancer cases worldwide are caused by a chronic infection. Most of these infections are viruses.

Folding Control Script
#1
So I've been working on a script for a little while that would allow F@H to automatically stop and start based on the presence of predefined processes.
ie: Whenever I start minecraft, F@H pauses, then restarts when I close the minecraft process.

The script works as is right now, but could use some polishing.

Pros:
  • Pauses folding when any process (or combination of processes) from a list is detected
  • Unpauses folding when no items from list are detected (if there were detected items detected in the previous check)

Cons:
  • Must use PuTTY client to access F@H web control
  • Must have F@H configured to accept web control
  • There is a brief moment when the vb script is entering commands in the invisible puTTY window, during which the user can pull focus and disrupt the process
  • User must compile list of process names (unavoidable?)

At this point, the user manually enters the process names in the ~4th line of the script ('gameList'), and the script must have the portable PuTTY executable in the same folder.

The code:
Code:
'=============================================================
' Name:     Folding Control
' Author:     Devon Hanbey - dhanbey@barghausen.com
' Date:     2014/12/29
' Description:     This script can pause or unpause F@H slots-
'        to be used with a scheduler, or based on open
'        software such as games. (as notated in 'gameList')
' Version:     2.2
'=============================================================

Option Explicit
Dim WshShell, objWMIService, objProcess, colProcess, strComputer, gameList, itemQuantity, gameNum, i, foundMatches, paused, fileContents(), file, objFSO, contents

'gameList = Array("vlc.exe","hexchat.exe")
'itemQuantity = 2

'Read contents of watchList from file
Function readFile(fileName)
    'Open file
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set contents = objFSO.OpenTextFile(fileName, 1)
    
    'Read in file contents, line by line
    i = 0
    Do Until contents.AtEndOfStream
    Redim Preserve fileContents(i)
    fileContents(i) = contents.ReadLine
    i = i + 1
    Loop
    
    readFile = fileContents        
End Function
    

'Send specified command to local installation of FAH
Function controlFAH(command)
    
    'Begin Telnet session using the putty client that ought to be in this folder
    set WshShell = CreateObject("WScript.Shell")
    WScript.Sleep 2000
    WshShell.run "putty.exe -raw localhost 36330",0,false
    'This command includes the port FAH listens to, and a command to run silent
    
    'Wait for PuTTY for a bit
    WScript.Sleep 2000

    'Send appropriate command
    WshShell.AppActivate("PuTTY")
    WshShell.SendKeys command
    WshShell.AppActivate("PuTTY")
    WshShell.SendKeys ("{Enter}")
    WScript.Sleep 300

    'Exit Telnet session
    WshShell.run "taskkill /im PuTTY.exe /f",0,false

End Function


'Compare each running process against list of games to watch for, return # of matches
Function countMatchRunning(itemQuantity,gameList)
    'Reset foundMatches for a new check
    foundMatches = 0
    
    'Get list of running processes
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process")
    
    'number of games to use in a loop
    gameNum = itemQuantity

    'For every process,
    For Each objProcess in colProcess
        'check against each line of our watch list
        For i=0 To gameNum
        
            If (CStr(objProcess.Name) = gameList(i)) then
                'MsgBox (CStr(objProcess.Name))
                foundMatches = foundMatches + 1
            Else
                'MsgBox ("Nope!")
            End If
            
        Next
    Next
    countMatchRunning = foundMatches
End Function


Function main()
    MsgBox("Running")
    foundMatches = 0
    paused = 0
    
    'Gather list of programs to watch for from config file
    file = "config.ini"
    contents = readFile(file)
    itemQuantity = UBound(contents)
    
    Do While (paused <> 3)
        foundMatches = countMatchRunning(itemQuantity,contents)
        'WScript.Echo ("Matches:" & foundMatches & "  Paused:" & paused)
                
        'If FAH was unpaused because no game was running, but a game is now RUNNING:
        If (paused = 0) And (foundMatches > 0) Then
            'MsgBox("Found " & foundMatches & " match(es). Stopping FAH.")
            'Sleep for just a moment to try and avoid conflict with opening window.
            'WScript.Sleep 500
            controlFAH("pause")
            'WScript.Echo ("Pausing")
            paused = 1
        End If
        
        'If FAH was paused because a game was running, but the game is now GONE:
        If (paused = 1) And (foundMatches = 0) Then
            controlFAH("unpause")
            'WScript.Echo ("Unpausing")
            paused = 0
        End If
        'Sleep until next check
        WScript.Sleep(1000)
    lOOP
    
End Function

main()




'Every 1 seconds, Get all running processes
'Compare this list against the ini file
'If any number of matches is found, pause FAH
'If no matches are found, unpause FAH

Any tips would be appreciated!
(I can't seem to avoid a small window of time where user interaction breaks it by changing what window is in focus.
Even when I have the script intentionally pull focus directly before it sends each command... gah!)

If anyone wants to use it, let me know, I can post a download link or tailor it to the processes you want.
I'll get around to making it look at a config file in a bit.
[Image: sigimage.php?w=2943722&p=81403693&u=6423...&b=pinkie1]
[Image: sigimage.php?e=ruthalas&b=pinkie1]
Reply
Likes: SilverComet
#2
My PC was once one of the best in town... but now most of its parts are from the last decade, so I really appreciate this method to minimize the micromanaging of the CPU/GPU workload.
[I never used PuTTY; if there is a proper way to configure it, please leave a link to a guide].

I want this script for the processes "torch.exe" and "TorchCrashHandler.exe" (both parts of my Youtube/Internet Browser); and "waterfox.exe" (my backup browser for some badly implemented dynamical webpages).

[My default its actually a modless Opera (chromium), since I needed something light on CPU for the F@H webcontrol; I want both running at the same time, in case I need a casual webmail check or simple google/wiki searchs].
[Image: sigimage.php?u=657718&t=212997&b=luna2]
Reply
Likes:
#3
(2015-02-12, 04:30:53 AM)SilverComet Wrote: My PC was once one of the best in town... but now most of its parts are from the last decade, so I really appreciate this method to minimize the micromanaging of the CPU/GPU workload.
[I never used PuTTY; if there is a proper way to configure it, please leave a link to a guide].

I want this script for the processes "torch.exe" and "TorchCrashHandler.exe" (both parts of my Youtube/Internet Browser); and "waterfox.exe" (my backup browser for some badly implemented dynamical webpages).

[My default its actually a modless Opera (chromium), since I needed something light on CPU for the F@H webcontrol; I want both running at the same time, in case I need a casual webmail check or simple google/wiki searchs].

Ok! Try this on for size: File Download

Simply unzip to a convenient location and double click the one that says 'RUN ME'.
(Feel free to look at the script if you like, it's commented fairly well.)

The config file can be opened with any text editor to add more executable files to your watchlist! (Just finished that handy feature.)
Your requested executables are in there already.

As long as the config file and the puTTY file are in the same folder as the script, you should only need to run the script- no configuring at all!
It'll let you know it is running and then it is silent.

If you want to turn it off, terminate process 'wscript.exe'
I know that isn't elegant, but I haven't figured out a better method. Twilightblush
[Image: sigimage.php?w=2943722&p=81403693&u=6423...&b=pinkie1]
[Image: sigimage.php?e=ruthalas&b=pinkie1]
Reply
Likes: SilverComet
#4
Global hotkeys, perhaps? Or have something in the systray with options?
[Image: sigimage.php?FAHUser=hiigaran&FAHTeam=21...hangeling1]
Reply
Likes:
#5
Global hotkeys is the only option I have as far as I can tell.
Documentation is a bit sparse on this, to dissuade keyloggers I think. I'll keep looking.

I can't seem to create sys tray icons with VBS without sacrificing foals to the Elder Ponies. Facehoof
[Image: sigimage.php?w=2943722&p=81403693&u=6423...&b=pinkie1]
[Image: sigimage.php?e=ruthalas&b=pinkie1]
Reply
Likes:
#6
(2015-02-12, 05:36:16 AM)Ruthalas Wrote: If you want to turn it off, terminate process 'wscript.exe'
I know that isn't elegant, but I haven't figured out a better method. Twilightblush
perhaps you could have a button somewhere on the screen that will stop it

Also I'm not dead.
~Spy Pengen
[Image: sigimage.php?u=661255&t=212997&b=rainbowdash2]

CPU power!
Reply
Likes: Ruthalas
#7
(2015-02-12, 08:01:33 AM)Ruthalas Wrote: I can't seem to create sys tray icons with VBS without sacrificing foals to the Elder Ponies. Facehoof

But you can always make more foals, right? Pinkiecrazy
Reply
Likes: SXRXE




SOON