Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getdde.vbs

(view source code of getdde.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim arrAssoc, arrKeys, arrSubKeys
  4. Dim blnFullCmdOnly
  5. Dim i, intValidArgs, j
  6. Dim objDic, objReg
  7. Dim strCommand, strDDEApp, strDDEExec, strDDETopic
  8. Dim strFileType, strKey, strSubKey, strSubSubKey
  9.  
  10. Const HKCR = &H80000000
  11.  
  12. blnFullCmdOnly = False
  13. intValidArgs   = 0
  14.  
  15. ' No command line arguments required
  16. With WScript.Arguments
  17. 	If .Unnamed.Count > 0 Then Syntax
  18. 	If .Named.Count   > 0 Then
  19. 		If .Named.Exists( "H" ) Then
  20. 			intValidArgs = intValidArgs + 1
  21. 			WScript.Echo "Extension"          & vbTab _
  22. 			           & "File Type"          & vbTab _
  23. 			           & "Shell Command"      & vbTab _
  24. 			           & "DDE Server Command" & vbTab _
  25. 			           & "DDE Application"    & vbTab _
  26. 			           & "DDE Topic"          & vbTab _
  27. 			           & "DDE Client Command"
  28. 		End If
  29. 		If .Named.Exists( "F" ) Then
  30. 			intValidArgs   = intValidArgs + 1
  31. 			blnFullCmdOnly = True
  32. 		End If
  33. 		If intValidArgs <> .Named.Count Then Syntax
  34. 	End If
  35. End With
  36.  
  37. Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv" )
  38. Set objDic = CreateObject( "Scripting.Dictionary" )
  39.  
  40. ' List all keys in the HKEY_CLASSES_ROOT hive
  41. objReg.EnumKey HKCR, "", arrKeys
  42.  
  43. For i = 0 To UBound( arrKeys )
  44. 	' Store registered extensions and their associated file types in a dictionary
  45. 	If Left( arrKeys(i), 1 ) = "." Then
  46. 		objReg.GetStringValue HKCR, arrKeys(i), "", strFileType
  47. 		objDic.Item( strFileType) = arrKeys(i)
  48. 	End If
  49. 	' Check if any commands are available for a file type
  50. 	strSubKey = arrKeys(i) & "\shell"
  51. 	objReg.EnumKey HKCR, strSubKey, arrSubKeys
  52. 	If IsArray( arrSubKeys ) Then
  53. 		For j = 0 To UBound( arrSubKeys )
  54. 			strSubSubKey = arrKeys(i) & "\shell\" & arrSubKeys(j) & "\ddeexec"
  55. 			objReg.GetStringValue HKCR, strSubSubKey, "", strDDEExec
  56. 			' DDE commands only
  57. 			If IsNull( strDDEExec ) Then Exit For
  58. 			strSubSubKey = arrKeys(i) & "\shell\" & arrSubKeys(j) & "\command"
  59. 			objReg.GetStringValue HKCR, strSubSubKey, "", strCommand
  60. 			strSubSubKey = arrKeys(i) & "\shell\" & arrSubKeys(j) & "\ddeexec\Application"
  61. 			objReg.GetStringValue HKCR, strSubSubKey, "", strDDEApp
  62. 			strSubSubKey = arrKeys(i) & "\shell\" & arrSubKeys(j) & "\ddeexec\Topic"
  63. 			objReg.GetStringValue HKCR, strSubSubKey, "", strDDETopic
  64. 			If blnFullCmdOnly Then
  65. 				If IsNull( strDDEApp   ) Then Exit For
  66. 				If IsNull( strDDETopic ) Then Exit For
  67. 			End If
  68. 			' Display the DDE commands
  69. 			strFileType = Split( strSubSubKey, "\" )(0)
  70. 			WScript.Echo objDic.Item( strFileType ) & vbTab _
  71. 			           & strFileType   & vbTab _
  72. 			           & arrSubKeys(j) & vbTab _
  73. 			           & strCommand    & vbTab _
  74. 			           & strDDEApp     & vbTab _
  75. 			           & strDDETopic   & vbTab _
  76. 			           & strDDEExec
  77. 		Next
  78. 	End If
  79. 	arrSubKeys = ""
  80. Next
  81.  
  82. Set objDic = Nothing
  83. Set objReg = Nothing
  84.  
  85.  
  86. Sub Syntax
  87. 	WScript.Echo vbCrLf _
  88. 	           & "GetDDE.vbs,  Version 1.00" _
  89. 	           & vbCrLf _
  90. 	           & "List DDE commands for all registered file types" _
  91. 	           & vbCrLf & vbCrLf _
  92. 	           & "Usage:  CSCRIPT.EXE  //NoLogo  GETDDE.VBS  [ /F ]  [ /H ]" _
  93. 	           & vbCrLf & vbCrLf _
  94. 	           & "Where:  /F    list fully defined DDE commands only, i.e. if either the DDE" _
  95. 	           & vbCrLf _
  96. 	           & "              Application or Topic is not defined, it will not be displayed." _
  97. 	           & vbCrLf _
  98. 	           & "        /H    display a header line." _
  99. 	           & vbCrLf & vbCrLf _
  100. 	           & "Note:   Only one file extension will be listed for each registered file type." _
  101. 	           & vbCrLf & vbCrLf _
  102. 	           & "Written by Rob van der Woude" _
  103. 	           & vbCrLf _
  104. 	           & "http://www.robvanderwoude.com"
  105. 	WScript.Quit 1
  106. End Sub
  107.  

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