Whenever I access windows shares from OSX 10.5 it leaves .DS_Store files on the remote filesystem. What are they used for, and are they necessary, and can they be prevented from being created?
The ".DS_Store" files are used by the Mac OS Finder to store info about Finder window settings for a folder. They will appear in each folder that you visit (browse to) with the Finder. You normally do not see these files in Finder (they are "hidden", like any *NIX alike dot files)
To prevent the creation of these files, open the Terminal and type:
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
These files are used by Finder to save the positions of icons, the size of the respective Finder window, the window's background, and other view options.
An alternative method to disabling .DS_Store files if you don't have control over the Macs accessing the Windows shares is to disable the ability for these files to even be stored on the share. (Using the veto_files option in smb.conf or File Screen Management on Windows - thankfully it's disabled by default on 10.5+ clients)
You may want to check out another question: File shares for Mac users here on SF for some other associated pointers.
Spotlight also uses the info in the .DS_Store for indexing.
As many others have said, these are used by Finder. However if you don't like them you can safely delete them.