PlayZoneUK Posted March 2, 2008 Posted March 2, 2008 Good evening all, I was wondering whether someone would be able to help / advise me with the following scenario: I have a program which requires a client printer to have a specific name in order to print to it. When a user logs onto Terminal Services in a Windows server 2003 environment, the local printer is mapped with the following name: "<Printer name> (from <PC Name>) in Session #" When I rename the printer to its original name e.g. HP LaserJet 2200 PCL 6 the program works ok. However as soon as a user logs out and back in the issue arises again. Ive searched the forums to locate a sample script which would rename a printer if it meets a specific requirement i.e. a printer name contains (from and in Session which will then truncate the printer name accordingly, but I've had no success Any help would be appreciated. Words of Wisdom and Favourite Quotes: 'Nothing is impossible, despite what other people say and think, prove them wrong and show them what you can do!' 'Understanding is a three edged sword, your side, their side and the truth!' 'The truth that humanity has never been able to grasp, is that death may be the only absolute freedom there is!' 'I've run out of places to put the brush... what do you suggest?'
kfuller Posted March 12, 2008 Posted March 12, 2008 While not a true AutoIt script, here is a WSH script I wrote that will set the users default printer to whatever printer is seen in the current session that contains the name of the client making the connection. var oShell=WScript.CreateObject("WScript.Shell"); var ThinClientID=oShell.ExpandEnvironmentStrings("%ClientName%"); var WshNetwork=WScript.CreateObject("WScript.Network"); //list of printers installed var oDevices=WshNetwork.EnumPrinterConnections(); var localDefault=''; for(var i=0;i<=oDevices.length-2;i+=2) { var devName=oDevices(i+1).split('/'); //we expect the name of the PC to be the 2nd part of the array if(ThinClientID==devName[1]) { localDefault=oDevices(i+1); break; } } WshNetwork.SetDefaultPrinter(localDefault); WshNetwork=null; WScript.Quit(); Eventually I'll clean this up and make an AutoIt version but this should help point you in the right direction. -Kirk
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now