Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Get variable from ini

Get variable from ini

Get variable from ini

Hi All

I have created a vb script in PCOMM which logs on and pulls back data from an AS400. What I want it to do is to take data from an ini file which contains the username and password to logon.

Here is the ini:


My code is below


dim struserid, strpassword

REM This line calls the macro subroutine

sub subAWDPrty_()
Dim Strinput

    rem strInput = InputBox ( "Please enter your user ID", "User ID")
    rem autECLSession.autECLPS.SendKeys strInput


   autECLSession.autECLPS.SendKeys "    "

    rem strInput = InputBox ( "Please enter your password ", "Password")
    rem autECLSession.autECLPS.SendKeys strInput


   autECLSession.autECLPS.SendKeys "[ENTER]"

How do I do it??

This has been confusing me for a while.

If possible aswell csn you show me how to write back to the ini aswell?

All help and advise is appreciated

Many Thanks


RE: Get variable from ini

This is how I do it in VB:

Writeinivalue and readinivalue are the bits you're interested in:

Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function OpenMutex Lib "kernel32" Alias "OpenMutexA" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal lpName 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

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 Sub btnCallApp(strLocalAccountNo As String, strLocalBranchCode As String)
    Dim APPlusHandle As Long
    Dim WindowName As String
    Dim ShellResult As Long
    Dim i As Long
    Dim Module2String As String
    Dim strDrivePath As String
    Dim strResults As String
    strResults = Dir$("C:\WINNT\APP.ini")
    If strResults = "" Then
        MsgBox "Cannot launch APP - ini file missing"
    End If
    frmBusySplash.lblBusyCaption = "Loading APP"
    strDrivePath = GetBranchPath(strLocalBranchCode)
    strDrivePath = Left(strDrivePath, (InStr(strDrivePath, "BMPC\") + 3))
    Call WriteIniValue("Databases", "DrivePath", strDrivePath)
    Call WriteIniValue("Databases", "Bankbranch", Mid(strLocalBranchCode, 3, 2))
    'See if BM+ Menu is running
    WindowName = "TfrmMainMenu"
    BMPlusHandle = FindWindow(WindowName, vbNullString)
    'Check result
    If APPlusHandle = 0 Then
        'Start up APP
        ShellResult = Shell("I:\APP32\MENU.EXE")
        If ShellResult = 0 Then
            MsgBox "Unable to Start APP"    'Report unable to start menu
            GoTo btnCallAPPExit          'get out
            'wait for APP menu to start
            i = 0
            While (i < 20000) And (APPlusHandle = 0)
                'look to see if APP has started
                APPlusHandle = FindWindow(WindowName, vbNullString)
                i = i + 1
            'if APP did not start then warn and exit
            If APPlusHandle = 0 Then
                MsgBox "APP did not start"
                GoTo btnCallAPPlusExit
            End If
        End If
    End If
    'if we get here then APP is running so start module 2 - build the start string
    If strLocalAccountNo <> Space(0) Then
        If Len(strLocalAccountNo) > 6 Then
            Module2String = "I:\APP32\Module2.exe " + Mid(strLocalAccountNo, 6, 6) + " " + strLocalAccountNo
            Module2String = "I:\APP32\Module2.exe " + strLocalAccountNo
        End If
        Module2String = "I:\APP32\Module2.exe "
    End If

    'Call the enquiry module
    Shell Module2String
    Unload frmBusySplash
End Sub

Public Function ReadIniValue(strSection As String, strElement As String) As String

Dim iret As Long            'Return Code
Dim retStr As String * 30   'Return String -> Answer is in it
Dim strdisplay As String

  iret = GetPrivateProfileString(strSection, strElement, "Default", retStr, 30, "c:\WINNT\APP.ini")
  ReadIniValue = "Return Code: " & iret & vbCrLf & "Return String: " & retStr

End Function

Public Function WriteIniValue(strSection As String, strElement As String, strValue As String) As String
Dim iret As Long          'return code
  iret = WritePrivateProfileString(strSection, strElement, strValue, "c:\WINNT\APP.ini")
  WriteIniValue = "Return Code: " & iret
End Function

RE: Get variable from ini

Hi TomKane

I am having trouble understanding what bits to use in my code from yours. Could you give me a bit of info to help me adapt this to work in my code.

I gave it an attempt but Pcomm didnt seem to like the public functions. does all vbscript in different applications work the same?

This is the first time I have worked with vb script so you'll have to forgive me if I seem dull at any point. I do use visual basic coding in Access and vb 6 though so I have some understanding



RE: Get variable from ini

try this


dim fso
dim ts
dim strIni

set fso =  createobject("Scripting.FileSystemObject")
set ts = fso.Opentextfile("C:\Doc.ini")
strIni = ts.readall
msgbox strIni
Then you can parse the string or use the readline method to read each line individually


RE: Get variable from ini

Thanks sdraper, That was really helpful. I have now been able to get the data I wanted. Many thanks for your help.


RE: Get variable from ini

Glad to help. One addition. add the following lines at the end to cleanup resources.
set fso = Nothing
set ts = Nothing


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close