You can prevent a pinworm infection by practicing good hygiene. It is especially important to shower in the morning because pinworms lay their eggs at night. A shower works better at preventing a pinworm infection than a bath.