Automatic Printing

Summary: Learn about automatic printing in a Windows platform using WScript.

Automatic printing is a subject you will find a lot of content about on the internet — but most of it is useless. It’s a massive collection of try-this-try-that. I was searching for some descent content on how to do scheduled automatic printing but spent far more time that I would like to. Finally I arrive at this code:

Option Explicit
Private Const OLECMDID_PRINT = 6
Private Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Private Const READYSTATE_COMPLETE = 4
Private Const PRINT_DONTBOTHERUSER = 1
Private Const PRINT_WAITFORCOMPLETION = 2

Dim pValIn, pValOut

With CreateObject("InternetExplorer.Application")
	'.visible=true
	.Navigate "http://yourpage/"
	Do Until .ReadyState = READYSTATE_COMPLETE AND NOT .Busy
	loop

	pvalIn = PRINT_WAITFORCOMPLETION XOR PRINT_DONTBOTHERUSER
	pvalOut = ""
	Call .ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER, pValIn, pValOut)
	.Quit
End With

There something important to note here. The following lines are necessary for Windows 2003 Enterprise server:

pvalIn = PRINT_WAITFORCOMPLETION XOR PRINT_DONTBOTHERUSER
pvalOut = ""
Call .ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER, pValIn, pValOut)

On a regular Windows XP machine you could get by simply doing:

Call .ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER)

This code works by opening a Internet Explorer window and loading a page and printing that page. Note that if that file loads a PDF file or an excel document then this won’t work. This only works in plain HTML documents.

Four Part Naming Convention in SQL Server

In SQL server if you want to reference a table using four-part naming convention and you receive the error message: Server ‘xxxx’ is not configured for DATA ACCESS. Then you need to execute this statement against the target server:

EXEC sp_serveroption 'xxxx','DATA ACCESS',TRUE

… that should fix the problem. An obvious point here is to replace xxxx with the target server.

Triggers in SQL

In SQL server you can list all the triggers in a database using the following query:

SELECT * FROM sysobjects WHERE xType = 'TR';

You can run this code in query analyzer.

Bush and Failure

If you do a Google search on the word failure the first result comes up with Biography of President George W. Bush. According Marissa Mayer, Director of consumer web products at Google, explains:

Google’s search results are generated by computer programs that rank web pages in large part by examining the number and relative popularity of the sites that link to them. By using a practice called googlebombing, however, determined pranksters can occasionally produce odd results. In this case, a number of webmasters use the phrases [failure] and [miserable failure] to describe and link to President Bush’s website, thus pushing it to the top of searches for those phrases. We don’t condone the practice of googlebombing, or any other action that seeks to affect the integrity of our search results, but we’re also reluctant to alter our results by hand in order to prevent such items from showing up. Pranks like this may be distracting to some, but they don’t affect the overall quality of our search service, whose objectivity, as always, remains the core of our mission.

I found out about this from the Google Blog.

CTRL+ALT+DEL Twice?

In Windows XP pressing CTRL+ALT+DEL twice in the login screen will take you to the classic login screen where you can manually type in the username and password to authenticate yourself. According to a Microsoft employee this feature maybe removed in future releases of Windows or worst yet it might be removed in future service packs. This would have caused serious problems for me because non-of the users I have on the intial list are administrators to the system. That means without that feature I wouldn’t have been able to login to the computer as an administrator (unless I did run-as on computer management MMC and made myself administrator and then loged as me again). But just a note that whoever is depending on this should be aware!

Using ASP.NET to authenticate against AD

The company I work for reliies heavily on active-directory to organize, authenticate and integrate. In order to login to the intranet from our site, we currently request the integrated windows authentication box and ask the user to login. For some people this was a little flattering because it didn’t really say why the login was taking place — where are they loging into and so on. So to remedy this issue, I am working on a ASP.NET product that will authenticate against AD. This can be done using DirectoryServices provided within the .NET framework.

Create secure connection to Active Directory

public static DirectoryEntry GetDirectoryEntry() {
	DirectoryEntry de = new DirectoryEntry();
	de.Path = "LDAP://192.168.1.1/CN=Users;DC=Yourdomain";
	de.AuthenticationType = AuthenticationTypes.Secure;
	return de;
}

Set the culture and identity

public static void SetCultureAndIdentity() {
	AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
	WindowsPrincipal principal = (WindowsPrincipal)Thread.CurrentPrincipal;
	WindowsIdentity identity = (WindowsIdentity)principal.Identity;
	System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
}

Validate if user exists

public bool UserExists(string UserName) {
	DirectoryEntry de = ADHelper.GetDirectoryEntry();
	DirectorySearcher deSearch = new DirectorySearcher();
	deSearch.SearchRoot =de;
	deSearch.Filter = "(&(objectClass=user) (cn=" + UserName +"))";
	SearchResultCollection results = deSearch.FindAll();
	if(results.Count == 0) {
		return false;
	}
	else {
		return true;
	}
}

Code provided from C-Sharp corner.

Bug: Movable Type 3.2

When you have multiple blogs setup in Movable Type and you perform a search from one of the blogs — results come from all the blogs. This is true when only the search is made from mt-search.cgi not from the Main Index file. The solution to this problem can be fixed by modifying search_templatesdefault.tmpl file. Search for the “Search this site:” then after that line add the following code:


The hidden field IncludeBlogs is in the Main Index file but it was orginally missing from the mt-search.cgi file.

Finding Content in your files

If you want to search text files in your computer for a specific string you can do this easily using the following code:

for /f "tokens=*" %i IN ('dir /s /b *.asp') DO find /I "depthomepages" %i >> output.txt

You can replace dir /s /b *.asp to something more appropriate. You can alternatively search only specific folders also, by simply modifying the dir arguments.

Microsoft ISA Server 2004

Finally a resolution to the problem posted last week has been found. In ISA server, in your basic firewall rules there is an option called: “FTP Readonly”. This option was default unchecked until in 2004 Microsoft decided to make that default. This caused us a lot of problems we were unable to send data through FTP even though we could successfully connect to FTP servers. So after lots of hard working hours we found that evil checkbox.

Adobe Photoshop CS2

I have been using Adobe Photoshop CS2 for sometime now and I would like to write a review for it.

In short I don’t really think it’s worth the money to move from Aobe Photoshop CS (if you are using this version). Howerver from a 7.0 it’s a great change, here are some I noticed and liked:

Adobe Bridge
Is the new tool to explore your files. It can view RAW thumbnails and also allow you to paste settings from one RAW file to another saving you a great deal of time. It also allows for you to rank images and preview them at various sizes using a simple slider.

RAW Tool
The rool tool is updated as well. They added a new contrast curve which works much like the curve on actual photoshop but right within the RAW viewer.

Smart Sharpen
Finally, a new sharpening tool. It allows finer control than the Unsharp mask allow you to fade sharpness from highlights and shadow area individually.

32-Bits Images
Yes! You can now edit images in 32-Bit RGB. 32-Bit only seems to work in RGB and CMYK not in lab color modes. But’s it’s a way to change the levels and curves making certain that there will be no loss in the process.

More tools availabe in 16-Bit
There are more tools available in 16-Bit now almost as if you are working on 8-Bit.

I purchased a Canon 20D at the same time I moved from Adobe Photoshop CS to CS2. Now most of the images it seems like there is less work that I need to do specially when it comes to white-balance (in the shadows) and contrast. The Canon 20D seems to produce more contrasted images using the same lens compared to the Canon 10D. Anyway, CS2 seems to do a better job at white-balancing from the RAW viewer than CS did. For sometime I also used Phase One’s Capture One — which I think is a great tool and was using this while I was using CS. However since CS2 I don’t feel the need to use Capture One anymore because I think the conversion quality I get with CS2 is same if not better than Capture One.

Page 1 of 212»