Sign in to follow this  
Followers 0
tobi

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

10 posts in this topic

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

Share this post


Link to post
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 ()


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

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

Share this post


Link to post
Share on other sites

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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


[center]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.[/center]

Share this post


Link to post
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!

Share this post


Link to post
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

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

[center]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.[/center]

Share this post


Link to post
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

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

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

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

8)

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

[center]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.[/center]

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  
Followers 0