Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ini and File Path Question.... 1

Status
Not open for further replies.

devilman0

IS-IT--Management
Nov 14, 2002
257
0
0
US
A. Can vbscript read inifiles? B. Can Vbscript use the api to read inifiles? C. If Vbscript can use the api to read inifiles, what is does the code look like. D. Can vbscript figure out where it is running?

Here is what i want to read.

[UpdatedFiles]
TraceyWindows#DLLNAME#=1.0.2

[CurrentUpdates]
Windows#DLLNAME#=1.0.3

i uses this file to check to see if my computers are up to date, and to automatically update them. Thanks,
James

 
My answer asumes that your VBSCript is not contained in an html page.
A : Yes, a Vbscript can read any kind of file.
B : As ini file have been replaced in recent Ms OS by registry, The API's that before read the ini files now search the registry. So I'm not sure that you'll find an API to access ini files in 9x, 2k or XP versions of Windows.
C : See B
D : yes : use
Code:
Wscript.ScriptFullName
that'll give you the full path of the VBS file currently running.

Note : To achieve what you want to do, I'd advice to choose beween these 2 solutions :
- Either you use registry to store your values.
- Or you open your ini file as a textStream using fileSystem object and you read it as a standard text file. Water is not bad as long as it stays out human body ;-)
 
In vb this is how you do it:
Code:
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long


'ini functions
Public Function WriteIni(ByVal HeaderName As Variant, Section As Variant, Value As Variant, PathToIni As String) As Variant
WriteIni = WritePrivateProfileString(CStr(HeaderName), CStr(Section), CStr(Value), PathToIni)
End Function

Public Function ReadIni(ByVal HeaderName As Variant, Section As Variant, PathToIni As Variant) As Variant
    Dim strReturn As String
    strReturn = String(255, Chr(0))
    ReadIni = Left$(strReturn, GetPrivateProfileString(CStr(HeaderName), ByVal CStr(Section), "", strReturn, Len(strReturn), CStr(PathToIni)))
End Function
i was hoping that there was a way in vbscript simular to this, it seems that it can only handle classes, i guess i'll make a dll in vb and call it from the script, the reason i want to use an ini file over the registry is
a) easy to modify
b) the script is on a network drive, all computers will access it (contains ips, unc paths, etc.) Thanks,
James

 
You can't use "Declare" statement in vbs. by the way if I can advice, I already try to create ActiveX objects in VB to call them in VBS (or HTML vbs scripts). I had many problems with it as it leads to many bugs if OS where you compile the dll is not exactly the same (with same registred DLL's) than the target OS.

By the way, did you think about using an XML file instead of an INI file. This way, you can easily access it using DOMDocument objects. Water is not bad as long as it stays out human body ;-)
 
Didn't even think about XML would be a lot eaiser (and faster) than an ini, seeing that windows would do all the work, and i wouldn't need to code an external control.
thanks Targol Thanks,
James
[shadeshappy] [evil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top