When I bought my new pc and installed windows 8 on it. I ran into the following problem: every cold start resulted in a missing hard disk. When I went to "Computer => Manage => Disk Management" the drive and the specific partitions were there. So with "Assign drive letter" I could remap things. But this was I annoying task and hard to explain (by the phone) to my girl-friend and my children. So I first searched online for solutions for these symptoms but none was solving the problem: power shell scripts, start-up folders, etc.
That's when I decided to write my own windows service that deals with the problem.
The service is quite simple.
- Start a proces called 'diskpart' with the right command line options.
- Wait 1 minute.
- Stop the service. Hence the name single shot service.
public partial class FSaysDriveMountService : ServiceBase
protected override void OnStart(string args)
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("diskpart", "/s c:\\scripts\\diskpart.txt");
Thread thread = new Thread(AutoStopService);
protected override void OnStop()
private void AutoStopService()
The commands for 'diskpart' are stored in c:\scripts\diskpart.txt For my machine, the required commands are:
Additionally I changed the security settings such that only admins can change the content of the diskpart.txt file.
All other users only have 'read'-rights.
The most important thing was to store the service on the disk that is accessible all the time. So not on my missing 'E-drive'.