×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

Get variable from ini

Get variable from ini

Get variable from ini

(OP)
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:

[Logon_Details]
userid=user1
password=password1

My code is below

CODE


[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)
dim struserid, strpassword

REM This line calls the macro subroutine
subAWDPrty_

sub subAWDPrty_()
Dim Strinput
   autECLSession.autECLOIA.WaitForAppAvailable


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

autECLSession.autECLPS.SendKeys USERID VARIABLE FROM INI


   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "    "

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

autECLSession.autECLPS.SendKeys PASSWORD VARIABLE FROM INI


   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[ENTER]"
   autECLSession.autECLOIA.WaitForInputReady


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

Tim

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
Const MUTEX_ALL_ACCESS = 2
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.Show
    frmBusySplash.lblBusyCaption = "Loading APP"
    frmBusySplash.Refresh
    
    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
        Else
            '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
            Wend
            '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
        Else
            Module2String = "I:\APP32\Module2.exe " + strLocalAccountNo
        End If
    Else
        Module2String = "I:\APP32\Module2.exe "
    End If

    'Call the enquiry module
    Shell Module2String
btnCallAPPlusExit:
    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

(OP)
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

Thanks

Tim

RE: Get variable from ini

try this

CODE

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
Sam

Sam

RE: Get variable from ini

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

Tim

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

Sam

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!

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