C# で imdisk を介して RAM ディレクトリを作成しようとしています。cmd コマンドは次のようなものなので、imdisk -a -s 512M -m X: -p "/fs:ntfs /q /y"
C# で cmd コマンドを処理する方法を調べたところ、ProcessStartInfo() に関するいくつかのヒントが見つかりました。このクラスは、ほぼ意図したとおりに機能しますが、imdisk には管理者権限が必要なため、ちょっと行き詰まっています。コード ブロックは例外なく実行されますが、Windows エクスプローラーに新しいデバイスが表示されません。
try
{
string initializeDisk = "imdisk -a ";
string imdiskSize = "-s 1024M ";
string mountPoint = "-m "+ MountPoint + " ";
string formatHdd = "-p '/fs:ntfs /q /y' ";
SecureString password = new SecureString();
password.AppendChar('0');
password.AppendChar('8');
password.AppendChar('1');
password.AppendChar('5');
ProcessStartInfo procStartInfo = new ProcessStartInfo();
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.FileName = "cmd";
procStartInfo.Verb = "runas";
procStartInfo.UserName = "Admin";
procStartInfo.Password = password;
procStartInfo.Arguments = initializeDisk + imdiskSize + mountPoint + formatHdd;
Process.Start(procStartInfo);
catch (Exception objException)
{
Console.WriteLine(objException);
}
誰かが私にちょっとしたヒントをくれるといいのですが、今はアイデアがありません。