Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-09
5
Medium Priority
?
365 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 58

Accepted Solution

by:
Bill Prew earned 1000 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 1000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

609 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