1
我目前正試圖實現一個服務,該服務運行一個特殊的命令,通過參數傳遞一些東西,例如:文件路徑。我使用的是cmd
命令:帶參數的C#服務onCustomCommand?
sc control "ServiceName" 128
但是,該命令不爲我輸入參數提供任何方法。該方法如下:
protected override void OnCustomCommand(int command)
{
switch(command)
{
case 128:
Command.StartProcess(3);
LogWriter.WriteLog("Next output: ");
Command.StartProcess(4);
break;
case 129:
// input extension, output extension, key id , working path
try
{
test t1 = new test();
t1.readLog(@"C:\Users\Joe\Desktop\success.txt");
LogWriter.WriteLog(t1.input);
LogWriter.WriteLog(t1.output);
}
catch(Exception e)
{
LogWriter.WriteLog(e.ToString());
}
finally { LogWriter.WriteLog("abc"); }
//LogWriter.WriteLog(t1.output + "def");
break;
}
}
我可以輸入的唯一參數是所述int
command
的方法。我想爲輸入folder path
。在上面的代碼中,我必須對不靈活和麻煩的路徑進行硬編碼。那麼,無論如何要解決這個問題嗎?