Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for netshare.cmd

(view source code of netshare.cmd as plain text)

  1. /* List shared netnames on a server */
  2.  
  3. call RxFuncAdd 'LoadLsRxutFuncs', 'LSRXUT', 'LoadLsRxutFuncs'
  4. call LoadLsRxutFuncs
  5.  
  6. NETSERVER = 160
  7. NETSHARE  = 190
  8. SrvType   = -1  /* All servers */
  9.  
  10. parse upper arg SrvName DomainName dummy "/"pause
  11. if SrvName = '' then call Syntax
  12. if left( SrvName, 2 ) <> '\\' then do
  13. 	DomainName = SrvName
  14. 	SrvName    = ''
  15. end
  16. if left( pause, 1 ) = "P" then do
  17. 	pause = 1
  18. 	parse value SysTextScreenSize( ) with rows cols
  19. end
  20. else do
  21. 	pause = 0
  22. end
  23.  
  24. myRc = NetEnumerate(NETSERVER, 'serverList', SrvName, SrvType, DomainName)
  25. if myRc <> '0' then do
  26. 	say 'Got error from NetEnumerate() ' myRc
  27. 	exit 9
  28. end
  29.  
  30. if serverList.0 = 0 then do
  31. 	say 'Domain controller was not found'
  32. 	exit 0
  33. end
  34.  
  35. call SysCls
  36. say
  37. say 'Number of servers found: ' serverList.0
  38.  
  39. k = 0
  40. do i=1 to serverList.0
  41. 	say
  42. 	say
  43. 	say serverList.i
  44. 	myRc = NetEnumerate(NETSHARE, 'shareInfo', '\\'serverList.i)
  45. 	if myRc <> '0' then do
  46. 		say 'Got error from NetEnumerate() ' myRc
  47. 		exit 9
  48. 	end
  49. 	if shareInfo.1 = 0 then do
  50. 		say 'Server does not share a resource'
  51. 		exit 0
  52. 	end
  53. 	say 'Number of shared netnames: ' shareInfo.0
  54. 	say
  55. 	do j=1 to shareInfo.0
  56. 		myRc = NetGetInfo(NETSHARE, 'shareInfoX', '\\'serverList.i, shareInfo.j)
  57. /*
  58. 		myRc = NetGetInfo(NETSHARE, 'shareInfoX', SrvName, shareInfo.j)
  59. */
  60. 		if myRc <> '0' then do
  61. 			say 'Got error from NetGetInfo() ' myRc
  62. 			exit 9
  63. 		end
  64. 		say
  65. 		say '    Network name        :  ' shareInfoX.netname
  66. 		say '    Share type          :  ' shareInfoX.type
  67. 		say '    Comment             :  ' shareInfoX.remark
  68. 		say '    Local resource path :  ' shareInfoX.path
  69. 		if pause = 1 then call PauseIfNeeded
  70. 	end
  71. end
  72. if k > 0 then call PauseIfNeeded 'Exit'
  73. EXIT 0
  74.  
  75.  
  76. PauseIfNeeded:
  77. 	param = strip( translate( arg( 1 ) ) )
  78. 	parse value SysCurPos( ) with x y
  79. 	k = k + 1
  80. 	if x > rows - 8 | param = 'EXIT' then do
  81. 		call SysCurPos rows - 3, 0
  82. 		say 'Press any key . . .'
  83. 		call SysCurState 'OFF'
  84. 		call SysGetKey 'NOECHO'
  85. 		if param <> "EXIT" then do
  86. 			call SysCls
  87. 			say
  88. 			say 'Number of servers found: ' serverList.0
  89. 			say
  90. 			say
  91. 			say serverList.i
  92. 			say 'Number of shared netnames: ' shareInfo.0
  93. 			say
  94. 		end
  95. 		k = 0
  96. 	end
  97. return
  98.  
  99.  
  100. Syntax: procedure
  101. 	say
  102. 	say 'Usage: NETSHARE [ \\server_name ] [ domain_name ] [ /Pause ]'
  103. 	say
  104. 	exit 1
  105. return
  106.  

page last modified: 2024-04-16; loaded in 0.0180 seconds