The decision by Charles XII to carry the war into Poland and Lithuania in order to force Augustus II to abdicate has for more than 300 years been regarded as one of his most controversial decisions. As far as we know most of his political advisors argued against it, either because they felt that it would be nearly impossible to achieve such a result or because they felt that negotiations with Polish representatives would make Augustus virtually incapable of interfering with a Swedish campaign against Russia. When Charles made this decision has also been debated by historians. Some have tended to think that it was made shortly after the battle of Narva, when it appeared that the Czar would be out of the game for some time. Others have suggested that it was made shortly after the crossing of the Daugava in July 1701, when it became clear that the Saxon army had been beaten but not destroyed. In more recent works (which in this case is the 1960's) it has been suggested that the Sapieha family and Prince Jakub Ludwik Sobieski played an important. According to this version of events it was appeals from the Prince and from the Sapieha's gave Charles the opportunity to send his forces into Lithuania and get involved in the civil war.
I believe it's fairly obvious that the Swedish goverment had been watching events in Poland and Lithuania very closely since the death of Jan Sobieski. While Charles XI was reluctant to act decisively for a certain candidate was clear who he and his advisors preferred - a native Pole. He would presumably be friendly towards Sweden and inclined to view Russia as a threat because of the major territorial losses suffered by the Commonwealth in 1667/1686. A French candidate was the least desirable, which in hindsight may seem a bit paradoxical as France was probably the country which could be of most value to the Swedish Empire. Indeed, this was something Charles XII eventually came to realize and one wonders what might have happened if he in 1701-1702 had been prepared to throw his support behind the Prince of Conti.
The Sapieha family became the first really influential ally to Charles and he would stick with them. In General Lewenhaupt's memoirs there is a description of an incident which took place during the General's visit to the Royal headquarters in the Spring of 1708. At that point Prince Michał Serwacy Wiśniowiecki (1680-1744) had switched sides and Lewenhaupt spoke, he writes, highly of the Prince and the assistance his forces had been given Lewenhaupt during the preceding months. The King, Lewenhaupt claims, got redder and redder in the face while the General made unfavorable remarks about the Sapiehas and their forces and finally said: "But We wish to support the Sapieha family!" This is amply corraborated by the instruction to Georg Wachschlager, the Swedish envoy to King Stanislaw, dated 31 May 1708. In paragraph 8 it says (roughly translated):
"As it is in the aforementioned treaty (Warsaw 1705 - ny note) it is assured that the Sapieha family will be reinstated in all its former honors and offices and receive compensation for all injuries and damages suffered through the actions of the opposing faction during this war, it is His Majesty's wish that the Envoy embraces the issues of concern to this family and in all possible ways supports and assists them when they so ask. He should do this in such a way that the Royal Court of Poland understands that it is very dear to the heart of the King of Sweden that the Sapieha family, which all the way back to the beginning of the war has shown a most laudable fidelity to its promises, is supported and protected against all oppression."
Source: Riksarkivet, Diplomatica, Polonica, vol. 311.