We report electrochemical and in-situ scanning tunneling microscopy (STM) studies of surface processes on graphite and Au(111) electrodes in N-methyl-N-propylpyrrolidinium bis(fluorosulfonyl)imide (Py13FSI) and N-methyl-N-propylpiperidinium bis(trifluoromethanesulfonyl)imide (Py13TFSI) ionic liquids in the absence and presence of LiTFSI salt. In both of neat ionic liquids, the intercalation of cations and exfoliation of HOPG layers occur during cathodic excursion. However, the surface decomposition of FSI anions can form an effective protection film on the surface, which suppresses the intercalation and exfoliation processes, while the surface decomposition of TFSI anions mainly causes etching of the surface, which makes the intercalation and exfoliation easier to proceed. The addition of Li salt can promote the formation of the protective film, especially in Py13FSI, and thus significantly suppress the intercalation and exfoliation processes. The discrepancies between these two ionic liquids are caused by the different anion interactions with graphite. Additionally, comparisons of the behaviors on HOPG and on Au(111) confirm that the surface processes are crucially dependent on the nature of the electrode. Trace amounts of oxygen and water can cause the formation of a film-like structure on Au(111), but show no apparent influence on HOPG.