Home All Groups Group Topic Archive Search About

Work around for lack of "If Exists"



Author
24 Sep 2007 1:44 PM
Joseph
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

Author
24 Sep 2007 3:56 PM
J Ford
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...


Show quote
"Joseph" wrote:

> 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
Author
25 Sep 2007 4:36 AM
Al Dunbar
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_driveexists.html

/Al

Show quote
"J Ford" <JF***@discussions.microsoft.com> wrote in message
news:95D60E7F-4D36-4DDC-8F81-8D48E103E853@microsoft.com...
> 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...
>
>
> "Joseph" wrote:
>
>> 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
Author
25 Sep 2007 12:36 PM
Tom Lavedas
On Sep 24, 9:44 am, Joseph <Jos***@discussions.microsoft.com> wrote:
Show quote
> 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

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/
Author
25 Sep 2007 10:16 PM
Joseph
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


Show quote
"Joseph" wrote:

> 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

AddThis Social Bookmark Button