コード例 #1
0
        protected void SetupUserPrinter(string username, string printername)
        {
            var    ident   = WindowsIdentityStore.GetWindowsIdentity(username);
            string reguser = "******";
            string usersid = ident.User.Value;

            if (Registry.Users.GetSubKeyNames().Contains(usersid))
            {
                reguser = usersid;
            }

            string devregpath = reguser + @"\Software\Microsoft\Windows NT\CurrentVersion\Devices";

            using (var devregkey = Registry.Users.CreateSubKey(devregpath))
            {
                if (devregkey.GetValue(printername, null) == null)
                {
                    string portname = GetPrinterPort(printername);

                    if (portname == null)
                    {
                        portname = GeneratePrinterPort(devregkey);
                    }

                    devregkey.SetValue(printername, "winspool," + portname);
                }
            }
        }
コード例 #2
0
        protected virtual int RunCommandAsUser(string username, string[] args, Stream stdin, Stream stdout, Stream stderr)
        {
            string gsexepath = GetGhostscriptPath("gswin32c.exe");

            return(WindowsIdentityStore.RunProcessAsUser(username, stdin, stdout, stderr, Path.GetDirectoryName(gsexepath), gsexepath, args));
        }