Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for scsi.rex

(view source code of scsi.rex as plain text)

  1. /* SCSI.rex                     */
  2. /* List all SCSI and IDE drives */
  3.  
  4. /* Empty line */
  5. Say
  6.  
  7. /* Check command line arguments (none required) */
  8. If Arg( 1, "E" ) Then Call Syntax
  9.  
  10. /* Check OS version */
  11. Parse Upper Source os .
  12. If os <> "WIN32" Then Call Syntax "This Rexx script was not written for this Windows version"
  13.  
  14. /* Initialize W32Funcs */
  15. If RxFuncAdd( "w32loadfuncs", "W32Util", "w32loadfuncs" ) Then Do
  16. 	Call Syntax "Could not load W32Util Rexx extension"
  17. End
  18. Else Do
  19. 	Call w32loadfuncs
  20. End
  21.  
  22. /* Read SCSI ports from registry */
  23. porthandle = w32RegOpenKey( "HKEY_LOCAL_MACHINE", "HARDWARE\DEVICEMAP\Scsi" )
  24. If w32RegEnumKey( porthandle, , "port." ) Then Call Syntax
  25. Do i = 1 To port.0
  26. 	Parse Upper Value port.i With test1 test2 port
  27. 	If test1||" "||test2 = "SCSI PORT" Then Do
  28. 		Call ScsiPort port.i, i
  29. 	End
  30. 	Else Do
  31. 		Call Syntax "Invalid port name: "||port.i
  32. 	End
  33. End
  34. Call w32RegCloseKey porthandle
  35.  
  36. /* Done */
  37. Exit 0
  38.  
  39.  
  40. ScsiBus: Procedure
  41. 	port = Arg(1)
  42. 	bus  = Arg(2)
  43. 	type = Arg(3)
  44. 	/* Read target ID from registry */
  45. 	tidhandle = w32RegOpenKey( "HKEY_LOCAL_MACHINE", "HARDWARE\DEVICEMAP\Scsi\"||port||"\"||bus )
  46. 	If w32RegEnumKey( tidhandle, , "tid." ) = 0 Then Do
  47. 		Do i = 1 To tid.0
  48. 			Parse Upper Value tid.i With test1 test2 .
  49. 			If test1||" "||test2 = "TARGET ID" Then Do
  50. 				Call ScsiTid port, bus, tid.i, type
  51. 			End
  52. 		End
  53. 	End
  54. 	Call w32RegCloseKey tidhandle
  55. Return
  56.  
  57.  
  58. ScsiLId: procedure
  59. 	port = Arg(1)
  60. 	bus  = Arg(2)
  61. 	tid  = Arg(3)
  62. 	lid  = Arg(4)
  63. 	type = Arg(5)
  64. 	/* Read logical ID from registry */
  65. 	idhandle = w32RegOpenKey( "HKEY_LOCAL_MACHINE", "HARDWARE\DEVICEMAP\Scsi\"||port||"\"||bus||"\"||tid||"\"||lid )
  66. 	identifier = w32RegQueryValue( idhandle, "Identifier" )
  67. 	devtype    = w32RegQueryValue( idhandle, "Type"       )
  68. 	If devtype = "CdRomPeripheral" Then Do
  69. 		devicename = w32RegQueryValue( idhandle, "DeviceName" )
  70. 	End
  71. 	Else Do
  72. 		devicename = devtype
  73. 	End
  74. 	Call w32RegCloseKey idhandle
  75. 	id = SubStr( tid, 11 )
  76. 	Say port||", "||bus||", ID "||id||", "||type||", "||devicename||" = "||identifier
  77. Return
  78.  
  79.  
  80. ScsiPort: Procedure
  81. 	port = Arg(1)
  82. 	/* Read SCSI bus from registry */
  83. 	bushandle = w32RegOpenKey( "HKEY_LOCAL_MACHINE", "HARDWARE\DEVICEMAP\Scsi\"||port )
  84. 	bustype   = w32RegQueryValue( bushandle, "Driver" )
  85. 	If Translate( bustype ) = "ATAPI" Then Do
  86. 		bustype = "IDE"
  87. 	End
  88. 	Else Do
  89. 		bustype = "SCSI"
  90. 	End
  91. 	If w32RegEnumKey( bushandle, , "bus." ) Then Call Syntax
  92. 	Do i = 1 To bus.0
  93. 		Call ScsiBus port, bus.i, bustype
  94. 	End
  95. 	Call w32RegCloseKey bushandle
  96. Return
  97.  
  98.  
  99. ScsiTId: procedure
  100. 	port = Arg(1)
  101. 	bus  = Arg(2)
  102. 	tid  = Arg(3)
  103. 	type = Arg(4)
  104.  
  105. 	/* Read logical ID from registry */
  106. 	lidhandle = w32RegOpenKey( "HKEY_LOCAL_MACHINE", "HARDWARE\DEVICEMAP\Scsi\"||port||"\"||bus||"\"||tid )
  107. 	If w32RegEnumKey( lidhandle, , "lid." ) = 0 Then Do
  108. 		Do i = 1 To lid.0
  109. 			Parse Upper Value lid.i With test1 test2 test3 .
  110. 			If test1||" "||test2||" "||test3 = "LOGICAL UNIT ID" Then Do
  111. 				Call ScsiLid port, bus, tid, lid.i, type
  112. 			End
  113. 		End
  114. 	End
  115. 	Call w32RegCloseKey lidhandle
  116. Return
  117.  
  118.  
  119. Syntax:
  120. 	Parse Arg errdescr
  121. 	If errdescr <> "" Then Do
  122. 		Say errdescr
  123. 		Say
  124. 	End
  125. 	Say "SCSI.rex,  Version 1.00 for Windows 2000"
  126. 	Say "Enumerate SCSI and IDE drives"
  127. 	Say
  128. 	Say "Usage:  REGINA.EXE  SCSI.REX  [ /? ]"
  129. 	Say
  130. 	Say "Written by Rob van der Woude"
  131. 	Say "http://www.robvanderwoude.com"
  132. 	Exit 1
  133. Return
  134.  

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