Exemplo n.º 1
0
        static PortStatus WSDPort(string s)
        {
            Logger.Log("Processing " + s + " as a WSD port.");
            String      guid;
            PortStatus  res  = new PortStatus();
            RegistryKey r    = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\SWD\\PRINTENUM\\" + s);
            String      host = null;

            if (r != null && r.GetValue("ContainerID") != null)
            {
                guid = r.GetValue("ContainerID").ToString();
                guid = guid.Substring(1, guid.Length - 2);
                Logger.Log("ContainerID is " + guid);
                r = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\SWD\\DAFWSDProvider");
                if (r != null)
                {
                    foreach (String n in r.GetSubKeyNames())
                    {
                        if (n.StartsWith("urn:uuid:" + guid) || n.StartsWith("uuid:" + guid))
                        {
                            Logger.Log(n + " matches the WSD set.");
                            RegistryKey kid = r.OpenSubKey(n, true);
                            String      loc = kid.GetValue("LocationInformation").ToString();
                            Logger.Log("WSD URI: " + loc);
                            Uri u = new Uri(loc);
                            System.Net.IPAddress.TryParse(u.Host, out IPAddress ip);

                            if (ToHost && ip != null)
                            {
                                host = IPtoHostname(ip);
                            }
                            else if (ToIP && ip == null)
                            {
                                host = HostnameToIP(ip.ToString());
                            }

                            if (host != null)
                            {
                                String newloc = loc.Replace(u.Host, host);
                                Logger.Log("Changing URL from " + loc + " to " + newloc);
                                kid.SetValue("LocationInformation", newloc);
                                res.Changed = true;
                            }
                        }
                    }
                }
            }

            if (res.Changed)
            {
                String loc = r.GetValue("LocationInformation").ToString();
                Logger.Log("WSD URI: " + loc);
                Uri    u      = new Uri(loc);
                String newloc = loc.Replace(u.Host, host);
                Logger.Log("Changing URL from " + loc + " to " + newloc);
                r.SetValue("LocationInformation", newloc);
            }

            return(res);
        }
Exemplo n.º 2
0
        static bool EvaluatePrinter(string s)
        {
            RegistryKey cc = Registry.LocalMachine.OpenSubKey(BASE + "\\" + s, true);

            Logger.Log("Name: " + cc.GetValue("Name"));
            string port = cc.GetValue("Port").ToString();

            Logger.Log("Port Name: " + port);
            PortStatus res = EvaluatePrinterPort(port);

            if (res != null && res.Changed && res.NewName != null)
            {
                Logger.Log("The printer port name has changed. Changing port name from " + port + " to " + res.NewName);
                cc.SetValue("Port", res.NewName);
            }

            Logger.Log("----");
            return(res != null && res.Changed);
        }