Jump to content

Recommended Posts

Posted

Hi All,

 

I am writing a new logon script in VB Script. As part of this I need to check the network printers that the user already has connected, and connect/disconnect printers as requires.

 

The following code works very well, however if I run it as a logon script it takes 9/10 seconds to run. If I run it after logon it takes less than a second. As a logon script it seems to spend most of the time doing 'nothing' with a quick burst right at the end.

 

Does anyone have any ideas as to why this is? Or any ideas as to how to get the info in some other way without the delay?

 

 

'Loop round all printers, only list ones that start \\
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
   If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
LogMsg("Found Printer: "&WSHPrinters.Item(LOOP_COUNTER +1))
   End If
Next

 

Many thanks

 

Will

Posted

I know nothing, so just guessing, but maybe it is running before the printer connections are setup/recognised yet so there is nothing to enumerate. Is there a way you can delay the script until later? Perhaps put in some debugging like once you've set variable to enumprinterconnections, echo the value to screen. if it takes 9 seconds for that to happen, then it might be what i'm thinking. either that or something else is delaying the script.

like i said i know nothing. :)

Posted

I have enhaced the code slightly so that it logs every printer found not just the network ones.

 

 

'Loop round all printers, only list ones that start \\
Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
   If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
LogMsg("Found Network Printer: "&WSHPrinters.Item(LOOP_COUNTER +1))
   Else
LogMsg("Found Local Printer: "&WSHPrinters.Item(LOOP_COUNTER +1))
   End If
Next

 

This gives the following at logon: (printer names replaced by ***)

 

21/09/2009 15:56:30: Listing all mapped network printers...

21/09/2009 15:56:40: Found Local Printer: ***
21/09/2009 15:56:40: Found Local Printer: ***
21/09/2009 15:56:40: Found Local Printer: ***
21/09/2009 15:56:40: Found Local Printer: ***
21/09/2009 15:56:40: Found Local Printer: ***
21/09/2009 15:56:40: Found Local Printer: ***
21/09/2009 15:56:40: Found Local Printer: ***
21/09/2009 15:56:40: Found Network Printer: \\***\***
21/09/2009 15:56:40: Found Network Printer: \\***\***

 

If I run the code after logon there is no delay, or indeed if I run the same code again later on in the script there is no delay.

 

If I put a sleep in the script to say wait 2 mins and then list the printers, this makes no difference the script still sits there for 10 seconds.

 

It looks like it is actually conncting to the server to verify the printers exist. Could this casue the delay?

Posted

Thanks for all your help. At least I know that the code should work.

 

I think I will do some packet logs tommorrow using ethreal to see if I can find out what happens in that time frame.

 

Will

  • 3 weeks later...
Posted

Well I finally have got to the bottom of this...

 

All of my test accounts have "been arround for a while" therefore at some point in the past have connected to printers on servers which no longer exist.

 

These connections have been stored in the registry (as they should). When our existing (old script) touches printers it uses con2prt.exe

It appears con2prt.exe does not properly remove a printer which it is unable to connect to, it removes the "visible bits" but leaves connection settings in the registry.

 

If I load the ntuser.dat file into a regedit and remove the old junk then the script progresses as it should.

 

Just for reference, if this problem exists you cannot use the WMI method others suggest - that times out so the array cannot be looped.

 

Hope this helps someone else out in the future!

 

Will

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...