Good day all,
I have a logon script that sets up mapped drives and printers. The problemI
have been getting complaints of too much time logging on, is after the user
has logged on once there is no need to go through the process again.
My idea is if I could test for the first printer I could end the script on
the true condition. I am using standard
"objWshNet.AddWindowsPrinterConnection "\\yyy14\yyyGroupLaser"".
"If exists" does'nt (exist).
Ideas?
Thank you,
Joseph
J Ford - 24 Sep 2007 16:56 GMT
Maybe something like this:
REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices" | FIND
/I "\\yyy14\yyyGroupLaser"
IF %errorlevel% EQU 0 GOTO EOF
Watch for word wrap...
> Good day all,
> I have a logon script that sets up mapped drives and printers. The problemI
[quoted text clipped - 11 lines]
> Thank you,
> Joseph
Al Dunbar - 25 Sep 2007 05:36 GMT
Or, instead of testing for the printer, test for a drive that should be
mapped if the script has already run, using .driveExists:
http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject_driveexis
ts.html
/Al
> Maybe something like this:
>
[quoted text clipped - 23 lines]
>> Thank you,
>> Joseph
Tom Lavedas - 25 Sep 2007 13:36 GMT
> Good day all,
> I have a logon script that sets up mapped drives and printers. The problemI
[quoted text clipped - 11 lines]
> Thank you,
> Joseph
There isn't a 'IF Exists' for printers, but there is an
EnumPrinterConnections. The little example below illustrates its use
to construct a string of all available resources, which you could
search for the desired existence indication (drive or printer) using
an InStr(), maybe.
Set oNet = CreateObject("WScript.Network")
Set oDrives = oNet.EnumNetworkDrives
Set oPrinters = oNet.EnumPrinterConnections
s = "Network drive mappings:" & vbNewline
For i = 0 to oDrives.Count - 1 Step 2
s = s & "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1) _
& vbNewline
Next
s =s & vbnewline & "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
s = s & "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1) _
& vbNewline
Next
WScript.Echo s
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Joseph - 25 Sep 2007 23:16 GMT
Thank you all for your insight, it shaped my thinking to this solution.
-----------------------
Option Explicit
Dim strLaser
Dim strComputer
Dim ColItems
Dim objItem
Dim objWMIService
strComputer = "."
strLaser = "yyyGroupLaser"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer",,48)
For Each objItem in colItems
If InStr(objItem.Name,strLaser) > 0 Then
WScript.Echo "Found yyyGroupLaser"
WScript.Quit
Else
Wscript.Echo "Searching"
End If
--------------------------------
Again thank you J Ford, Al Dunbar and Tom Lavedas
Joseph
> Good day all,
> I have a logon script that sets up mapped drives and printers. The problemI
[quoted text clipped - 11 lines]
> Thank you,
> Joseph