Showing posts with label Printing. Show all posts
Showing posts with label Printing. Show all posts

Thursday, October 24, 2013

Has Rundll32 run away with your CPU?

So, the truth is you will probably get a call about application slowness and you will see rundll32.exe is taking up all the CPU. You will then proceed to call your server team and tell them to fix it. They will likely tell you that your application is causing it and that rundll32 could be any of a number of things. You will probably yell at them insisting that rundll32 is not part of your application. Luckily I've been a server guy and an application guy so I figured that out myself. But be warned this conversation has and will happen many times.

Easiest thing to start off with is simply trying to figure out what in the world rundll32.exe is actually attempting to do. There are probably many ways to find this but I simply opened up task manager --> clicked on the process tab --> went to the View menu --> Select Columns --> Check the box next to Command Line --> Click Ok.

You will now have an extra column for each process. Find your rundll32.exe process and look at the Command Line column. Hopefully you will see something you recognize but you may find something obscure that requires lots of research...your mileage may vary.

Back to my problem, here is what I found:

rundll32 C:\Windows\system32\spool\DRIVERS\x64\3\hpmsn130.dll,MonitorPrintJobStatus /pjob=31 /pname"printer-c"

That very quickly stood out as a printer related issue because of the spool directory, printer name which wasn't printer-c but changed for this example, MonitorPrintJobStatus, and well those dang hp dlls.

So for a while I cursed printers and HP unified print drivers but realized that wasn't going to fix my problem. I changed the print processor to winprint from the HP specific print processor but that didn't result in a fix.

I proceeded to poke around the printer properties and ran across and option called "Printer Status Notification:" which was the cause of the CPU hogging. I disabled this feature and all was good.

So I went back to cursing HP unified print drivers! But I will save that for another day (we'll call that day never)...I don't like printers.

Friday, February 1, 2008

Standard TCP/IP Port Missing

This post is specifically related to Standard TCP/IP Ports missing in any version of windows.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port

Under that key there is a string value named "Driver" and the data value should be "tcpmon.dll".

I have seen this messed up on server migrations. It is a rare occurrence but a difficult one to figure out.

Also, check to make sure that the following files are in the C:\Windows\System32\ or C:\Winnt\System32\ directory:

tcpmib.dll
tcpmon.dll
tcpmon.ini
tcpmonui.dll

Monday, January 28, 2008

Excel VBA printing and NE numbers

Anyone who has dealt with printing in VBA for Excel knows the plight of the NE00-NE99 ports/numbers that need to be appended to the printer name when passing it into the Application.ActivePrinter.

There are many ways to do this. I have found little bits and pieces here and there on the web and have come up with numerous ways of doing it myself. So I hope to guide you through the easier ways to do this as there seems to be little on the web about working around this problem.

The key:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts

holds the values of the printers and NE port numbers. You could use these registry entries to figure out the NE port number for your printer. It requires some knowledge of using vba to access the registry for reading and using string functions to make a match.

I have also seem some people loop through all the NE numbers....from 00 to 99 to print out. It is possible but I think bad programming and I just don't like it.

The easiest way I've found is using the windows API via VBA.

How it works....

1. You need to declare the API function as below,

Private Declare Function SetDefaultPrinter Lib "winspool.drv" Alias "SetDefaultPrinterA"(ByVal pszPrinter As String) As Long

Note: Don't try to be smart and change the function name or alias or whatever just copy the lines...seriously it won't work if you mess with it.

2. Call the Function: SetDefaultPrinter strPrinter where strPrinter is the name of the print queue..if local the PrinterName and if located on a print server then \\server\queue_name

3. Print Something like the selected sheets or whatever floats your boat.

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

So now you are asking well but now my default printer changed even though it printer correctly...I can't live without my default printer...So here is what I implemented for my specific situation and should get you moving in the right direction. This was a module in Excel and I called it from Workbook_Open by using:

Call PrintModule.Print_Selected_Sheets("C:\Printer.txt")

where PrintModule is the name of my Module if you are creating a new module and copying/pasting the code your module will be Module1 most likely if it is a new workbook.

Also the way this code works is it prints the Selected Sheets so I added the following line prior to calling my PrintModule function.

Sheets(Array("Sheet1","Sheet2")).Select

You could obviously edit Sheet1 and Sheet2 with the sheets you want to print out. You could specify only Sheet1 or add more Sheets to print out....

Please post comments and I will do my best to reply. If you think there is a much better way then please post. I have seen lots of dead end posts with no real answer in my searches so hopefully this one will help out at least a few people. Also I apologize for the formatting as this is my first attempt at using Blogger.