By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

Windows CD autorun program

P: n/a
Hello all,
I needed this and did a quick search around and didn't see any
examples.
I knew it had to be easy, and it was.
So here it is a CD_Autorun program in python.
It is very simple and without comments is only about 30 lines.
Also included a setup.py at the end of the script so you can
'compile' it easily.

py>############################################### ######################
py># CD_Autorun.pyw
py># tested on windows 98, windows 2000
py>############################################### ######################
py># Why, you ask , because it was sorta easy and free ;)
py># Really I just have fun writing my on tools and I
py># needed a simple autoloader for a project I am working on.
py># It is not full featured and guarnteed to have a few bugs.
py>############################################### ######################
py># 'compile' with py2exe or McMillan Installer
py># All you need now is this and autorun.inf file on your cd
py># You can run this first to generate your autorun file.
py># Then you can edit at will, or leave default for index.htm
py># To make a CD autorun under windows you have
py># to have an autorun.inf file in top level of your cd.
py># For autorun.inf syntax go to msdn or just google it.
py>############################################### ######################
py># We need few files to get going
py># autorun.inf <-create with this program, run once
py># CD_Autorun.exe <-create this with py2exe or McMillan Installer
py># *.* <-any other files creted by py2exe or McMillan Installer
py># CD_Autorun.ico <-name your cd icon this or edit autorun.inf
py># index.htm or your_file <-your file
py># Put them all in the top directory and edit your autorun.inf
py># to your_file_name if you didn't already.
py># then just use your favorite cd burning software and burn it.
py># Put the disk back in the cd tray and it should
py># autorun your program.
py>############################################### ######################
py>__version__ = '.1'
py>import os, sys, traceback
py>pathbase = os.path.split(sys.executable)[0]
py>autorun = os.path.join(pathbase,'autorun.inf')
py>if os.path.exists(autorun):
py> try:
py> if len(sys.argv) > 1:
py> try:
py> item = sys.argv[1]
py> try:
py> args = sys.argv[2:]
py> except:
py> args =[]
py> path = os.path.join(pathbase,item)
py> args.insert(0,path)
py> args = ' '.join(args)
py> os.spawnl(os.P_NOWAIT, path, args)
py> except:
py> try:
py> os.startfile(path)
py> except:
py> os.starfile('index.htm')
py> else:
py> os.startfile('index.htm')
py> except:
py> os.startfile('index.htm')
py>else:
py> try:
py> autorun_template = """[AutoRun]
py>open=CD_Autorun.exe index.htm
py>icon=CD_Autorun.ico
py>"""
py> autorun_file = open(autorun, 'wt')
py> autorun_file.write(autorun_template)
py> autorun_file.close()
py> except:
py> traceback.print_exc()
py>sys.exit(0)
py>############################################### ##############
py>## I prefer to use McMillan Installer
py>## and use the onefile option, it just looks cleaner to me.
py>## I will leave that for you to figure out.
py>## It isn't hard.
py>############################################### ##############
py>## This is for py2exe.
py>## Remeber you can use --icon to change the icon(win2k only?)
py>############################################### ##############
py>## setup.py py2exe
py>############################################### ##############
py># from distutils.core import setup
py># import py2exe
py># setup(name="CD_Autorun",
py># scripts=["CD_Autorun.pyw"])
py>############################################### ##############
py>## 2004 M.E.Farmer Jr.

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.