Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for kixini.vbs

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

  1. Option Explicit
  2.  
  3. Dim blnWrite
  4. Dim objFSO, objKiXtart, objScript, wshShell
  5. Dim strAction, strINI, strKey, strScript, strSection, strTemp, strValue
  6.  
  7. ' Parse command line
  8. With WScript.Arguments
  9. 	If .Named.Count   > 0 Then Syntax
  10. 	If .Unnamed.Count < 3 Then Syntax
  11. 	If .Unnamed.Count > 4 Then Syntax
  12. 	strINI     = .Unnamed(0)
  13. 	strSection = .Unnamed(1)
  14. 	strKey     = .Unnamed(2)
  15. 	If .Unnamed.Count = 4 Then
  16. 		strValue = .Unnamed(3)
  17. 		blnWrite = True
  18. 	Else
  19. 		blnWrite = False
  20. 	End If
  21. End With
  22.  
  23. ' Get %TEMP% path
  24. Set wshShell = CreateObject( "Wscript.Shell" )
  25. strTemp = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
  26. Set wshShell = Nothing
  27.  
  28. Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  29. With objFSO
  30. 	' Check if specified INI file exists
  31. 	If Not .FileExists( strINI ) Then
  32. 		Set objFSO = Nothing
  33. 		Syntax
  34. 	End If
  35. 	' Create temporary KiXtart script
  36. 	strScript = .BuildPath( strTemp, "_ReadINI.kix" )
  37. 	Set objScript = .CreateTextFile( strScript, True, False )
  38. 	objScript.WriteLine "If $Write"
  39. 	objScript.WriteLine vbTab & "$RC = WriteProfileString( $INIFile, $INISection, $INIKey, $INIValue )"
  40. 	objScript.WriteLine "EndIf"
  41. 	objScript.WriteLine "$RC = ReadProfileString( $INIFile, $INISection, $INIKey )"
  42. 	objScript.Close
  43. 	Set objScript = Nothing
  44. End With
  45.  
  46. ' Create KiXtart object
  47. On Error Resume Next
  48. Set objKiXtart = CreateObject( "KiXtart.Application" )
  49. 'If Err Then Syntax True
  50. On Error Goto 0
  51.  
  52. ' Run temporary KiXtart script
  53. With objKiXtart
  54. 	.SetVar "INIFile", strINI
  55. 	.SetVar "INISection", strSection
  56. 	.SetVar "INIKey", strKey
  57. 	If blnWrite Then
  58. 		.SetVar "INIValue", strValue
  59. 		.SetVar "Write", True
  60. 	Else
  61. 		.SetVar "Write", False
  62. 	End If
  63. 	.RunScript strScript
  64. 	strValue = .GetVar( "RC" )
  65. End With
  66. Set objKiXtart = Nothing
  67.  
  68. WScript.Echo strValue
  69.  
  70.  
  71. Sub Syntax( )
  72. 	Dim strMsg
  73. 	strMsg = "KixINI.vbs,  Version 1.00" & vbCrLf _
  74. 	       & "Use KiXtart COM object to read or write INI files" & vbCrLf & vbCrLf _
  75. 	       & "Usage:" & vbTab & "KIXINI.VBS  INIFile  INISection  INIKey  [ INIValue  ]" & vbCrLf & vbCrLf _
  76. 	       & "Where:" & vbTab & "INIFile, INISection and INIKey are the INI file, section and key" & vbCrLf _
  77. 	       & vbTab & "respectively." & vbCrLf _
  78. 	       & vbTab & "INIValue is the optional new value; if it is specified, it will be" & vbCrLf _
  79. 	       & vbTab & "written to, otherwise the value will be read from the INI file." & vbCrLf & vbCrLf _
  80. 	       & "Notes:" & vbTab & "The script can read, write and create values, but not delete them." & vbCrLf _
  81. 	       & vbTab & "KIXTART.DLL must be registered for this script to work." & vbCrLf & vbCrLf _
  82. 	       & "Written by Rob van der Woude" & vbCrLf _
  83. 	       & "http://www.robvanderwoude.com"
  84. 	WScript.Echo strMsg
  85. 	WScript.Quit 1
  86. End Sub
  87.  

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