The research on virus propagation process and control method in wireless sensor networks (WSNs) is one of the essential challenges of network security. This paper proposes a virus control mechanism of degree, betweenness centrality, and k-core-based analytical hierarchy process (DBC-AHP) for WSNs. According to the topology of WSNs, the virus control mechanism uses the DBC-AHP to identify the crucial nodes of the network. It uses the way of crucial nodes’ self-disconnection to suppress the spread of the virus, to improve the network security. In this paper, the effectiveness of the virus control mechanism based on the DBC-AHP is verified by comparing and analyzing the effect of four different crucial node recognition algorithms. With the research of virus control mechanisms in various network environments, it is found that the average degree of nodes, the communication radius of nodes, and the probability of virus infection can affect the inhibition effect of the virus control mechanism. Furthermore, the inhibition effect of virus control mechanisms is studied under the condition with/without MAC mechanism.