For a good context for this post please see ‘The Theological Advantages of Molinism’ for a list of relevant discussions on middle knowledge and Molinism.
The second moment to God’s knowledge is His knowledge of the contingent states of affairs that would be produced by an antecedent state of affairs were it to be obtained. Counterfactuals are conditional statements in the subjunctive mood. That is to say, God knows what any free creature would do. This is not because the circumstances causally determine the creature’s choice, but simply because this is how the creature would freely choose. God thus knows that were He to actualize certain states of affairs, then certain other contingent states of affairs would obtain. Middle knowledge does not depend on any decision of divine will; God does not determine what counterfactuals of creaturely freedom are true or false. Thus, if it is true that:
If some agent S were placed in circumstances C, then he would freely perform action a,
then even God in His omnipotence cannot bring it about that S would refrain from a if he were placed in C. WL Craig expands on the subject:
For although it is logically possible that God actualize any possible world (assuming that God exists in every possible world), it does not follow there from that it is feasible for God to actualize any possible world. For God’s ability to actualize worlds containing free creatures will be limited by which counterfactuals of creaturely freedom are true in the moment logically prior to the divine decree. In a world containing free creatures, God can strongly actualize only certain segments or states of affairs in that world, and the remainder He must weakly actualize, using His middle knowledge of what free creatures would do under any circumstances. Hence, there will be an infinite number of possible worlds known to God by His natural knowledge, which are not realizable by Him because the counterfactuals of creaturely freedom, which must be true in order for Him to weakly actualize such worlds, are in fact false. His middle knowledge serves to delimit, so to speak, the range of logically possible worlds to those, which are feasible for Him to actualize. This might be thought to impugn divine omnipotence, but in fact such a restriction poses no non-logical limit to God’s power.
God does not receive His knowledge from the actual world. Human decisions do not fashion or determine God’s middle knowledge; His middle knowledge is derived from His natural knowledge. Molina denies that God’s perfection or necessity is dependent upon His middle knowledge, so that if God chose not to create anything then His middle knowledge would not have usurped His perfection.
God does not get His knowledge from things, but knows all things in Himself and from Himself; therefore, the existence of things, whether in time or eternity, contributes nothing to God’s knowing with certainty what is going to be or not to be… For prior to any existence on the part of the objects, God has within Himself the means whereby He knows all things fully and perfectly; and this is why the existence of created things contributes no perfection to the cognition He has of them and does not cause any change in that cognition… [And] God does not need the existence of those things in His eternity in order to know them with certainty.
God does not, say, sit back and watch the course of human history, and then fashion His intentions accordingly. God still has absolute intention, and middle knowledge maintains absolute intention while still affirming creaturely freedom. For example, it is God’s absolute intention that no creature should sin and that all reach beatitude. But it is not within God’s power to control what free creatures would do in any set of circumstances. In specific circumstances, free creatures would freely sin—even though God does not will it to happen. If God chooses to actualize these specific circumstances then His absolute intentions are constrained and frustrated to allow the creature to sin. But God’s conditional intentions, via middle knowledge and the truth behind counterfactuals, can allow Him to take account of what free creatures would do, and thus cannot be frustrated.
 William Lane Craig, “‘No Other Name’: A Middle Knowledge Perspective on the Exclusivity of Salvation Through Christ,” Faith and Philosophy 6:2 (April, 1989), 172–88.
 See Thomas P. Flint, “The Problem of Divine Freedom,” American Philosophical Quarterly 20 (1983): 257. According to Flint, although all worlds are possible for God to actualize, a world is feasible for God to actualize if and only if it is a member of that proper subset of all possible worlds determined by the counterfactuals of creaturely freedom, which God knows to be true.
 See Thomas P. Flint and Alfred J. Freddoso, “Maximal Power,” in The Existence and Nature of God, ed. Alfred J. Freddoso (Notre Dame, Ind.: University of Notre Dame Press, 1983), pp. 93-98. Craig, “No Other Name”.
 Molina, On Divine Foreknowledge, 4.49.12, 11.
 Craig, “No Other Name.”