Jump to content

Read ini with vbs using AutoItX


stev379
 Share

Recommended Posts

I have a vbs file to set an IP address. The IP address needs to be read from ini file. The ini file is used by AutoIT to read other info and using the same ini would make things easier.

I have basically no experience with Dll's.

Can anyone get me started on how I would use the AutoItX.dll to take advantage of AutoIt's IniRead so that the ini file can be read by a vbs file?

Sample ini:

[uSERNAME01]

Name=PERSON NUMBER ONE'S NAME SPACE

IP01=192.168.1.x11

IP02=192.168.1.x12

[uSERNAME02]

Name=PERSON NUMBER TWO'S NAME SPACE

IP01=192.168.1.x21

IP02=192.168.1.x22

Link to comment
Share on other sites

I just found this in the help file.

I can't remember if it is VBS syntax.

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
var = IniRead "C:\Temp\myfile.ini", "section2", "key", "NotFound"
WScript.Echo "Result: " & var
Link to comment
Share on other sites

I just found this in the help file.

I can't remember if it is VBS syntax.

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
var = IniRead "C:\Temp\myfile.ini", "section2", "key", "NotFound"
WScript.Echo "Result: " & var

<{POST_SNAPBACK}>

Thanks! I kept looking under "readini" instead of "iniread" in the help file.

Any clue why it errors (Expected end of statement) on line 2 char 15? I pointed it to the same ini that is read without error with a pure autoit script.

Edited by stev379
Link to comment
Share on other sites

You probably need to register the AutoIt DLL with regsvr32.exe

<{POST_SNAPBACK}>

I did that already and it succeeded. I tested with oAutoIt.iniwrite and oAutoIt.IniDelete and both work fine. If I remove the variable from the iniread vbs script it doesn't error but of course has no variable to output.

Whenever the variable is in place it gives the "Expected end of statement" error.

This is testing on a machine with AutoIt v3 installed and the AutoItX.dll registered.

I even unregistered AutoItX.dll and re-registered it again.

Any suggestions? :)

Link to comment
Share on other sites

I did that already and it succeeded.  I tested with oAutoIt.iniwrite and oAutoIt.IniDelete and both work fine.  If I remove the variable from the iniread vbs script it doesn't error but of course has no variable to output.

Whenever the variable is in place it gives the "Expected end of statement" error.

This is testing on a machine with AutoIt v3 installed and the AutoItX.dll registered.

I even unregistered AutoItX.dll and re-registered it again.

Any suggestions? :)

<{POST_SNAPBACK}>

I've got to be missing something here.

Can anybody test this to see if they are able to get the variable to work? This is the example copied from the AutoItX help file.

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
var = IniRead "C:\Temp\myfile.ini", "section2", "key", "NotFound"
WScript.Echo "Result: " & var

These all work fine with just autoIt but when the "AutoItX3.Control" from a vbs script. they all error with Expected end of statement.

Link to comment
Share on other sites

I knew it. You need the ( ) characters.

set var = IniRead("C:\Temp\myfile.ini", "section2", "key", "NotFound")

I just downloaded and registered the DLL. I fixed the code.

The following is working here:

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
var = oAutoIt.IniRead("C:\Temp\myfile.ini", "section2", "key", "NotFound")
WScript.Echo "Result: " & var
Edited by SlimShady
Link to comment
Share on other sites

I knew it.  You need the ( ) characters.

set var = IniRead("C:\Temp\myfile.ini", "section2", "key", "NotFound")

I just downloaded and registered the DLL. I fixed the code.

The following is working here:

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
var = oAutoIt.IniRead("C:\Temp\myfile.ini", "section2", "key", "NotFound")
WScript.Echo "Result: " & var

<{POST_SNAPBACK}>

Thanks! :)

very cool.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...