Automatically clean up/kill Orphaned Processes

A nice easy way to patrol and eliminate orphaned processes 

I have several web applications on our local intranet that require Excel to be called to make documents for my users.  That brings up a problem:If you add the impatient tendancies of users (hey, I just clicked that button, I want my spreadsheet NOW!) to the statelessness of html on top of the stubornnessof the Excel process you get orphans, those pesky orphans that sit around, use your resources and do nothing.  Now programatically, I have done all I can to kill these bastards but I can't seem to stop the persistant jerks 100% of the time.


So, what I decided to do was to make an 'enforcer' on the web server that makes his rounds every five minutes and kills any of these little pricks that are still hanging out in my otherwise peaceful system.  This enforcer is not only effective, he is also efficient (tiny script, executes instantly) and keeps track of his work (log file).


The code for my vbs file can be seen here:



Option Explicit
Dim objWMIService, objProcess, colProcess, intCount
Dim strComputer, strProcessKill, logPath
strComputer = "."
strProcessKill = "'EXCEL.EXE'" 'process to kill
logPath = "C:\scripts\killExcel.log" 'path to log file
intCount = 0

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
intCount = intCount + 1

If intCount > 0 Then
    Dim fso, txtFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txtFile = fso.OpenTextFile(logPath, 8)
    txtFile.WriteLine(Date & " - " & Time & " Killed " _
    & intCount & " processe(s)")
End If




As you can see, it's very simple, and you can change it to eliminate any kind of process you want.  Here it is if you want to check it out, included is an empty log file, the vbs file, and the bat file used to schedule it (assuming you place this in c:\scripts\), enjoy.



Un-compressed automated backups

Sometimes you want an uncompressed backup...

I have run into many automated backup solutions, but they all seem to want to compress my data.  A particular intranet site we have has data that I regularly need to access the backups of, and it is a pain to use backup software or compression day after day.  To fix this, I came up with a script/batch file to do the work for me.  I set it to run on a schedule and I get backups in tidy date-named folders every day with automated cleanup after a specified amount of days.  It is pretty simple and straight-forward.  Uses RoboCopy for the backups (included in the zip).  Usage is as such: 

cscript backup.wsf
The only things that are required are to and from.  I put up a walkthrough of setting up batch files and scheduling for a different process here if you need a refresher.

Quickly add and attach multiple content databases to a MOSS 2007 install

A detailed tutorial on how to use some borrowed/modified scripts for making this task very simple

These scripts were stolen from and have been modified just a little to get some different functionality, I want them to take 95% of the credit... the rest is MINE!  (Thanks guys!)


These scripts were almost exactly what we needed, but we needed each content database to have custom names.  So I twisted the code around a bit and here is a detailed tutorial of what we did. 

**IMPORTANT - do this ONLY after you have made your initial web application.


Make the Databases

  1. Make a new database named temp_db_builder
  2. Make a table in temp_db_builder with this:
    CREATE TABLE create_dbs(
    db_name VARCHAR(MAX)
  3. Fill that table with the trailing end of your content db names- EX: WSS_Content_SomeSite : 'SomeSite' = trailing end
  4. Edit make_dbs.sql (from the zip below):
    1. Change @ServiceIdentity and @AppPoolIdentity to the proper accounts
    2. Change the X in WHILE @Number <= X to the number of entries you added in the create_dbs table
    3. Change @DataFile and @LogFile to the proper destinations
    4. That is all that is needed, change the other properties if your situation requires
  5. Run that file, or run the query text in SQL Server Management Studio
  6. Databases are made


Produce the Batch file:

  1. Edit the file make_db_batch_file.vbs (from the zip below):
    1. edit NUMBER_OF_DATABASES to the number of names you added in the create_dbs table above
    2. edit SQL_SERVER_NAME to your SQL Server
    3. for however many databases you specified in #1, add the names to dbArray(x) from 0 to NUMBER_OF_DATABASES - these HAVE TO match the names in the table create_dbs
    4. edit DBnameconv to what the prefix of the databases is
    5. edit SiteURL to your site url
  2. Copy that file to your Sharepoint Admin Server to C:\Add_ContentDB_Script\
  3. Go in to your command prompt and run cscript make_db_batch_file.vbs from the C:\Add_ContentDB_Script\
  4. Batch File is made


Attach Content Databases to Sharepoint

  1. On your Sharepoint admin server, run a command prompt as the Sharepoint admin account (runas /user:domain\username cmd)
  2. Navigate to C:\Add_ContentDB_Script\ and run AddDBAContentDB.bat


And you should be all done.

Automated Sharepoint Backups including daily folders and trash collection

SAMS came up with a great SharePoint backup automation tool with their SPSiteBackup.wsf windows script file - it is good, but needed a couple things... so I added them...

The SAMS backup utility is really pretty great.  It runs backups on all of your site collections on a given site as well as as logging the results and emailing the logs to users.  This is very useful, but it is lacking a few features that I felt it needed.


First of all, the backup utility put all of the backup files into one directory.  When you have a lot of sites, not to mention if you are backing up MySites, this can become a massive chunk of data.  If you are running this script on any recurring basis, it just turns into a non-decipherable mess of hundreds and hundreds of files, no organization whatosever.  I made a change here that will automatically make folders (named by date) and place the backups in the properly dated folder.


Second, there is no garbage collection.  If I ran the script every day, I would eventually choke out all of my storage and be stuck with 100s of GBs of backups.  I could just go in and delete them manually, but no one wants to do that (so 90s).  What if I forget, or go on vacation, or leave Tongue out - so, I made a garbage collection method run within the script as well.


All you need to do is place the script file directly on your C: drive, customize the batch file (explanation provided within the .bat file) and schedule it to run (or run it manually) and you are running maintenance-free automatic backups on your SharePoint server/farm.





Ok, if you feel ok on your own now, stop reading - if not, read on for a step-by-step tutorial on how to schedule the automated backups on your server...


Get the backup script files ready  

  1. Copy the 2 files from the .zip file to the machine you want to run backups on directly to the C: drive
  2. Open spBackup.bat in a text editor, you will see the following:
    cscript c:\spBackupScript.wsf
  3. Change the input variables to what you need them to be (self-explanatory) for that server instance.


Now that is set up, you need to schedule the job.

  1. Click Start->Programs->Accessories->System Tools->Scheduled Tasks
  2. Double-click Add Scheduled Task, choose Next
  3. Click Browse... and browse to the .bat file you just edited (C:/spBackup.bat)
  4. Name the task and choose how often to perform the task click Next
  5. Choose the start time click Next
  6. Enter your password click Next
  7. Click Finish


It's just that easy, you are now making and cleaning up backups automatically.  Here it is one more time: (3.60 kb)