Solved

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

Posted on 2011-03-09
5
362 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 55

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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