Here is code for Writing ini files
Public Class IniFile
' API functions
Private Declare Ansi Function GetPrivateProfi leString _
Lib "kernel32.d ll" Alias "GetPrivateProf ileStringA" _
(ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedStrin g As System.Text.Str ingBuilder, _
ByVal nSize As Integer, ByVal lpFileName As String) _
As Integer
Private Declare Ansi Function WritePrivatePro fileString _
Lib "kernel32.d ll" Alias "WritePrivatePr ofileStringA" _
(ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Integer
Private Declare Ansi Function GetPrivateProfi leInt _
Lib "kernel32.d ll" Alias "GetPrivateProf ileIntA" _
(ByVal lpApplicationNa me As String, _
ByVal lpKeyName As String, ByVal nDefault As Integer, _
ByVal lpFileName As String) As Integer
Private Declare Ansi Function FlushPrivatePro fileString _
Lib "kernel32.d ll" Alias "WritePrivatePr ofileStringA" _
(ByVal lpApplicationNa me As Integer, _
ByVal lpKeyName As Integer, ByVal lpString As Integer, _
ByVal lpFileName As String) As Integer
Dim strFilename As String
' Constructor, accepting a filename
Public Sub New(ByVal Filename As String)
strFilename = Filename
End Sub
' Read-only filename property
ReadOnly Property FileName() As String
Get
Return strFilename
End Get
End Property
Public Function GetString(ByVal Section As String, _
ByVal Key As String, ByVal [Default] As String) As
String
' Returns a string from your INI file
Dim intCharCount As Integer
Dim objResult As New System.Text.Str ingBuilder(256)
intCharCount = GetPrivateProfi leString(Sectio n, Key, _
[Default], objResult, objResult.Capac ity,
strFilename)
If intCharCount > 0 Then GetString = _
Left(objResult. ToString, intCharCount)
End Function
Public Function GetInteger(ByVa l Section As String, _
ByVal Key As String, ByVal [Default] As Integer) As
Integer
' Returns an integer from your INI file
Return GetPrivateProfi leInt(Section, Key, _
[Default], strFilename)
End Function
Public Function GetBoolean(ByVa l Section As String, _
ByVal Key As String, ByVal [Default] As Boolean) As
Boolean
' Returns a boolean from your INI file
Return (GetPrivateProf ileInt(Section, Key, _
CInt([Default]), strFilename) = 1)
End Function
Public Sub WriteString(ByV al Section As String, _
ByVal Key As String, ByVal Value As String)
' Writes a string to your INI file
WritePrivatePro fileString(Sect ion, Key, Value,
strFilename)
Flush()
End Sub
Public Sub WriteInteger(By Val Section As String, _
ByVal Key As String, ByVal Value As Integer)
' Writes an integer to your INI file
WriteString(Sec tion, Key, CStr(Value))
Flush()
End Sub
Public Sub WriteBoolean(By Val Section As String, _
ByVal Key As String, ByVal Value As Boolean)
' Writes a boolean to your INI file
WriteString(Sec tion, Key, CStr(CInt(Value )))
Flush()
End Sub
Private Sub Flush()
' Stores all the cached changes to your INI file
FlushPrivatePro fileString(0, 0, 0, strFilename)
End Sub
End Class
writing the following code to use it
Dim objIniFile As New IniFile("c:\dat a.ini")
objIniFile.Writ eString("Settin gs", "ClockTime" , "12:59")
Dim strData As String = _
objIniFile.GetS tring("Settings ", "ClockTime" , "(none)")
To run an application from .NET using the following code
Process.Start(" NotePad.exe")
-----Original Message-----
Hi
I know that what I am asking for is very simple, but as a
newbie in VB.NET i have following 2 questions:
Eigentlich ist das ja etwas ganz einfaches, aber für mich
als VB.NET-Neulingdoch etwas komplizierter.
1. How can I read and write value from / into a ini-file?
2. How can I run a file (exe, doc, etc.)
Thanks for every help
Nijazi Halimaji
.