Jeremy
Tue Feb 21 23:29:09 CST 2006
Richard,
I didn't even notice that I had commented out the first line. Thanks for
pointing that out.
The character after end if must be a typo too. I've been too sloppy on this
project!
Thanks for the other suggestions. I'll try them out at work tomorrow.
Jeremy
"Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in message
news:eN73352NGHA.720@TK2MSFTNGP14.phx.gbl...
> Jeremy Schubert wrote:
>
>> Jens Frieben from this group gave me some help creating the folowing
>> script to map a printer depending on the computer's name. But I'm not
>> sure I have it quirte right yet because it doesn't work. It seems to go
>> through all the steps because I get the Script Complete message. But no
>> printer is added. (Maybe I have a group policy interfering).
>>
>> It's suppose to check the first eight characters of the computer name (ex
>> 047-lib out of 047-lib-05) and base the printer selection on that. Does
>> anyone have any suggestions?
>>
>> 'Declare Variables
>> Dim sComputerName
>> Set oNet = CreateObject("WScript.Network")
>>
>> 'Determine Computer Name
>> ' sComputerName = left(oNet.ComputerName,8)
>> If (Instr(sComputerName,"047-clib")<>0) Then
>> oNet.AddWindowsPrinterConnection "\\s047-s0371-01\c111"
>> oNet.SetDefaultPrinter "\\s047-s0371-01\c111"
>> End If|
>>
>> 'Determine Computer Name
>> ' sComputerName = left(oNet.ComputerName,8)
>> If (Instr(sComputerName,"047-c309")<>0) Then
>> oNet.AddWindowsPrinterConnection "\\s047-s0371-01\c309"
>> oNet.SetDefaultPrinter "\\s047-s0371-01\c309"
>> End If|
>> MsgBox "Script Complete"
>
> Hi,
>
> First, the line to retrieve computer name is commented out, so as written
> the variable sComputerName will be blank. Next, I don't know what the
> character is after "End If". It must not belong. Next, if you extract the
> first 8 characters of the computer name, I would suggest testing for a
> match, and not use the InStr function. For example:
>
> 'Determine Computer Name
> sComputerName = left(oNet.ComputerName,8)
> If (sComputerName = "047-clib") Then
> oNet.AddWindowsPrinterConnection "\\s047-s0371-01\c111"
> oNet.SetDefaultPrinter "\\s047-s0371-01\c111"
> End If
>
> Or, another way might be:
>
> 'Determine Computer Name
> sComputerName = oNet.ComputerName
> If (Instr(sComputerName, "047-clib") = 1) Then
> oNet.AddWindowsPrinterConnection "\\s047-s0371-01\c111"
> oNet.SetDefaultPrinter "\\s047-s0371-01\c111"
> End If
>
> And, remember the tests are case sensitve. You can use LCase or UCase to
> make the tests case insensitive.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -
http://www.rlmueller.net
>