如何编辑快捷方式的目标并启动它?

时间:2012-11-17 10:45:47

标签: c# target shortcut

我翻阅了一下,找不到任何可以解决的问题;

我正在使用ForceBind强制浏览器使用wi-fi连接而不是以太网连接。 为了使用ForceBind启动浏览器,我使用了一个目标字段为:

的快捷方式

C:\ Windows \ System32 \ ForceBindIP.exe 192.168.2.91“C:\ Program Files \ Mozilla Firefox 3.6 \ firefox.exe” (我基本上是启动ForceBind程序并告诉它启动浏览器)

这里的主要问题是每次我连接到无线网络时IP地址都会发生明显变化(由于与此处无关的原因,我无法设置固定地址来尝试从路由器请求),所以我写了下面的代码来获取当前无线适配器的地址:

    static void Main(string[] args)
    {
        try
        {
            //Variable declaration
            string adapterName = "";
            string adapterIPAddress = "";
            int num = 0; //assisting var

            NetworkInterface[] interfaceList = NetworkInterface.GetAllNetworkInterfaces();

            for (int i = 0; i < interfaceList.Length; i++) 
            {
                if ((interfaceList[i].NetworkInterfaceType == NetworkInterfaceType.Wireless80211) && (interfaceList[i].OperationalStatus == OperationalStatus.Up)) 
                {
                    adapterName = interfaceList[i].Name; 
                    var ipProperties = interfaceList[i].GetIPProperties(); 
                    foreach (var ip in ipProperties.UnicastAddresses) 
                    {
                        if (ip.Address.AddressFamily == AddressFamily.InterNetwork)
                        {
                            adapterIPAddress = ip.Address.ToString();
                        }
                    }
                    num = i;
                    break;
                }
            }
            Console.WriteLine("Adapter name:    " + adapterName);
            Console.WriteLine("Adapter type:    " + interfaceList[num].NetworkInterfaceType);
            Console.WriteLine("Address:         " + adapterIPAddress);
            Console.WriteLine("");

            //Create a string that represents the path with the appropriate IP Address
            ///<   C:\Windows\System32\ForceBindIP.exe xxx.xxx.xxx.xxx "C:\Program Files\Mozilla Firefox 3.6\firefox.exe"   >
            string newPath = "C:/Windows/System32/ForceBindIP.exe " + adapterIPAddress + " \"C:/Program Files/Mozilla Firefox 3.6/firefox.exe\"";
            Console.WriteLine("New path: ");
            Console.WriteLine(newPath);
            Console.WriteLine("Press Enter to launch...");
            Console.ReadLine();

            System.IO.File.Open(newPath, FileMode.Open);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Oh no! Something went wrong! Bummer.", ex.Message);
        }
    }

问题是,在尝试启动(System.IO.Open ...)时,我得到一个异常,说路径有非法字符。那么一个。什么是非法字符,我该如何启动该文件,或b。如果我的计算机上有现有的快捷方式,我该如何让这个程序编辑其目标(仅更改IP地址)并启动它?

0 个答案:

没有答案