【问题标题】:How to disable Open file – Security warning如何禁用打开文件 - 安全警告
【发布时间】:2013-02-05 08:07:16
【问题描述】:

我有一个奇怪的问题。 我编写了一个 winform 服务器应用程序和一个 winform 客户端应用程序。 客户端的作用是向服务器发送运行某个脚本的命令。 服务器接收这些命令,解析它们,然后运行它们。

这两个效果很好。

我编写了一个 cmd 应用程序,它使用了我的客户端的一些功能。此应用程序应该用作 cmd 客户端。

问题是这样的:当我运行winform客户端时,服务器运行命令完全没有问题。 当我运行cmd客户端时,当服务器尝试执行接收到的命令时,服务器端的windows会弹出脚本是否可以运行的安全问题(见附图)。

为什么会发生在cmd而不是winforms上。

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Net.Sockets;
using System.ComponentModel;
using System.IO;
using System.Management;

namespace RemoteBatcher
{
    class ClientCmdProgram
    {
        private static RegistryKey registryKey;
        private static Socket clientSock;
        private static string remoteIpAddress = "192.168.0.1";
        private static int remotePort = 8;
        private static string userName = "";
        private static string targetPath = "Z:\\nBatcher\\";
        private static List<string> listOfCommands = new List<string>();

        static void Main(string[] args)
        {
            var backgroundWorker = new BackgroundWorker();
            userName = RemoteUtils.getConnectedUser();            
            registryKey = Registry.CurrentUser.OpenSubKey("Key");

            if (registryKey == null)
            {
                Console.WriteLine("Error! No Saved Data Was Found In The Registry. Please Run The RemoteBatcherClient App First.");
                Environment.Exit(1);
            }

            if (!connectToServer(backgroundWorker))
                Environment.Exit(1);

            getCommandsList();
            sendCommands(backgroundWorker);
        }
        private static bool connectToServer(BackgroundWorker backgroundWorker)
        {
            try
            {
                clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                clientSock.Connect(remoteIpAddress, remotePort);
                backgroundWorker.DoWork += (sender1, e1) => RemoteUtils.copyDllsToServer(targetPath += userName);
                backgroundWorker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return false;
            }

            return true;
        }
        private static void getCommandsList()
        {
            string[] commandsInRegistry = registryKey.GetValueNames();

            for (int i = 0; i < commandsInRegistry.Length; i++)
            {
                listOfCommands.Add(registryKey.GetValue(commandsInRegistry[i]).ToString());
            }
        }
        private static void sendCommands(BackgroundWorker backgroundWorker)
        {
            int flicker = 100;
            int counter = 100;
            try
            {

                while (backgroundWorker.IsBusy) 
                {
                    if (counter == flicker)
                    {
                        counter = 1;
                        Console.WriteLine("Copying Executable Files, Please Wait..");
                    }
                    else if (counter == 50)
                    {
                        Console.Clear();
                    }
                    else
                        counter++;
                }

                for (int i = 0; i < listOfCommands.Count; i++)
                {
                    clientSock.Send(Encoding.Default.GetBytes(listOfCommands[i] + " <eom> "));
                }
                clientSock.Close();
                clientSock.Dispose();
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                Environment.Exit(1);
            }

        }
    }
}

有什么想法吗?

【问题讨论】:

  • 让我猜猜...命令行程序的可执行文件在共享上,而winforms客户端的可执行文件在硬盘上?
  • 不,它在我的桌面上运行...
  • @ldanis 他们两个?你的桌面在你的硬盘上吗?
  • 是的,他们两个,我的桌面在我的硬盘上。我关注了@Yaqub Ahmad 的链接,现在它可以工作了/谢谢。

标签: c# winforms process client-server console-application


【解决方案1】:

How can i disable open file - security warning in windows xp ?

要禁用警告,请启动组策略编辑器(开始 > 运行,键入 -gpedit.msc- 并按 OK)并转到:

-用户配置 > 管理模板 > Windows 组件 > 附件管理器 - 然后将 - 低文件类型的包含列表 - 设置为 启用并输入您不想被警告的文件类型 框(例如:.exe)。

【讨论】:

  • 有效!我已经编辑了我的组策略...(按照您的第二个链接),它现在可以工作了。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-27
  • 1970-01-01
  • 1970-01-01
  • 2018-01-21
  • 1970-01-01
  • 2023-04-10
  • 2014-07-09
相关资源
最近更新 更多