相关疑难解决方法(0)

如何判断是否有控制台

我有一些控制台和wpf应用程序使用的库代码.在库代码中,有一些Console.Read()调用.如果应用程序是一个控制台应用程序,我只想做那些输入读取,如果它是一个GUI应用程序 - 如何在dll中告诉应用程序是否有控制台?

c# console

19
推荐指数
5
解决办法
2万
查看次数

使用InstallUtil安装具有启动参数的Windows服务

我使用InstallUtil来安装我的服务,我只是无法弄清楚如何为它指定启动参数!

这是我的Installer子类:

[RunInstaller(true)]
public class ServerHostInstaller : Installer
{
  private ServiceInstaller m_serviceInstaller;
  private ServiceProcessInstaller m_serviceProcessInstaller;
  private static string s_usage = "Usage:\ninstallutil /i /username=<user_name> /password=<user_password> NCStub.Server.Host.exe";

  public ServerHostInstaller()
  {
    m_serviceInstaller = new ServiceInstaller();
    m_serviceInstaller.ServiceName = Program.ServiceName;
    m_serviceInstaller.DisplayName = Program.ServiceName;
    m_serviceInstaller.StartType = ServiceStartMode.Automatic;

    m_serviceProcessInstaller = new ServiceProcessInstaller();
    m_serviceProcessInstaller.Account = ServiceAccount.User;

    Installers.Add(m_serviceInstaller);
    Installers.Add(m_serviceProcessInstaller);
  }

  public override void Install(IDictionary stateSaver)
  {
    base.Install(stateSaver);

    string userName = this.Context.Parameters["username"];
    if (userName == null)
    {
      Console.WriteLine(s_usage);
      throw new InstallException("Missing parameter 'username'");
    }

    string userPass = this.Context.Parameters["password"];
    if (userPass …
Run Code Online (Sandbox Code Playgroud)

.net c# windows-services installutil

14
推荐指数
1
解决办法
2万
查看次数

从控制台C#上的位置读取

我需要从控制台中的特定位置读取文本,例如5,5.

如果我需要写到这个位置,它只会是:

Console.SetCursorPosition(5, 5);
Console.Write("My text");
Run Code Online (Sandbox Code Playgroud)

有什么方法可以用类似的方式阅读吗?

只是为了澄清:我不想停止接受用户的输入,即使输入不是来自用户,也不是先前打印出来的东西.我真的想要某种:Console.GetCharAtLocation(5,5)或类似的东西.

c# console

13
推荐指数
3
解决办法
6575
查看次数

标签 统计

c# ×3

console ×2

.net ×1

installutil ×1

windows-services ×1