Jump to content

Choose last line in a .txt file to add a entry ?


tobi
 Share

Recommended Posts

Hi everybody !

I am trying to add one entry to the services file in C:\...\system32\drivers\etc .

i open this file with notepad and i use the send command to add some more lines.

my problem is that i cant find out how add my lines behind the existing lines...

Here is the code i use:

RunAsSet ( "administrator",@Computername, "****", 1 )

Run( "Notepad.exe C:\WINDOWS\system32\drivers\etc\services", "C:\Windows", @SW_MAXIMIZE)

WinWaitActive("services - Notepad")

Send("bla bla bla")

WinClose("services - Notepad")

WinWaitActive("Notepad")

Send("!n")

RunAsSet ()

I also tried it with FileWriteLine and then it automatically adds my stuff at the end of the existing lines. But i couldnt use this script with RunAsSet, which is requiered.

have anyone some ideas to help me ?

Thx in advance

br, Tobi

Link to comment
Share on other sites

Hi everybody !

I am trying to add one entry to the services file in C:\...\system32\drivers\etc .

i open this file with notepad and i use the send command to add some more lines.

my problem is that i cant find out how add my lines behind the existing lines...

Here is the code i use:

RunAsSet ( "administrator",@Computername, "****", 1 )

Run( "Notepad.exe C:\WINDOWS\system32\drivers\etc\services", "C:\Windows", @SW_MAXIMIZE)

WinWaitActive("services - Notepad")

Send("bla bla bla")

WinClose("services - Notepad")

WinWaitActive("Notepad")

Send("!n")

RunAsSet ()

I also tried it with FileWriteLine and then it automatically adds my stuff at the end of the existing lines. But i couldnt use this script with RunAsSet, which is requiered.

have anyone some ideas to help me ?

Thx in advance

br, Tobi

Try

RunAsSet ( "administrator",@Computername, "****", 1 )
Run( "Notepad.exe C:\WINDOWS\system32\drivers\etc\services", "C:\Windows", @SW_MAXIMIZE)
WinWaitActive("services - Notepad")
Send("^{END}")
Send("{ENTER}")
Send("bla bla bla")
WinClose("services - Notepad")
WinWaitActive("Notepad")
Send("!n") 
RunAsSet ()


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

  • Developers

What about doing it without the need for Notepad:

RunAsSet ( "administrator",@Computername, "****", 1 )
Run(@comspec & " /c ECHO bla bla bla >> C:\WINDOWS\system32\drivers\etc\services", "C:\Windows", @SW_HIDE)
RunAsSet ()

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

This worked for me:

RunAsSet( "administrator",@Computername, "****", 1 )
FileWriteLine(@SystemDir & '\drivers\etc\services', 'Testing---------------------------------------')
TestTheory()
RunAsSet()

Func TestTheory()
    Run( "Notepad.exe " & @SystemDir & "\drivers\etc\services", "C:\Windows", @SW_MAXIMIZE)
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

In the latest beta, there's a UDF of mine called _FileWriteToLine, that's probably what you're lookin for.

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

  • Moderators

In the latest beta, there's a UDF of mine called _FileWriteToLine, that's probably what you're lookin for.

~cdkid

You don't need a UDF, it's a one liner.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

ooohhh... your in the beta... way to go cdkid

8)

I didn't comprehend that!! WTG!! (P.S., I did like the UDF)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

thanks :)

~cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
Link to comment
Share on other sites

  • Developers

Seems your are all missing the issue that the OP needs elivated rights to do this, at least that what I assume since there is a RunASSet() in the original post.

Thats why I proposed the one-liner using Run().

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...