Solved

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

Posted on 2011-03-09
5
357 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
5 Comments
 
LVL 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now