We have a automated printing service running as System account printing web urls.
The idea is using WebBrowser to load page and call Print upon it finished loading.
This works fine on Server 2003 , 2008r2 etc but does not work on Server 2012 ONLY IF it was running as a service. running as a console application works fine.
The problem:
It would load web pages fine and would call Print() , Print() will return but nothing gets printed on the default printer: no print job at all.
I thought it would be account problem so I tried to run service as the same logged on user but still does not work, if that user run application as console app then it would work fine. So default printer and user account get ruled out.
I don't think it is a code problem (it must be though) as it works for older Windows versions running as service.
It seems something fundamental got changed for a service process in server 2012.
Update 1. It may relates to How do I print an HTML document from a web service?
However it works fine for me prior server 2012.
Update 2. It does not work even the whole print happens in a separate process, i.e. my service launches a process to do print, it does not work either. Everything works fine if I run same code in console mode. It is definitely not a threading problem but rather something deep in server 2012.
Now the questions are:
What is changed? Why it stopped working?
At http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/fdcfa0fa-50aa-4a61-be79-5b4c8f65fbf7/ we see that this was reported to Microsoft and confirmed as a bug in Windows 8 and Windows Server 2012.
This bug is triggered when trying to print from a 32bit process in non-standard user session (like e.g. a service).
According to Microsoft, this a bug was resolved in Windows 8.1 and Windows Server 2012 R2. However, we could still reproduce it on Windows 8.1.
On the same site, a workaround is given by Microsoft. This workaround solved the problem for us on Windows 8.1. It probably also works on Windows 8 and Windows Server 2012.
The workaround goes as follows:
Open Regedit and go to HKEY_CLASSES_ROOT\CLSID{BA7C0D29-81CA-4901-B450-634E20BB8C34}
Check the value of the "AppID" Registry Entry. In our case this was {AA0B85DA-FDDF-4272-8D1D-FF9B966D75B0}
Now go to HKEY_CLASSES_ROOT\AppID{AA0B85DA-FDDF-4272-8D1D-FF9B966D75B0} (or the respective value you found on your system)
Under this registry key, delete the entries with the name "AccessPermission", "LaunchPermission" and "RunAs"
Since this is a bug in Windows, you cannot fix it in your code. The workaround might have side effects, but we haven't seen any so far in our scenario.
Related
I'm facing a usual problem in Asp.Net (C#).
Is there anybody who knows the complete successful way to run a cmd.exe inside IIS (Win 10 Pro x64 v.2004)? I have tried almost everything suggested (User privileges,Enable 32 Application, AppPools...etc) with code inside my Form.cs (System.Process.Start...etc.) but with no luck. I've also tried using java procedure in PL SQL (I'm using Oracle 9i Oracle database) with no result for one more time :(
My aim is to have a button in my form just to run rwrun60.exe inside cmd.exe in order to display a RDF report (Oracle Reports 6i) on screen.
Inside VS2012 Ultimate the embedded IIS works really fine. However when I try this in localhost IIS Web Server the result is nothing. The most bizzare thing is that in Task Manager after the button push (with the neccessary code) I can see the processes (cmd.exe, rwrun60.exe) running but I cannot see the Live Previewer on my screen.
Any help or suggestions?
Thnx in advance
Billy P. Ellas- Athens- Greece
I'm building an ASP.NET application that requires printing using PrintDocument method:
PrintDocument.Print()
Printing works properly in development env with IIS express. when publishing it to an intranet IIS server, printing fails, which I think is caused by permission issue for aspnet working process.
I tried to do the following with no success:
I created an application pool in integrated pipeline mode for an admin local user with load user profile option set to true
I moved the application to the new created application pool
I added <identity impersonate="true" username="username" password="*****"/> in web.config file
An error appeared stating that: An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode so I added <validation validateIntegratedModeConfiguration="false"/> to <system.webServer> section.
Any help please?
I think you might be misunderstanding some fundamental concepts here. When you use PrintDocument.Print() you are printing on the server. When you deploy your application in IIS this printing will happen on the server computer that is hosting your application. The reason why you thought your code was working in IIS Express is because you were hosting your application on the same computer as the client browser that was testing it. Also you were running your application under your account which had a printer configured.
You cannot print directly to the client computer from a web application. That would be a big security issue. The best you could do is provide some HTML document using a print media CSS type. Then if the user decides, he might print it in his browser.
If on the other hand you want to print on some printer that is attached to your web server, you will need to configure the Application Pool in IIS to run under an identity that has a printer configured in its profile.
Hopefully I am understanding your question correctly, but I just had some confusion myself with this. Our setup at my work is Windows Server 2008 R2 with IIS 7.
We have a print server as well installed on the same box (not sure if it matters as this is not my area of expert).
Basically, viewing the installed printers using, PrinterSettings.InstalledPrinters I was able to see all the printer names installed on the server.
I attach a debugger to the application process to debug and I can just use the debugger to see this, otherwise you will have to run a loop to print through these. If you run this locally, you will see only the printers installed on your machine. If they are network printers, then the full path will be shown. So determine the path/name the server will recognize the printer as and then set that to the printer name explicitly using the,
PrinterSettings.PrinterName property of the PrintDocument class. This worked for me. Also, my application pool identity is set to NetworkService.
I think the original poster has gotten a lot of flack for their question. If you want to generate .PDFs using GhostScript, for example, you install a printer driver and create a printer for it. You can suppress the Saveas() dialog in many languages by providing one ahead of time. This was feasible in earlier versions of IIS (that may have been less secure), but is harder to do in IIS 8.
I think this issue is caused by IIS inhibiting access to the local printer queue. This is either caused by not being in the NT AUTHORITY\INTERACTIVE group at runtime, or because IIS will put the user, (whomever is running the app pool) in two groups: IIS APPPOOL\, and BUILTIN\IIS_IUSRS.
You can validate all this by looking at the thread permissions using a tool like Sys Internal's Process Explorer.
I have faced same issue and I found the following solution and it worked for me.
1 - Go to printer and setting of system
2 - Select Printer
3 - Go to Printer Properties
4 - Security
5 - Click on Add "IIS AppPool\DefaultAppPool" as object name and click on check name (Default Pool will be your Pool Name)
6 - Give permission Manage This Printer and Manage Document permission.
7 - Restart IIS
We have an application that requires to be continously run but it can't run as a service so we run it in Windows 2003 console session. After migration to Windows 2008 and with the session 0 isolation, the GPO causes the session to teminate after the session is idle for 30 minutes.
I wrote a little C# application to simulate key press using sendkeys.send and sendwait but the remote desktop session still gets connected. Any source code or idea to keep the session permentantly active other than changing the GPO as this isn't possible for the time being?
I think there are prob two options you could look at for obtaining the desired effect.
1) SrvAny.exe - this is a tool provided by Microsoft, that will take any exe and run it from the services control panel. While there is no version that officially supports server 2008, the version that works on server 2003 works just fine. I've used it to run dropbox has a service in the past.
Here is a tutorial that does something similar with dropbox Dropbox as a service on server 2008
2) Write a stub application that will run as a service and do nothing more than launch the exe from the vendor.
I realize this is not what you asked persay, but it would give you the desired effect.
I'm writing this program that will need to access the registry to pull some info on the machine. It should always be run by someone in the Local Admin group, and it will be used on Server 2003 and 2008 machines. Basically it's been working fine for the most part on the box that I'm mainly writing it on, as well as my test 2003 and 2008 servers. The problem is, when I get on my laptop, which is running Windows 7, I cannot seem to use it for testing as I'm getting errors when trying to read or write the registry below HKEY_LOCAL_MACHINE\SOFTWARE.
I'm logged in as a user who is a local admin, and I can run Regedit to create a key, such as test9999. If I use the following it will always come back null.
RegistryKey testKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\test9999");
I've tried dropping the subkey and SOFTWARE will return, but I haven't been able to get anything below that.
I'm using MS VC# Express and I've tried running it "as Administrator" as well as trying to run the .exe's the same way, but it still continues to return null for anything below Software. What am I missing?
Turns out registry redirection behavior for 32 bit processes running on 64 bit Windows was changed in Windows 7 and Windows 2008 R2, which may explain why it works on Windows 2008 (not R2 I assume) and not on Windows 7.
Read more about it here: http://msdn.microsoft.com/en-us/library/aa384232(v=vs.85).aspx
Solved the problem see the bottom of my post.
So I have a simple windows service that watches a specific folder and upploads files that come into it to a server using a web service.
It's working fine on my machine using windows 7 but when I try to start it on a windows server 2003, I receive an error: Error 1053: the service did not respond to start or control request in a timely fashion. But I get this message after only a few seconds.
I have created the ServicesPipeTimeout and set it to 60000 milliseconds.
I have tried running it from command line using sc query command and found out that the WIN32_EXIT_CODE is 0, which I think means that the service doesn´t even try to start because it find an error before it starts.
In the event viewer I get errors 7000 and 7009.
I am the Administrator on the windows server.
The only thing I haven´t tried is a hotfix I found from microsoft but I don´t want to use it because as I understand it, it is for when the service actually times out.http://support.microsoft.com/kb/886695
I have tried everything I can think of, is there anything that I am missing?
Gísli
EDIT: Re-installed the .NET framework and now I get a new error, Saying that the service controller can not be found.
EDIT: I setup the service with a setup project, not using the installutil command. This is because I need to get user input during the installation and save that in the registry.
EDIT: I have installed the .NET 4.0 framework, it wasn´t possible to install the service with out doing that.
In addition to what I wrote above I have also tried:
Rebooting.
Re-installing.
I have tried to change the permissions on the files that the service needs to access.
Changing permissions in the registry editor.
Edited the code so that the onStart function only starts one thread.
I think it is some kind of permission problem but I don´t have much experience dealing with Windows server.
Solution:
It turned out to be two seperate problems. The .NET framwork had to be repaired and I had to remove the try/catch clause that I had when starting the service. For some reason (unknown to me) the try catch block did something that made it impossible to start the service in a windows server 2003 but it ran fine on windows 7.
It would be very interesting to know why this is.
Thanks for all the help.
Gísli
Have you installed the right version of .NET Framework on the Server 2003 PC? What comes as standard on Windows 7 will need to be installed manually on an older OS.
You say "I have tried everything I can think of". Please edit the question to show what you have already tried so we don't suggest something you have already done.
EDIT:
Try also the Fusion Log viewer. Set it to log failures then start your service. Hit refresh then see if any errors are logged. Double-click a line for more details.
I'd guess that you installed the .NET 3.5 service using .NET 2.0? InstallUtil will work since the CLR is the same, but the service won't start because of .NET 3.5 dependencies.
See Also:
How to install a Windows service developed in .NET 3.5?
In your OnStart code you could wrap everything in a try-catch block and write the exception message and stack trace to a file using something like:
File.WriteAllText(#"C:\Temp\MyServiceLog.txt", exp.Message + exp.StackTrace);
This will help you analyze the problem. Also, I'm using a very simple way of debugging my services: I'm wrapping them in a WinForms wrapper if the session is interactive. For that, I need the following:
A form that creates an instance of the service class
New methods DoStart and DoStop in my service class, which are public and call the protected OnStart and OnStop methods
New code in above form's OnLoad and OnClose handlers, so the DoStart and DoStop methods of the service instance are called accordingly
Then I add the following code to the Main method in Program.cs:
if (Environment.UserInteractive)
{
Application.Run(new FormServiceHoster());
}
else
{
// ... old code to create service instance.
}
This way you're making the "service" run as an application when you just hit F5 in Visual Studio or double click the EXE in the Explorer. When the service is actually run as a service, the Forms-code is ignored.
Usually you can debug services by attaching to the process, however, that doesn't work for debugging the start and stop code. This method helps a great deal debugging the service start and stop code.
You will need to add references to System.Windows.Forms and System.Drawing manually.
This is the point where I bet you wish you had used some logging package like log4net, which might help tell how far your program gets.
Is it possible that the code in the OnStart event is actually taking longer than you expect. If so, you could move that code to a thread, so that the OnStart event finishes (and so Windows reckons the service has started) while your thread continues working.
Are you running the service as admin? If so, that usually rules out permissions issues. (If it still goes wrong, it will rule out the KB 886695 issue as that seems to only apply to local system).
Since you are using .NET 4.0 are you sure that either, the full version is installed, rather than the Client Profile, or that your application works with the client profile?