こんにちは私は.NETアプリケーションを介してWindowsサービスを開始/停止/無効にしようとしていますが、動作するために以下のコードを取得するようですが、エラー4エラーC2065: 'ServiceController':宣言されていない識別子Managed C++のServiceController? (.NET)
これに関する正しい参考情報は何ですか?私は、システムに正しいものを見つけるように見えるカント::
String ^servicename = "srservice";
// Stop the service if it's started.
ServiceController^ controller = new ServiceController(servicename);
if (controller.Status == ServiceControllerStatus.Running)
controller.Stop();
// Set the startup type of the service.
String^ serviceregistrylocation = String::Format("SYSTEM\CurrentControlSet\Services\{0}", servicename);
RegistryKey ^localMachine = Registry::LocalMachine;
RegistryKey servicekey = localMachine.OpenSubKey(serviceregistrylocation, true);
// Set value to 2 for automatic, 3 for manual, or 4 for disabled.
servicekey.SetValue("Start", 3);
[OK]をので、私は、コードを修正し、それが今
String ^servicename = "Fax";
// Stop the service if it's started.
ServiceController^ controller = gcnew ServiceController(servicename);
if (controller->Status == ServiceControllerStatus::Running)
controller->Stop();
// Set the startup type of the service.
String^ serviceregistrylocation = String::Format("SYSTEM\CurrentControlSet\Services\{0}", servicename);
RegistryKey ^localMachine = Registry::LocalMachine;
RegistryKey ^servicekey = localMachine->OpenSubKey(serviceregistrylocation, true);
// Set value to 2 for automatic, 3 for manual, or 4 for disabled.
try{
servicekey->SetValue("Start", 4);
}
catch (Exception^ e)
{
MessageBox::Show(e->Message);
}
}
をコンパイルしますが、「オブジェクト参照オブジェクトのインスタンスに設定されていません」というエラーがスローされます
厥だけで問題を、私はシステム:: ServiceProcess :: ServiceControllerのを持っていない、それは、そうですSystem :: serviceProcessは表示されません。 – cox
NVM、参照を追加していない、うまくいくようです、ありがとう! – cox
Hmm今、次のようなエラーが表示されます。エラーエラーC3673: 'Microsoft :: Win32 :: RegistryKey':クラスにコピーコンストラクタがありません – cox