I currently have a WPF C# application that basically loads a XAML Window control, stuff information in it, and then call PrintVisual();
On Windows 10, this operation works normally for standard user (Limited permission). However on Windows 7, PrintVisual hangs and does not print unless application is elevate to run as Administrator.
All windows 7 machine has been updated to the latest version.
Here's my question; why does PrintVisual require administrator privilege to print? Do I need to use a different technique when running on Windows 7?
(Thought about Graphic.CopyFromScreen Method to bypass administrative privilege...)
Below is a code sniplet of where the problem lies.
BinLocation bl = new BinLocation(); // A Windows control object
PrintDialog dlg = new PrintDialog(); // API from System.Windows.Controls
LocalPrintServer prtSrv = new LocalPrintServer(); // API from System.Printing
PrintQueue pq = prtSrv.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local }).Where(w => w.Name.Contains("QL-500") && !w.IsOffline).FirstOrDefault();
if (pq != null) dlg.PrintQueue = pq;
bl.Show();
// Problem here with Win7 Standard user, code hangs and refuse to raise exception. using System.Windows.Media.Visual
dlg.PrintVisual(bl, "");
bl.Close();
I am currently using WPF C# project in VS2015 on Win7 x64 machine.
Related
I have a winform application (.exe file) in my windows server 2019 and windows 10 .
This app should auto run when winsows start without login ,
and my code is below , but it now work well ,
how i can fix it
public static void AddApplicationToCurrentUserStartup()
{
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
if (key.GetValue("MyApplication") == null)
{
key.SetValue("MyApplication", Application.ExecutablePath.ToString());
}
}
}
You can design your application as a Windows service, then as it detects user logon, make your service execute the WinForm for further interaction.
You can use ServiceBase.OnSessionChange and SessionChangeReason.SessionLogon. Since this event is under ServiceBase, I think you'd need to find another way if you don't want to redesign your application as a service?
update:
Service can achieve what you mentioned in your comment in OP. If configured properly in the service's installer, service will start up after the system is booted.
// Automatically starts up the service after boot up.
serviceInstaller1.StartType = ServiceStartMode.Automatic;
I have a WPF app that installed on Windows 10 Pro via ClickOnce and uses MahApps.Metro.
It is set to launch on Windows boot with a non-admin account that has no password. Tablet mode is enabled.
I want the application pop up full screen to create kiosk-like experience, however the app starts minimized when launching on boot. To clarify, the WindowState is Maximized, but Windows does not show it, instead it shows the start screen. It launches fullscreen maximized when launching manually.
Here is some code, however I guess this is more of a configuration problem than code problem:
This is how I set the launch on boot:
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey(#"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
string startPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs)
+ #"\Publisher\AppName.appref-ms";
rkApp.SetValue("AppName", startPath);
This is MainWindow.xaml
<Controls:MetroWindow x:Class="AppName.MainWindow"
IgnoreTaskbarOnMaximize="True" ShowTitleBar="False" WindowStyle="None" WindowState="Maximized">
...
</Controls:MetroWindow>
Take a look at Kiosk Mode for Windows 10.
From Set up a device for anyone to use (kiosk mode):
A single-use device is easy to set up in Windows 10 for desktop
editions (Pro, Enterprise, and Education). For a kiosk device to run a
Universal Windows app, use the assigned access feature. For a kiosk
device (Windows 10 Enterprise or Education) to run a Classic Windows
application, use Shell Launcher to set a custom user interface as the
shell.
From Assigned access (Industry 8.1):
Administrators can use assigned access to restrict a user account to
access a single application. You can use assigned access to set up
single-function devices, such as restaurant menus or displays at trade
shows.
The following table identifies the type of application that can be used on each Windows 10 edition to create a kiosk device.
A Universal Windows app is built on the Universal Windows Platform
(UWP), which was first introduced in Windows 8 as the Windows Runtime.
A Classic Windows application uses the Classic Windows Platform (CWP)
(e.g., COM, Win32, WPF, WinForms, etc.) and is typically launched
using an .EXE or .DLL file.
You can do this in the MainWindow.xaml.cs by adding a windowstate of maximized.
public MainWindow()
{
InitializeComponent();
this.WindowState = WindowState.Maximized;
}
The solution (hack) was to open any other window (e.g. powershell) on startup using Task Scheduler, and after another window is open, we can call Alt+Tab in a powershell script using.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("%{TAB}")
Set the Window state in the ContentRendered event handler:
protected override void OnStartup(StartupEventArgs e)
{
Application.Current.MainWindow.ContentRendered += (s, a) =>
Application.Current.MainWindow.WindowState = WindowState.Maximized;
}
I am having an issue with Chromedriver failing to send simulated inputs (Control + P ) on a server. The inputs that I am sending with InputSimulator (http://inputsimulator.codeplex.com/). Using Selenium and Firefox, the tests execute perfectly; however when I change over to use Chromedriver, I am encountering failures from my input simulator not properly firing on the page. That is the only difference taking place.
If I perform the test on my local machine instead of on the server, it executes flawlessly. Since InputSimulator just simulates they keys being pressed, it never reports a failure.
The servers that I am running on Windows Server 2008 R2 64 Bit.
Why would Selenium(Firefox) not have any issue and changing to Chromedriver now causes them to never send only one the servers? The only section of code changing is the driver settings.
Selenium (firefox)
FirefoxProfile profile = new FirefoxProfile(#"path/to/profile");
using (IWebDriver driver= new FirefoxDriver(profile))
{
//Navigate to URL
driver.Navigate().GoToURL(#"http://google.com");
//Wait for the page to load
Thread.Sleep(2000);
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_P);
Thread.Sleep(2000);
InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
//Now I have the dialog to send my save path.
}
Chromedriver
var options = new ChromeOptionsWithPrefs();
options.prefs = new Dictionary<string, object>
{
{ "printing.print_preview_sticky_settings.appState","{\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\",\"selectedDestinationOrigin\":\"local\",\"customMargins\":null}" }};
options.AddArgument("--disable-extensions");
options.AddArgument("-incognito");
options.AddArgument("-start-maximized");
options.AddArgument("--renderer-print-preview");
using (IWebDriver driver= new ChromeDriver(#"C:/Chromedriver/path", options))
{
//Navigate to URL
driver.Navigate().GoToURL(#"http://google.com");
//Wait for the page to load
Thread.Sleep(2000);
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_P);
//Code never fires on the servers; does fire on my local machine.
Thread.Sleep(2000);
}
InputSimulator does not work in Windows Server 2008 R2 and Windows 7 if Aero is off (I have not tested with other versions, yet).
For Windows 7, switch to an Aero theme and it will start working again.
For Windows Server 2008 R2, you will need to install Workstation Theme for Aero:
Run this command in command prompt:
ServerManagerCmd -i Desktop-Experience
Restart the server.
Go to services.msc and start the Themes service.
Go to Windows Display settings, select Personalize, Pick an Aero Theme.
I have a simple windows service which i need to use to invoke a console application.The console app generates pdf to print by opening the adobe reader window.Running the console app works fine to print pdf.But invoking it from service not successful.It doesnt even show up the console window where i log events.
Process pdfprocess = new Process();
pdfprocess.StartInfo.FileName = #"C:\Documents and Settings\xyz\Desktop\dgdfg\PdfReportGeneration\bin\Debug\PdfReportGeneration.exe";
pdfprocess.StartInfo.UseShellExecute = false;
pdfprocess.StartInfo.RedirectStandardOutput = true;
pdfprocess.Start();
But invoking other application like
pdfprocess.StartInfo.FileName = #"C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe";
works fine.
What will be the reason?
There is probably some permissions issue there (PdfReportGeneration.exe inaccessible under service account or maybe something that it uses...)
I would advise to capture Process Monitor log to see where exactly it fails.
Windows services run in a different window station and cannot interact with the desktop, unless you're using an older version of Windows and tick a checkbox in the service properties in the service manager.
all,
I have code in C# 2.0 like this:
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
//.........
}
It is console exe for a 64bit Windows Server 2008 R2 Standard with sp1, IE9.
Basically it launches IE and download a file, then process that file.
When I run it manually, such as double click or from Command console, it works just fine. However, when I set up a Scheduled Task through Task Scheduler, it throws the error at the first line above:
Retrieving the COM class factory for component with CLSID {9BA05972-F6A8-11CF-A442-00A0C90A8F39} failed due to the following error: 8000401a.
I think it must be a permission issue,but I couldn't figure out how to fix it. Any ideas?
Thanks.
I suspect this is to do with access to the desktop.
As shdocvw has a UI, it requires permission to get the desktop handle. When it creates a window it must have a parent window and the desktop window handle is king (or Queen).
However, a scheduled task (for any user) cannot get the desktop handle unless the user is already logged-in in the foreground.