What?
Introducing a new over-the-top way of restarting your Folding@Home clients. Restart-Fah.
This is a simple [bloody 6 hours simple!
] Windows PowerShell script for restarting any Folding@Home client you set. What's more, the script also supports changing your machineid setting if set the appropriate -IncrementId option. The script fully supports [probably] the client.cfg format [despite appearences it is a binary file, not plain text]. Meaning your client wont throw a wobbly over the edited settings file and reset it to defaults.
Why?
Just lately I have been having a bit of a headache with my Folding@Home clients. First it was my GPU clients, then my SMP clients started giving me grief with Stanford's current lack of Work Units. Restarting the client is not always enough to get work. Changing the machineid for that client has been shown to work on occassion. It takes no effort on your part with Restart-Fah, so why not at least try?
As stated this a Windows PowerShell script [sorry penguin people!1]. It was written in PowerShell V2.0 [Preinstalled on Windows 7] but it should work in PowerShell V1.0 [Vista]. V2.0 is available for all versions of Windows from XP onwards via the Windows Management Framework .
I opted for PowerShell as it an environment I am very interested in for managing Windows Domains. Everything from Domain Controllers to lowly workstations can be managed easily, remotely and in bulk! As a means of getting to grips with it, I thought I would solve some issues I was having with my own machines - namely folding clients!
This script is a smaller part of a bigger project I am working on - FaHCMS. FahCMS - or Folding@Home Client Monitoring Script [catchy, I know!] - will monitor all clients on your machine and restart them when they stall or are accidently shutdown. I don't want to say too much about FaHCMS at this point as I am still experimenting [already accidently lost a WU
]. Suffice to say if it comes to fruition, you can [read: maybe] leave your Windows-based Folding@Home clients alone safe in the knowledge FaHCMS is taking care of it. Watch this space!
How?
The Restart-Fah script itself is relatively quite simple, if not a little rough around the edges! You run the script, with or without the -IncrementId option, and it goes away and restarts your Folding@Home client.
You can grab the script here, if you haven't already!
Restart-Fah
Enough waffle, time for the cheese. Or something...
NB: You will need to open the script in something like notepad and edit lines 2 and 3 to suit your client. Details in the Known Issues section below.
From within a PowerShell Console window [Run > powershell.exe] altering any paths as necessary.
And that's it! The script will run, and after a little over 10 seconds your client will have restarted. Want to change your machineid? No problem...
Done. 
The 10 second delay is entirely artificial. The processes usually end within a
second or two, but the delay just ensures they aren't lingering before trying to restart the client.
At this point it only supports one client, but there is no reason why you can't have several copies of the script set with a different F@H client directory. It does not matter where you run the script from, as the code ensures the client's working directory is correct. Also, you cannot run the script directly by double-clicking the file in Windows Explorer. This is a deliberate feature of PowerShell.
Administrative rights are not required to run restart-fah. This has been tested on Windows 7 and SBS 2008. Feedback on Vista and XP would be great if anyone has the inclination to try!
Other running methods
What's that, you don't want to have to open the PowerShell console to run the script? Not a problem. You can either create a shortcut that points to powershell.exe "C:\scripts\restart-fah". If you wish to use the -IncrementId option, use powershell.exe "C:\scripts\restart-fah -IncrementId" instead.
Alternatively, you could run it from a CMD prompt [or put the command in a Batch script!]:
Creating a shortcut or a batch script will allow you to run the script by double-clicking something!
Known Issues
This script is only version 0.6 and as such is entirely capable of going horribly wrong! Nah it wont. Honest, guv!
1: It doesn't do anything clever to work out where your client is located. So you will have to open the script file in Notepad or similar and edit lines 2 and 3 [marked by comments].
Line 2 asks for the full path to the client directory [with no trailing backslash].
Line 3 asks for the name of your client.exe. In my case it is fah6.exe.
2: If you have more than one client on your machine, running the script with the -IncrementId option is entirely NOT recommended. Restart-Fah does not keep track of all machineid's in use so a conflict is highly likely.
3: The script is a little bit too trusting and assumes all processes in the client_directory path are folding processes that must be stopped. Needless to say horrible things may happen if you choose a directory such as System32 and ran the script!
. This is the first thing I plan to remedy, so fear not those of a nervous disposition. UPDATE: I have corrected this massive potential disaster. The script will only kill the client.exe and fahcore* processes. So even if you [accidentally/deliberately] set the wrong directory, it won’t end all life as we know it.
4: There is almost no error capture or correction in the script, so if anything goes wrong it will bomb out in a spectacular manner. Actually it won’t, at worse you get some nasty red writing. Something I will work on if the script gains any ground here.
UPDATE: I added some error capture for the client path settings. The script should stop with an error if any of the paths cannot be resolved.
5: For those interested in how the script works, my code is a tad messy and might not be entirely efficient. It is very much a work in progress, so bear that in mind. All suggestions for improvement are welcome.
6: You tell me!
Troubleshooting
There isn't really a lot to go wrong with this script, but I will update this as and when issues arise. I will however get the ball rolling with an issue almost everyone will run into.
So you try to run Restart-Fah, either in the PowerShell console or via a batch script and you get the following error:
File C:\Scripts\restart-fah.ps1 cannot be loaded because the execution of scrip
ts is disabled on this system. Please see "get-help about_signing" for more det
ails.
At line:1 char:27
+ C:\Scripts\restart-fah.ps1 <<<<
+ CategoryInfo : NotSpecified:
) [], PSSecurityException
+ FullyQualifiedErrorId : RuntimeException
Uh oh!
This is due to the default policy of PowerShell not allowing any scripts to run. This can be changed very simply via a PoSH console. Run a new PowerShell window as and Administrator, and at the prompt type
You will be met with a confirmation. Choose Y and hit Enter. All done! This setting allows all locally created scripts to run, but not those you have downloaded. So you may wish to copy the contents of Restart-Fah to a file you have created locally, otherwise powershell wont run it [as it is not signed]. You could also use "Unrestricted" instead of RemoteSigned, this will allow any script to run. The choice is yours. As always you do these things entirely at your own risk! 

Another issue you may run into is running the script from within PowerShell when the file path contains spaces.
I would also like to point out that PowerShell is entirely case-insensitive.
1. I created a bash script for Linux a few years ago that periodically checked the CPU load and restarted the SMP client if it was idle. I created it when my SMP client at the time would sometimes hang/stall between WUs. You can find the script here. I used this script for a long time without any issue.
I do not know if it is still fully functional, but if anyone is interested I can always tweak it if necessary. The rar contains the script and some documentation, including how to set up a cronjob for the script.
Introducing a new over-the-top way of restarting your Folding@Home clients. Restart-Fah.
This is a simple [bloody 6 hours simple!

Why?
Just lately I have been having a bit of a headache with my Folding@Home clients. First it was my GPU clients, then my SMP clients started giving me grief with Stanford's current lack of Work Units. Restarting the client is not always enough to get work. Changing the machineid for that client has been shown to work on occassion. It takes no effort on your part with Restart-Fah, so why not at least try?

As stated this a Windows PowerShell script [sorry penguin people!1]. It was written in PowerShell V2.0 [Preinstalled on Windows 7] but it should work in PowerShell V1.0 [Vista]. V2.0 is available for all versions of Windows from XP onwards via the Windows Management Framework .
I opted for PowerShell as it an environment I am very interested in for managing Windows Domains. Everything from Domain Controllers to lowly workstations can be managed easily, remotely and in bulk! As a means of getting to grips with it, I thought I would solve some issues I was having with my own machines - namely folding clients!
This script is a smaller part of a bigger project I am working on - FaHCMS. FahCMS - or Folding@Home Client Monitoring Script [catchy, I know!] - will monitor all clients on your machine and restart them when they stall or are accidently shutdown. I don't want to say too much about FaHCMS at this point as I am still experimenting [already accidently lost a WU

How?
The Restart-Fah script itself is relatively quite simple, if not a little rough around the edges! You run the script, with or without the -IncrementId option, and it goes away and restarts your Folding@Home client.
You can grab the script here, if you haven't already!

Enough waffle, time for the cheese. Or something...
NB: You will need to open the script in something like notepad and edit lines 2 and 3 to suit your client. Details in the Known Issues section below.
From within a PowerShell Console window [Run > powershell.exe] altering any paths as necessary.
Code:
c:\scripts\restart-fah.ps1
Code:
c:\scripts\restart-fah -IncrementId

The 10 second delay is entirely artificial. The processes usually end within a
second or two, but the delay just ensures they aren't lingering before trying to restart the client.
At this point it only supports one client, but there is no reason why you can't have several copies of the script set with a different F@H client directory. It does not matter where you run the script from, as the code ensures the client's working directory is correct. Also, you cannot run the script directly by double-clicking the file in Windows Explorer. This is a deliberate feature of PowerShell.
Administrative rights are not required to run restart-fah. This has been tested on Windows 7 and SBS 2008. Feedback on Vista and XP would be great if anyone has the inclination to try!

Other running methods
What's that, you don't want to have to open the PowerShell console to run the script? Not a problem. You can either create a shortcut that points to powershell.exe "C:\scripts\restart-fah". If you wish to use the -IncrementId option, use powershell.exe "C:\scripts\restart-fah -IncrementId" instead.
Alternatively, you could run it from a CMD prompt [or put the command in a Batch script!]:
Code:
powershell.exe "C:\scripts\restart-fah"
powershell.exe "C:\scripts\restart-fah -IncrementId"
Known Issues
This script is only version 0.6 and as such is entirely capable of going horribly wrong! Nah it wont. Honest, guv!
1: It doesn't do anything clever to work out where your client is located. So you will have to open the script file in Notepad or similar and edit lines 2 and 3 [marked by comments].
Line 2 asks for the full path to the client directory [with no trailing backslash].
Line 3 asks for the name of your client.exe. In my case it is fah6.exe.
2: If you have more than one client on your machine, running the script with the -IncrementId option is entirely NOT recommended. Restart-Fah does not keep track of all machineid's in use so a conflict is highly likely.
3: The script is a little bit too trusting and assumes all processes in the client_directory path are folding processes that must be stopped. Needless to say horrible things may happen if you choose a directory such as System32 and ran the script!

4: There is almost no error capture or correction in the script, so if anything goes wrong it will bomb out in a spectacular manner. Actually it won’t, at worse you get some nasty red writing. Something I will work on if the script gains any ground here.

5: For those interested in how the script works, my code is a tad messy and might not be entirely efficient. It is very much a work in progress, so bear that in mind. All suggestions for improvement are welcome.
6: You tell me!

Troubleshooting
There isn't really a lot to go wrong with this script, but I will update this as and when issues arise. I will however get the ball rolling with an issue almost everyone will run into.
So you try to run Restart-Fah, either in the PowerShell console or via a batch script and you get the following error:
File C:\Scripts\restart-fah.ps1 cannot be loaded because the execution of scrip
ts is disabled on this system. Please see "get-help about_signing" for more det
ails.
At line:1 char:27
+ C:\Scripts\restart-fah.ps1 <<<<
+ CategoryInfo : NotSpecified:

+ FullyQualifiedErrorId : RuntimeException
Uh oh!

This is due to the default policy of PowerShell not allowing any scripts to run. This can be changed very simply via a PoSH console. Run a new PowerShell window as and Administrator, and at the prompt type
Code:
Set-ExecutionPolicy -ExecutionPolicy "RemoteSigned"


Another issue you may run into is running the script from within PowerShell when the file path contains spaces.
Code:
#this will generate an error due to the spaces
C:\my folder with spaces\scripts\restart-fah.ps1
#this will just echo the path back to the console
"C:\my folder with spaces\scripts\restart-fah.ps1
#Use this method!
& "C:\my folder with spaces\scripts\restart-fah.ps1
Code:
#these will all work
Restart-Fah.ps1
RESTART-FAH.PS1
restart-fah -incrementid
#and so on
I do not know if it is still fully functional, but if anyone is interested I can always tweak it if necessary. The rar contains the script and some documentation, including how to set up a cronjob for the script.
Last edited: