I had to replace the plastic rails on my sunroof. Thought I'd record it here in answer to your question should anyone else run into this issue. They were cracked at the rear and front nut receivers same as yours. I was going to just ride with it until I bumped the rear one putting the glass in and it broke off

So I had to replace that one with a plastic rail from another set. I removed the cable housing cover and loosened the keeper plate (front screw is out, rear is loose) to let the cover out and rail rise/fall. I bumped the switch aft and removed the keeper plate then let the rail rise so I could work with it. At this point I've been in here a dozen times so it goes pretty quickly with experience.
To answer your other question I dropped the check panel cover and motor housing then slid the whole cable/rail assemblies out and replaced them with the ones that came with the moonroof. I thoroughly cleaned the rails, cables with mineral spirits brush/rags and the housings with spray sovent WD40. Some solvent stays in the cable housing because there's a low point in the tubes ahead of the motor. I greased the business end of the cables then slid them in, preset them to the roof and reinstalled the motor. In a few years maybe I'll be able to say if there's a problem with that approach, but it works for now. The aft end of the cables were caked with gooey dirt and old lubricant so getting them clean was important. I left all of those dry - no graphite or anything else. I will say that I swapped over the smaller early model forward glides to the rails I kept in the car, they seemed to work better than the larger late model guides that came on the moonroof. I had to modify the cable covers as noted in jbort's write up.
Back to the plastic rail swap:

I found that the guide pin in the plastic rail has a mushroom tip on it and will come out of the rail using a fork-handle staple or clip remover. You can slide a pick through the small hole through the rail at the foreend of that guide to give it a start. A drop of 3 in One oil didn't hurt. Clean the new rail prior to install. These also had small cracks in them at the same place so I applied crazy glue to fill those. I think that's why we aren't supposed to overtighten them and the BMW techs use some thread locker on them. Maybe once it is time to secure the moonroof after the headliner install I'll back them out one at a time and apply thread locker. Again, this rail was already in place so I just bumped the position until it would clear the opening where I loosened keeper plate (it will work for one that's fully installed), inserted pick through the rail to give it a push then pried it loose with the staple remover, it unsnapped simply. Position the new one at the same foreend of the rail guide and pressed it in with large locking-jaw pliers. I repositioned it, secured the keeper plate and modified cable cover.

That is better. Now, DO NOT LEAN ON IT!

With the rail replaced and cover plates reinstalled, I was able to reposition the moonroof and install the trim (it worked this time after modifying the cable covers

Time to test drive.