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

----- 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!
BITASCIIAV Technology SupportAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi there,

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


I just had a read through this: http://msdn.microsoft.com/en-us/library/aa394363(VS.85).aspx and put the following snippet together - unfortunately though, it's pretty much just a theory as I have no way of testing it - so I really suggest testing offline if possible.

' This section relates to Note 1, and should remove -ADS01
strNewName = Left(objItem.DeviceID, (Len(objitem.DeviceID) - 6))
Wscript.Echo objItem.DeviceID

' This section related to Note 2, and should add -PSv3
objitem.RenamePrinter(objItem.Device & "-PSv3")
Wscript.Echo objItem.DeviceID

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BITASCIIAV Technology SupportAuthor Commented:
Thanks much for the solution and helping us understand that the 'RenamePrinter' method is needed to achive stated goals.  Thx again!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.