Link to home
Start Free TrialLog in
Avatar of BITASCII
BITASCIIFlag for United States of America

asked on

VBScript, trim and append to WMI object name

In our Win2003 Server and XP Pro workstation environment, the logon scripts install as many as 12 network printer drivers to each workstation.  Each printer driver that is installed locally via the logon scripts gets the tag "-ASD01" appended to printer name.  For example, if we click on Start | Settings | Printers & Faxes to display the print driver list, each automatically installed driver will end with -ASD01, such as HP LaserJet4-ASD01  -- where as if you manually installed that driver (not via login scripts) it would display as HP LaserJet 4.  The network login scripts are protected and we cannot edit them, however, WSH is enabled on workstations so that VBScript works.  We need help with a VBS that does 2 things: i) it trims the -ASD01 off each printer name in the local WS printer list, and ii) it appends a user supplied string that is to display at end of the DeviceID string (this user supplied string will identify driver type, version and other info - it does not have to be more than 8 chars).  Here is the beginnings of that vb script, is anyone able to manipulate strings to trim the unwanted right-most chars, then (preferably in a separate line) append mmyy?  

--- Code begins ---
On Error Resume Next
StrComputer = "."
Set objWMIService = GetObject("winmgmts:\\"& strComputer &"\root\cimv2")
Set ColItems = objWMIService.ExecQuery("Select * from win32_printer where DeviceID like '%-ADS01%'")
For each objItem in ColItems
*Note1: our code is missing line(s) here that would modify DeviceID so as to trim "-ASD01" off
*Note2: our code is missing line(s) here that would append mmyy (we will modify the file to supply appropriate
wscript.echo objItem.DeviceID
Next

----- end of code example ---

The succesful code would change
HP LaserJet 4-ASD01
to this (the 8 new chars are supplied by user who edits the vb script text file)
HP LaserJet 4-PSv3    

Appreciate any help with this WMI object string manipulation issue. Thx!
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi there,

Is ASD01 a constant for every printer?  If so, then you could just use
strMyString = Replace(objItem.DeviceID, "-ASD01", "-PSv3")

Regards,

Rob.
ASKER CERTIFIED SOLUTION
Avatar of Psy053
Psy053
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BITASCII

ASKER

Thanks much for the solution and helping us understand that the 'RenamePrinter' method is needed to achive stated goals.  Thx again!