473,789 Members | 2,602 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading from a ini-file and run a program

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-Neuling
doch 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
Nov 21 '05 #1
3 2501
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
.

Nov 21 '05 #2
"Nijazi Halimaji" <sp***@gmx.ne t> schrieb:
Eigentlich ist das ja etwas ganz einfaches, aber für mich als
VB.NET-Neuling
doch etwas komplizierter.

1. How can I read and write value from / into a ini-file?
Storing and loading user preferences
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=userprefere nces&lang=en>
2. How can I run a file (exe, doc, etc.)


Opening files, applications, Web documents, and the mail client
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=openfileapp webpage&lang=en >

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Herfried,
"Nijazi Halimaji" <sp***@gmx.ne t> schrieb:
Eigentlich ist das ja etwas ganz einfaches, aber für mich als
VB.NET-Neuling
doch etwas komplizierter.

I saw it, in German do they know that this is your most favorite question

:-)

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4603
by: furry | last post by:
I'm trying to set the PHP include path for a PHP class on my web host, but I don't have access to the root php.ini. My host allows me to have my own php.ini which applies to each directory it appears in but it seems I need to have a php.ini in each and every directory I want my include path to apply in. I would rather avoid having a php.ini in each directory, since it's a class I use all over my site (phpMailer - excellent multipart...
4
32539
by: Edo van der Zouwen | last post by:
Hi, This is the error: Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in c:\lserver\test\sendform.php on line 10 This is the code:
6
1884
by: aa | last post by:
Is it possible to enforce changed in php.ini without re-booting (w2k)?
1
1286
by: Bit Twiddler | last post by:
Does the BCL have built-in support for reading/writing standard ini files? Thanks! BT
5
10604
by: Oleg Subachev | last post by:
Are there good classes to work with .INI-files from C# ? Oleg Subachev
2
4667
by: Eric Layman | last post by:
I have checked this setting in my php.ini allow_url_fopen = On It is ON be default. According to the PHP documentation: it stated that as of php5, filesize supports the reading of remote html files:
4
14276
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
6
2548
by: DT | last post by:
Hello, I'm writing php extension to read php.ini settings from independent location, particularly some object or relational database, or, sleepycat db. PHP ini development concept seems pretty straightforward to me, anyway I can't figure out how to make a php.ini setting to be "admin value", e.g. not changeable with ini_set() function from within php script, whatever
29
17622
by: Guillaume Dargaud | last post by:
Hello all, anybody knows if there's some ANSI-C conformant code around that can read Windows-style .ini files ? I don't care about writing to it but I need to be able to read it from various OSs, so there shouldn't be any Windows includes. It doesn't look like it's too hard to do, but there are a few tricks (like multiple line strings), so I'd love to save some time (who doesn't). -- Guillaume Dargaud
25
2924
by: =?Utf-8?B?VG9tbXkgTG9uZw==?= | last post by:
I know how to do it in VB6, I have code snippets coming out my ears for VB6, but with the new framework in Visual Studio 2005, how do you get/put from a ..INI If I attempt to use a VB6 snippet in Studio 05 it whinges about using the 'as Any' type in my declarations, and it whinges about using the String$() function when creating a buffer string variable. Infact, it whinges a whole lot, why my employer got VS05 I'll never know. :( ...
0
9657
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9502
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10400
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9010
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6754
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5412
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5544
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3688
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2902
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.