Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for printers.kix

(view source code of printers.kix as plain text)

  1. ; Printers.kix,  Version 1.12
  2. ; Written by Rob van der Woude
  3. ; http://www.robvanderwoude.com
  4. ; DefPrt subroutine written by Adriaan Westra
  5. ; http://www.westra.speedlinq.nl/
  6. ; Kix script to map LPT ports to network printers
  7. ; using a personal configuration file (INI format)
  8. ; Tested in Windows NT 4 SP5 only
  9. ;
  10. ; Sample printers.ini:
  11. ; [Mappings]
  12. ; LPT2=\\server\printershare
  13. ; LPT3=/DEL
  14. ;
  15. ; LPT1 not specified: map to default printer
  16. ; Value /DEL: any existing mapping will be deleted
  17. ;
  18.  
  19. ; Hide script execution
  20. SETCONSOLE( "HIDE" )
  21.  
  22. ; Specify path for printers.ini here:
  23. $INI = "H:\PRINTERS.INI"
  24.  
  25. ; Check if INI file exists
  26. IF EXIST( $INI )
  27. 	; Read printer mapping for all ports specified
  28. 	$LPT1 = READPROFILESTRING( $INI, "Mappings", "LPT1" )
  29. 	$LPT2 = READPROFILESTRING( $INI, "Mappings", "LPT2" )
  30. 	$LPT3 = READPROFILESTRING( $INI, "Mappings", "LPT3" )
  31. 	$LPT4 = READPROFILESTRING( $INI, "Mappings", "LPT4" )
  32. 	$LPT5 = READPROFILESTRING( $INI, "Mappings", "LPT5" )
  33. 	$LPT6 = READPROFILESTRING( $INI, "Mappings", "LPT6" )
  34. 	$LPT7 = READPROFILESTRING( $INI, "Mappings", "LPT7" )
  35. 	$LPT8 = READPROFILESTRING( $INI, "Mappings", "LPT8" )
  36. ENDIF
  37. ; Delete existing mapping
  38. USE LPT1: /DEL /PERSISTENT
  39. ; If LPT1 is specified
  40. IF $LPT1
  41. 	; Display value read from INI file
  42. 	? "LPT1 = " + $LPT1
  43. 	; Map to network printer unless /DEL was specified
  44. 	IF $LPT1 <> "/DEL"
  45. 		USE LPT1: $LPT1
  46. 	ENDIF
  47. ELSE
  48. 	; Map to default printer if LPT1 was not specified
  49. 	GOSUB "DefPrt"
  50. ENDIF
  51. ; Except for the default printer mapping,
  52. ; do the same for LPT2 through LPT8
  53. IF $LPT2
  54. 	? "LPT2 = " + $LPT2
  55. 	USE LPT2: /DEL /PERSISTENT
  56. 	IF $LPT2 <> "/DEL"
  57. 		USE LPT2: $LPT2
  58. 	ENDIF
  59. ENDIF
  60. IF $LPT3
  61. 	? "LPT3 = " + $LPT3
  62. 	USE LPT3: /DEL /PERSISTENT
  63. 	IF $LPT3 <> "/DEL"
  64. 		USE LPT3: $LPT3
  65. 	ENDIF
  66. ENDIF
  67. IF $LPT4
  68. 	? "LPT4 = " + $LPT4
  69. 	USE LPT4: /DEL /PERSISTENT
  70. 	IF $LPT4 <> "/DEL"
  71. 		USE LPT4: $LPT4
  72. 	ENDIF
  73. ENDIF
  74. IF $LPT5
  75. 	? "LPT5 = " + $LPT5
  76. 	USE LPT5: /DEL /PERSISTENT
  77. 	IF $LPT5 <> "/DEL"
  78. 		USE LPT5: $LPT5
  79. 	ENDIF
  80. ENDIF
  81. IF $LPT6
  82. 	? "LPT6 = " + $LPT6
  83. 	USE LPT6: /DEL /PERSISTENT
  84. 	IF $LPT6 <> "/DEL"
  85. 		USE LPT6: $LPT6
  86. 	ENDIF
  87. ENDIF
  88. IF $LPT7
  89. 	? "LPT7 = " + $LPT7
  90. 	USE LPT7: /DEL /PERSISTENT
  91. 	IF $LPT7 <> "/DEL"
  92. 		USE LPT7: $LPT7
  93. 	ENDIF
  94. ENDIF
  95. IF $LPT8
  96. 	? "LPT8 = " + $LPT8
  97. 	USE LPT8: /DEL /PERSISTENT
  98. 	IF $LPT8 <> "/DEL"
  99. 		USE LPT8: $LPT8
  100. 	ENDIF
  101. ENDIF
  102. QUIT
  103.  
  104.  
  105. ; DefPrt subroutine, written by Adriaan Westra, http://people.a2000.nl/awestra
  106. :DefPrt
  107. 	; Read default printer string from registry
  108. 	$SUBKEY = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
  109. 	$VALUE  = READVALUE( $SUBKEY, "Device" )
  110. 	; Parse UNC only from string
  111. 	$OFFSET = INSTR( $VALUE, "," )
  112. 	$LEN    = $OFFSET - 1
  113. 	$LPT1   = SUBSTR( $VALUE, 1, $LEN )
  114. 	; Display UNC value found
  115. 	? "LPT1 = " + $LPT1 + " (Default Printer)"
  116. 	; Actual mapping
  117. 	USE LPT1: $LPT1
  118. RETURN
  119.  

page last uploaded: 2017-08-21, 14:26