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.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FsaysDriveMounter
{
public partial class FSaysDriveMountService : ServiceBase
{
public FSaysDriveMountService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("diskpart", "/s c:\\scripts\\diskpart.txt");
Process.Start(procStartInfo);
Thread thread = new Thread(AutoStopService);
thread.Start();
}
protected override void OnStop()
{
}
private void AutoStopService()
{
Thread.Sleep(60000);
this.Stop();
}
}
}
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'.
That's all.