Make Select Case run Script Conintue with new Select Case.
1. select case's map network drives.
then, all network printers should be deleted with the following code: For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2 If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True End If
After that, i start again with Select Case
But it the delete network printer code runs in an error.
Posts: 222
Score: 0
Joined: 11/12/2006
From: UK
Status: offline
not sure why that's not working.... i dont have a network printer i can tets with at the moment.... you could try using WMI though..??
quote:
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer Where Network = TRUE") For Each objPrinter in colInstalledPrinters objPrinter.Delete_ Next
Posts: 1924
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
If I am understanding you correctly, the issue is when the code loops again, your printer connection that you just made is deleted. if that is the case, you could just add a variable that you set the first go round.
If you do not want to do the above, you could remove all your deletes from the For-Next and have it run before the for-Next
_____________________________
Mike
For useful Scripting links see the Read Me First stickey!
the Network drives are mapped. The printers are deleted, then a error message appers "command Next expected". If i remove the Deleted Network Printers code, it runs ?
the problem is the code with network printers deletion.
Make sure you indent your code, makes it easier to read and find out where you have incomplete code blocks.
printerMapped = False 'Start your For here For each strGroup in objUser.memberOf ' All your stuff here
If printerMapped = False Then '******************************************************************************** 'Delete Network Printer '******************************************************************************** For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2 If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True End If ''There appears to be a Next missing. '******************************************************************************** 'Map Network Printer '********************************************************************************
Select Case strGroupName
Case "PRT_server_prt22" objNetwork.AddwindowsPrinterConnection "\\server06\asdf_prt101" printerMapped = True End Select NEXT 'this is the missing NEXT End If Next
if the printer exist and i run the script, the printer is removed, but not recreated? if the printer is removed and i run the script, the printer is created (that is correct) but why do the script noch recreate the printer after deletion ? i mean, the del comes before the create or?
is of course due to the code:
For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2 If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True End If
'----- Map printers ----- Select Case strGroupName Case "PRT2" objNetwork.AddwindowsPrinterConnection Printserver1 & "\prt2" End select Next '<---- Problem here
so lets take a look theres two main statements/arguments being used a FOR LOOP and a SELECT Case. the FOR LOOP is to delete all printers and your SELECT Case is to map printers two seperate things. your SELECT Case is in the FOR LOOP which is only for deleting printers. so first lets delete the printers ONLY:
For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2 If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True End If Next
Now AFTER deleting all the printers lets use are SELECT Case and map the correct printers to strGroupName:
'--- Map printers --- Select Case strGroupName Case "PRT_server_prt22" objNetwork.AddwindowsPrinterConnection "\\server06\asdf_prt101" End Select
it should look like this:
< Message edited by sheepz -- 9/6/2007 1:23:05 PM >
hi and sorry for asking again. but this script makes me creazy.... it loops arraound, maps printer, delete it, maps it, delete it, same with network drives.
are we having issues with the Delete/Map printers? OR Delete/Map drives? i thought we only had issues with the printer section? here is your code with ONLY the printer section, the drive mapping has been deleted to isolate the problem. one of the very first things i leared from the admins here was "take away the On Error Resume Next" if you have that ON, the code will not generate errors, so lets go ahead and take that out and see what errors you get with this reduce version of your code:
< Message edited by sheepz -- 9/7/2007 3:13:06 AM >