Next is a Trojan, as in Trojan Horse. A Trojan is a program designed to carry out some covert, undocumented or malicious act unknown to the user, by disguising itself as another program. Unlike viruses, Trojans do not replicate themselves. Lastly is a worm , which is a self-contained program that is able to spread copies of itself to other computer systems. Unlike viruses, worms do not attach themselves to a host program, but simply spread themselves throughout a given network or possibly the Internet.
Viruses work differently, depending on what type of virus they are.
A file infector virus can be either direct-action or resident. A direct-action virus selects one or more programs to infect each time a program infected by it executes. A resident virus installs itself somewhere in memory the first time an infected file is run and then attempts to infect other files when they are executed. A system or boot-record virus works by infecting the first sector of every DOS formatted disk. Generally a boot sector virus executes its own code, which infects the hard drive, and then continues the normal boot up process.