Solved

how to create a batch file that adds the registry values and deletes itself?

Posted on 2007-04-09
6
538 Views
Last Modified: 2010-03-05
Hi, i am system admin for a small distributed network. i want to put the netcat in the windows but as my network is distributed it would take time , what i have thought to put the netcat in systems and remove the shared drives. so can you please tell me how can i add a batch file to system start up folder that it adds the netcat registry value to registry automatically without interaction and deletes it self with out adding registry key every time and bothering the users when the system reboots?is there any alternative solution to this please, if batch file is not a good idea?
0
Comment
Question by:shairankhan
  • 3
6 Comments
 
LVL 9

Accepted Solution

by:
herbus earned 125 total points
ID: 18875596
If I understand right, you want the batch file to be deleted after it's been run so that it doesn't keep adding the registry value, yah?

For one, it won't matter if it runs multiple times - it will just overwrite the entry each time, but it will overwrite it with the same settings, so no problem?  Best to run this from a network location, ie: via group policy, rather than having local scripts to deploy...

If for whatever reason you don't want it to run if the registry key is already in there, then I'd suggest an easy way would be to incorporate some sort of logging into the script... even if all it does is make a folder somewhere (like c:\temp\...), then when the script runs it will check for that folder - if it exists the script will quit, if not then it will add the registry values and create the folder...

ie: a simple batch file would do the log check and call on a vbs script if the registry values need to be added - example batch file below:

if exist "%userprofile%\Local Settings\Temp\regadd.log" goto end
cscript \\domaincontroller\netlogon\AddRegistryValues.vbs
md "%userprofile%\Local Settings\Temp\regadd.log"
:end

the vbs file would obviously contain the reg additions you need... ala http://www.microsoft.com/technet/scriptcenter/scripts/os/registry/osrgvb02.mspx?mfr=true

Hope this helps,
Herb
0
 
LVL 9

Expert Comment

by:herbus
ID: 18875614
Keep in mind that the example I posted had %userprofile% variable paths, which would apply to a user login script, not a computer startup script... I'd copied it from one I use at work and forgot to change that bit... if it's a computer startup script you'd replace it with "c:\temp\regadd.log" or whatever...

...and of course you'll want to test it before deploying it network-wide via a policy or such...

Cheers,
Herb
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 18884691
Rather than coding in hard values you can use system variables %temp% instead of c:\documents and settings\%userprofile% ..
0
 
LVL 9

Expert Comment

by:herbus
ID: 19246774
G'day LeeTutor & folks,.. the recommendations for cleanup are normally spot on, but in this case I'm confident that the solution I posted is valid.  If there's no objection I'd put my hand up to claim this as answered...

Cheers,
Herb
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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

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

13 Experts available now in Live!

Get 1:1 Help Now