Jump to content

Replacing text in a file


Recommended Posts

Hey All... I am hoping someone can help me. I am trying to write a script to change a user name and password in a hummingbird quickscript for users that aren't tech savvy enough to open with notepad and change. I want to make a GUI for this that will look at a certain line in a (basically a .txt) file and read the username and allow the user to change it. I am trying to use something like below:

#include <GUIConstants.au3>
#include <File.au3>

GUICreate("XP Installer, ver 1", 400, 250)
GUISetFont(12)

GUICtrlCreateLabel("Please verify information:", 4, 4)
GUICtrlCreateLabel ("PC Name", 10,30)
GUICtrlCreateLabel ("User Name", 10,80)
GUICtrlCreateLabel ("Company", 10,130)
$put1 = GUICtrlCreateInput("", 100, 30, 200, 25)
$put2 = GUICtrlCreateInput("", 100, 80, 200, 25)
$put3 = GUICtrlCreateInput("", 100, 130, 200, 25)
$send = GUICtrlCreateButton("Save Changes", 4, 200, 120, 25)
$EXIT = GUICtrlCreateButton("Exit", 150 ,200, 120, 25)

GUISetState()

While  1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $send Then SendMyData ()
    If $msg = $EXIT then Exit
WEnd

Func SendMyData()
$filename = "L:\Documents\Autoit SAMPLES\great example files\replace text in a file\axe_login.qsv"
$find1 = "USERNAME"
$replace1 = GUICtrlRead($put1)
$find2 = "PASSWORD"
$replace2 = GUICtrlRead($put2)
$find3 = "OName"
$replace3 = GUICtrlRead($put3)

$retval1 = _ReplaceStringInFile($filename,$find1,$replace1)
$retval2 = _ReplaceStringInFile($filename,$find2,$replace2)
$retval3 = _ReplaceStringInFile($filename,$find3,$replace3)
MsgBox(0,'Info','Data written to quickscript file')
EndFunc

This is mostly a script from hirschy found http://www.autoitscript.com/forum/index.ph...place+text+file and it works great to replace just the tag given but I want it to read and only replace the username and password. Can anyone help me? I searched the Helpfile and found many occuernces for iniread/iniwrite and fileread/filewrite and such. Just not sure how to put them together.

here is my quickscript file

[Info]
Version=3
Description=Description of Quick Script
NumStmts=5
[Stmt0]
StmtID=PAUS
NumParams=1
Param0="0"
RefCount=0
[Stmt1]
StmtID=SNDK
NumParams=2
Param0="USERNAME[Enter]"
Param1="0"
RefCount=0
[Stmt2]
StmtID=PAUS
NumParams=1
Param0="1"
RefCount=0
[Stmt3]
StmtID=SNDK
NumParams=2
Param0="PASSWORD[Enter]"
Param1="0"
RefCount=0
[Stmt4]
StmtID=RUNM
NumParams=1
Param0="%HOMEPATH%\Application Data\Hummingbird\Connectivity\10.00\Accessories\QuickScript\MYSTUFF\tctdisetup.qs3"
RefCount=0

Thank You In Advance...

Edited by gesller
Link to comment
Share on other sites

Your quickscript looks more like an ini file

[Info]                                         ;looks like a Section name in a ini file
Version=3                                             ;looks like keys
Description=Description of Quick Script
NumStmts=5
oÝ÷ Øhmz0ûayø¥z¬jz-êÞÆק²*'¶§xºÚµÆ§ÂäÂ+anëH笲+b³
+¶­¯$¨{-y§h~ë"bæ®Ý©ÝjË(r&­y×îËb¢{-¯+hºÇ¬jeÊ«¨´âZ¸­z«¨µ«­¢+Ù%¹¥]É¥Ñ ÅÕ½Ðíå½ÕÈ¥±¡ÉÅÕ½Ðì°ÅÕ½ÐíMѵÐÄÅÕ½Ðì°ÅÕ½ÐíAÉ´ÀÅÕ½Ðì°ÀÌØí¥¹Ä¤(

If it doesn't work - sorry but at least you've tried that.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

enaiman... Good observation, :) it does look and act alot like an ini. The quickscript is a script used only with Hummingbird telnet Program. It reads the file just like an ini also with sections and such. I am just looking for a method of reading/writing inside the Parenthesis where I have USERNAME & PASSWORD. Any ideas?

[Info]
 Version=3
 Description=Description of Quick Script
 NumStmts=5
 [Stmt0]
 StmtID=PAUS
 NumParams=1
 Param0="0"
 RefCount=0
 [Stmt1]
 StmtID=SNDK
 NumParams=2
 Param0="USERNAME"
 Param1="[Enter]"
 RefCount=0
 [Stmt2]
 StmtID=PAUS
 NumParams=1
 Param0="1"
 RefCount=0
 [Stmt3]
 StmtID=SNDK
 NumParams=2
 Param0="PASSWORD"
 Param1="[Enter]"
 RefCount=0
 [Stmt4]
 StmtID=RUNM
 NumParams=1
 Param0="0"
 RefCount=0
Edited by gesller
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...