Solved

Need to append data in a file and run as a login script

Posted on 2011-03-09
5
360 Views
Last Modified: 2012-05-11
I wrote this bat file which appends deployment.proxy.type=0 to the end of the file deployment.properties and sent this up as a logon script. the issue I am having is it appends to that file everytime the user logs in but I would like it to only add it once and if its there to not do anything. Is there an easy way to do with a BAT file or VBS script?

 
echo deployment.proxy.type=0 >> "C:\Documents and Settings\%username%\Application Data\Sun\Java\Deployment\deployment.properties"

Open in new window

0
Comment
Question by:arraysg2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 54

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 35088448
You should be able to use FIND to check if the string is already in the file, something like this, although I didn't test this yet.

find /I "deployment.proxy.type=0" "C:\Documents and Settings\%username%\Application Data\Sun\Java\Deployment\deployment.properties" >NUL || echo deployment.proxy.type=0 >> "C:\Documents and Settings\%username%\Application Data\Sun\Java\Deployment\deployment.properties"

Open in new window

~bp
0
 
LVL 16

Assisted Solution

by:sjklein42
sjklein42 earned 250 total points
ID: 35088463
findstr deployment.proxy.type=0 "C:\Documents and Settings\%username%\Application Data\Sun\Java\Deployment\deployment.properties" >nul:
if ERRORLEVEL 1 echo deployment.proxy.type=0 >> "C:\Documents and Settings\%username%\Application Data\Sun\Java\Deployment\deployment.properties"

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35088481
Try this:

@echo off
set filename="C:\Documents and Settings\%username%\Application Data\Sun\Java\Deployment\deployment.properties"
set filename=c:\test.txt
set entry=deployment.proxy.type=0
find "%entry%" %filename% >NUL 2>&1 || (echo %entry%)>>%filename%2

It uses FIND to check if the entry is in the line and if it isn't then it runs the bit after the || to add it.

Steve
0
 

Author Closing Comment

by:arraysg2008
ID: 35088483
Works perfect, thanks
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 35088499
OK, was delayed in posting there a bit :-) ... my find entry was not working due to the 0 at the end of the entry line joining with >> which delayed me...

Steve
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question