Jump to content
Sign in to follow this  

Any suggestions on converting this VBScript to an AutoIt script?

Recommended Posts


I have created some basic AutoIT scripts and need to convert this VBScript to AutoIT. I am not very familiar familiar with VBScript. Does anyone have any suggestions on where to start? I was experimenting with this below and am able to read the file. However I need to check for individual user IDs and then copy the corresponding ini file for that user ID. Should I use _FileReadToArray? Any suggestions are greatly appreciated.

$file = FileOpen("\\ecdcdbtextpms02\d$\Admin-Setup\SetUp\lookuptable.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
; Read in 1 character at a time until the EOF is reached
While 1
Local $chars = FileRead($file, 1)
If @error = -1 Then ExitLoop
MsgBox(0, "Char read:", $chars)

This is the VBScript:

set fso = createobject("scripting.filesystemobject")
set onet = createobject("wscript.network")
username = onet.UserName
Do while Mid(username,1,1) = "0"
username = Mid(username,2,len(username) - 1)

If not fso.FileExists("\\ecdcdbtextpms02\d\Admin-Setup\SetUp\lookuptable.txt") then
Wscript.echo "You must be connected to the network to complete the configuration of DB TextWorks"
End If
set inFile = fso.OpenTextFile("\\ecdcdbtextpms02\d\Admin-Setup\SetUp\lookuptable.txt",1,false)
userfound = "N"
do while not inFile.atEndOfStream and userfound = "N"
linevar = inFile.ReadLine()
uservar = Mid(linevar,1,InStr(linevar,vbTab) - 1)
If uservar = username then
inipos = InStr(linevar,vbTab)
inivar = Mid(linevar,inipos + 1,len(linevar) - inipos)
userfound = "Y"
End if
If userfound = "Y" then
fso.CopyFile inivar, "C:\Program Files\inmagic\inmagic.ini"
Wscript.echo "Your username was not found in the Security Table for DB TextWorks. Your configuration was not completed."
End If

Share this post

Link to post
Share on other sites

Looks like the file is tab delimited. Use _FileReadToArray to read in the file and then process in a For loop using StringSplit() to separate the user name from the INI file.

Share this post

Link to post
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
Sign in to follow this