Solved

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

Posted on 2011-03-09
5
352 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 51

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

14 Experts available now in Live!

Get 1:1 Help Now