Page 1 of 2 12>
Topic Options
#198469 - 2010-04-28 04:29 PM Script sometimes hangs
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Hello everybody. I hope some one can help me to figure out why my script hangs on the part of installing printers. The script works but sometimes some PC's execute the script really slow. Other times PC's execute the script real fast. I don't understand why it doesn't execute fast alll the time. Is there something in my script that i can do to speed things up.
I appreciate any help



 Code:
 

color w+/m                                               ;change background color to yellow
cls                                                     ;Clears the screen

?"Here is some information about your session:"
?
?"Current Computer Name:        @wksta."
?"The Server you logged into:   @lserver."
?"Your IP Address is:           @ipaddress0."
?
?"Please wait while your login script connects all network resources..."



;;;;;;;;;;;;;;;;;;
; Script Options ;
;;;;;;;;;;;;;;;;;;
Debug on
If Not @LOGONMODE
	Break On
Else
	Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
If @SCRIPTEXE = "KIX32.EXE"
	$RC = SetOption("WrapAtEOL", "On")
EndIf

;;;;;;;;;;;;;;;;;;;;;
; Declare variables ;
;;;;;;;;;;;;;;;;;;;;;

Dim $Printers, $Printer
Dim $Drives, $Drive

; Server Name Variables
Dim $fileserver
Dim $newtechsrv


;;;;;;;;;;;;;;;;;;;;;;;;
; Initialize variables ;
;;;;;;;;;;;;;;;;;;;;;;;;

$Drives = Split('f:|g:|h:|i:|j:|k:|l:|m:|n:|o:|p:|q:|r:|s:|t:|u:|v:|w:|x:|y:|z:','|')


$Printers = '\\server\FIN',
'\\server\MEM',
'\\server\PS3',
'\\server\LJCPS',
'\\server\NPS',
'\\server\TN', 
'\\server\TN2',
'\\server\PCL6', 
'\\server\S',
'\\server\L6',
'\\server\24',
'\\server\7310' 

; Server Name Variables
$fileserver = 'server2'
$newtechsrv = 'server3'

;;;;;;;;
; Code ;
;;;;;;;;

; Disconnecting all network drives...
For Each $Drive in $Drives
	Use $Drive /del
Next

; Drive Mappings
Use k: '\\' + $fileserver + '\Pu'
Use l: '\\' + $fileserver + '\share'

If InGroup('fso_OfSvc')
	Use j: '\\' + $fileserver + '\OfSvc'
EndIf

If InGroup('fso_mem')
	Use p: '\\' + $fileserver + '\Mem'
EndIf

If InGroup('fso_member')
	Use i: '\\' + $fileserver + '\iMIS_LIVE'
EndIf

If InGroup('fso_fin')
	Use s: '\\AM01\SAGE'
	Use f: '\\' + $fileserver + '\Fin'
EndIf

If InGroup('fso_hr')
	Use x: '\\' + $fileserver + '\HR'
EndIf

If InGroup('fso_med')
	Use p: '\\' + $fileserver + '\MED'
EndIf

If InGroup('fso_mark')
	Use p: '\\' + $fileserver + '\Com'
EndIf

;IF INGROUP('fso_mark_cr')
;  use q: '\\' + $fileserver + '\Cr'
;ENDIF

If InGroup('fso_qa')
	Use q: '\\' + $fileserver + '\QA'
EndIf

If InGroup('fso_cha')
	Use p: '\\' + $fileserver + '\Cha'
EndIf

If InGroup('fso_pr')
	Use h: '\\' + $fileserver + '\Pr'
EndIf

If InGroup('fso_mark_space')
	Use o: '\\' + $fileserver + '\Space'
EndIf

If InGroup('fso_KT')
	Use t: '\\' + $fileserver + '\Knowledge'
EndIf

If InGroup('fso_ch')
	Use m: '\\' + $fileserver + '\Ch'
EndIf

If InGroup('fso_export')
	Use g: '\\' + $fileserver + '\Export'
EndIf

If InGroup('fso_r')
	Use r: '\\' + $fileserver + '\R'
EndIf

If InGroup('fso_tech')
	Use z: '\\' + $newtechsrv + '\Tech'
EndIf

If InGroup('fso_dwa')
	Use w: '\\' + $fileserver + '\D'
EndIf

If InGroup('fso_Rec')
	Use x: '\\' + $fileserver + '\Rec'
EndIf

If InGroup('fso_Re')
	Use x: '\\' + $fileserver + '\Performance\%USERNAME%'
EndIf

If InGroup('Non-Exempt Employees')
	Copy '\\DC01\NETLOGON\PunchINPunchOUT.url' '%USERPROFILE%\Start Menu\Programs\Startup\PunchINPunchOUT.url'
EndIf

If Exist('%USERPROFILE%\desktop\DatabaseCalender.lnk')
	Del '%USERPROFILE%\desktop\DatabaseCalender.lnk'
EndIf

If Not @wksta = "SQL" Or Not @wksta = "MAIL"
	If @wksta = "RIX01" Or @wksta = "RIX02"
		If @userid = "Administrator"
			$RC = WriteValue("HKEY_Current_user\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "StartMenuAdminTools", "NO", "REG_SZ")
		EndIf
	EndIf
	;Installs printers for everybody.
	If @wksta <> 'server'
		; Installing Printers...
		If InGroup("fso_tech")
			 ?"Mailroom printer install"
			If PriMapState('\\server\XWC120PS') = ''
				$RC = AddPrinterConnection('\\server\XWC120PS')
			EndIf
		EndIf
		For Each $Printer in $Printers
				If PriMapState($Printer) = ''
					$RC = AddPrinterConnection($Printer)
				EndIf
		Next
	EndIf
	;Changes setting for tabs in IE7 
	$RC = WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TabbedBrowsing", "ShortcutBehavior", "0", "REG_DWORD")
	
	;Turns Internet Explorer start page to blank, enables recover deleted items in Outlook, and sets IM and AutoArchive Preferences
	$RC = WriteValue("hkey_Current_user\Software\Microsoft\Internet Explorer\Main", "Window Title", "Provided by", "REG_SZ")
	$RC = WriteValue("hkey_Current_user\Software\Microsoft\Office\11.0\Outlook\IM", "Enabled", "0", "REG_DWORD")
	$RC = WriteValue("hkey_Current_user\Software\Microsoft\Office\11.0\Outlook\Preferences", "DoAging", "0", "REG_DWORD")
EndIf

;;;;;;;;;;;;;;;;;;;;;;;;
; Personal UDF Section ;
;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;
; UDF Section ;
;;;;;;;;;;;;;;;

; Do not forget to add the PriMapState UDF

function PriMapState($_Pri)
if @inwin=1
 if len(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices",$_Pri))
  if split(readvalue("HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),",")[0]=$_Pri
   $PriMapState=2
  else
   $PriMapState=1
  endif
 endif
else
 dim $_Root,$_C,$_C2 $_Root="HKLM\System\CurrentControlSet\control\Print\Printers"
 for $_C=0 to 259
  $_C2=enumkey($_Root,$_C)
  If instr(READVALUE($_Root+"\"+$_C2,"Port"),$_Pri)
   If instr(READPROFILESTRING("%windir%\win.ini","windows","device"),$_Pri)
    $PriMapState = 2
   Else
    $PriMapState = 1
   Endif
  Endif
  if $_C2=259 $_C=$_C2 endif
 next
endif
endfunction



Edited by amtagoran (2010-04-28 04:37 PM)

Top
#198470 - 2010-04-28 05:21 PM Re: Script sometimes hangs [Re: Gee]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
I am a noob so please I would appreciate any help.
Top
#198478 - 2010-04-28 06:26 PM Re: Script sometimes hangs [Re: Gee]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
Try giving yourself some information to work with. It's possible one of your printers does not exist.

 Code:
		For Each $Printer in $Printers
                ? $Printer
				If PriMapState($Printer) = ''
					$RC = AddPrinterConnection($Printer)
                                        ? @serror
				EndIf


Top
#198482 - 2010-04-28 06:48 PM Re: Script sometimes hangs [Re: Allen]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
I added the above script to my script and they all successfuly connect but for some printers it takes about 1 min to connect which is way too long.

Any suggestions.

Do you think i should download different drivers?

Top
#198483 - 2010-04-28 07:01 PM Re: Script sometimes hangs [Re: Gee]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
The long delay is the printer drivers reinstalling, which says to me the primapstate() is not doing its job.

Take a look at the example in Primapstate() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83306
and compare it to your code. It's possible the '' in your code is not working like expected.


Top
#198484 - 2010-04-28 07:06 PM Re: Script sometimes hangs [Re: Allen]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
The code is the exact same code on the above example. Is there anything else i should have when i have this code in place. (ex. maybe a .dll file). I am still pretty new at this.

Also some of the problematic PC's are running windows 7

Top
#198485 - 2010-04-28 07:08 PM Re: Script sometimes hangs [Re: Gee]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
Look at the example in the header of the UDF.
Top
#198487 - 2010-04-28 07:12 PM Re: Script sometimes hangs [Re: Allen]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
I don't understand can you please walk me through this.

Please excuse my misunderstanding

Top
#198488 - 2010-04-28 08:05 PM Re: Script sometimes hangs [Re: Gee]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Can you take a look at my above code and see what i am missing Please.
Top
#198495 - 2010-04-29 03:56 PM Re: Script sometimes hangs [Re: Gee]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Like I said before i did some testing and the script hangs on the printer part of the script. The weird thing is only 4 of the printers hang.
Top
#198496 - 2010-04-29 04:11 PM Re: Script sometimes hangs [Re: Gee]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Could be a printer driver issue.

Are the 4 problem printers using the same driver, and is different to the printers which don't cause a problem?

Do you get the same problem if you map the printers manually?

Top
#198498 - 2010-04-29 04:16 PM Re: Script sometimes hangs [Re: Richard H.]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
The only thing I notice is that the 4 drivers are Post script drivers.
Top
#198499 - 2010-04-29 04:19 PM Re: Script sometimes hangs [Re: Gee]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Also. Allen mentioned that maybe my UDF for the printer might not be functioning properly. Can anyone look at my above script and tell me if I am wording something wrong.

I appreciate any help

Top
#198504 - 2010-04-29 04:47 PM Re: Script sometimes hangs [Re: Gee]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 Originally Posted By: rich
Do you get the same problem if you map the printers manually?


Quite an important question that one.

If you map the printer manually and you get a similar delay then there is not much that you are going to be able to do with it scripting-wise other than avoiding the mapping in the first place.

If you cannot avoid the delay then one option is to split out the printer mapping and run it as a background task so that it doesn't hold up the main script. The printers will appear as the mappings complete, and in real terms it is rarely a problem for the user if the printers appear three or four minutes after they've logged on.

Top
#198505 - 2010-04-29 05:16 PM Re: Script sometimes hangs [Re: Richard H.]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4563
Loc: USA
The Primapstate udf is supposed to check for existing printers so that it does not reinstall them. I'm assuming you are seeing it reinstall the driver since you having the delays. The point of displaying the printer name and @serror to the screen is if you see the @serror output after each printer name, it means it's installing the printer (over and over). This leads me to think that the way you using primapstate might not be working as expected.

In the header of the Primapstate UDF the example is
 Code:
EXAMPLE 

;		if not PriMapState('\\server\printer1') 

;		 "printer1 not connected!" 

;	        endif 



your code is
 Code:
If PriMapState($Printer) = ''


In your case try:
 Code:
if not PriMapState($Printer)


This may not fix it, but it's what I was suggesting above.


Edited by Allen (2010-04-29 05:23 PM)

Top
#198506 - 2010-04-29 06:00 PM Re: Script sometimes hangs [Re: Allen]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Allen, thanks for your input. I did what you suggested and it seems like PCs running XP, the script runs a little quicker. Thanks alot.

But for some reason the issue persists on Windows 7 PC's. Is there anything i need to do for the WIN7 users to make the script not hang. I already have UAC turned off.

Any suggestions.

Thanks,

Top
#198528 - 2010-05-03 07:58 PM Re: Script sometimes hangs [Re: Gee]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Anyone have any further inputs on this?

I would really appreciate it.

Top
#198533 - 2010-05-04 12:31 AM Re: Script sometimes hangs [Re: Gee]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Had the same issue with Win7 and installing printers. We only have 3 Win7 systems (IT only), the rest is XP and have no issues.

I'll post my printer mapping script (I'm also using PriMapState) tomorrow when I'm back in the office (around 0:30 AM here now).

The only issue I have now is the “Do you trust this printer” pop up box that comes up when installing a printer that has never been installed before.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#198537 - 2010-05-04 09:11 AM Re: Script sometimes hangs [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Hmmmmm...reading through my script and it is not so much different than the way you use PriMapState. The only thing is that I check if the printer exists like this:

 Code:
;Set printer name.
$printer = "\\" + $printerserver + "\Printer1"
;Check group membership.
If InGroup("GROUPNAME")
	;Check if the printer is already installed.
	If Not PriMapState($printer)
		;Printer is not installed. Add printer.		
		$rc = AddPrinterConnection($printer)
	EndIf
EndIf


I did update the drivers on the server to support Windows 7.


Edited by Mart (2010-05-04 09:14 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#198542 - 2010-05-04 03:52 PM Re: Script sometimes hangs [Re: Mart]
Gee Offline
Fresh Scripter

Registered: 2009-02-04
Posts: 48
Loc: illinois
Mart, thanks for your input. When you updated the drivers did your script run a little faster on the Win7 machines?
Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 778 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.077 seconds in which 0.028 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org