Probier es halt selbst wenn du repräsentative antworten haben willst. Einen weiteren nachteil den sich sehe ist dass Psyco gar nicht auf 64-Bit-Systemen funktioniert (das will das Projekt unladen swallow soweit ich weiß korrigieren, aber noch ist es nicht soweit).ice2k3 hat geschrieben:Kaum oder gar nicht? Lohnt es sich oder nicht?
Script in Autostart ziehen
-
- Python-Forum Veteran
- Beiträge: 16025
- Registriert: Freitag 20. Juni 2003, 16:30
- Kontaktdaten:
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Ich habe jetzt ein ganzes modul gemacht:Aber wenn ich das ausführe:
Dann startet sich immer nur python.exe, das würde aber nicht passieren, wenn ich das zu einer .exe distributiere oder?
MfG Robin
Code: Alles auswählen
# -*- coding: cp1252 -*-
from __future__ import with_statement
import os
import sys
import win32api
import pythoncom
import ctypes
from win32com.shell import shell, shellcon
__all__ = "add", "exists", "remove", "autostart", "link"
def Username():
return win32api.GetUserName()
name=os.path.basename(sys.executable)
def autostart():
autonom="C:\\Dokumente und Einstellungen\\%s\\Startmenü\\Programme" %(Username())
if not name in os.listdir(autonom):
link(sys.executable,r"C:\Dokumente und Einstellungen\All Users\Startmenü\Programme",name+".lnk")
link(sys.executable,autonom,name+".lnk")
else:
return 0
def link(exe,path,lnkname):
shortcut = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink,
None,
pythoncom.CLSCTX_INPROC_SERVER,
shell.IID_IShellLink
)
shortcut.SetPath(exe)
shortcut.SetDescription("Python's Autostart Func")
shortcut.SetIconLocation(sys.executeable, 0)
persist_file = shortcut.QueryInterface(pythoncom.IID_IPersistFile)
persist_file.Save(os.path.join (path, lnkname), 0)
if sys.platform == 'win32':
import _winreg
_registry = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
def get_runkey():
return _winreg.OpenKey(_registry,
r"Software\Microsoft\Windows\CurrentVersion\Run", 0,
_winreg.KEY_ALL_ACCESS)
def add(name, application):
"""add a new autostart entry"""
key = get_runkey()
_winreg.SetValueEx(key, name, 0, _winreg.REG_SZ, application)
_winreg.CloseKey(key)
def exists(name):
"""check if a autostart entry exists"""
key = get_runkey()
exists = True
try:
_winreg.QueryValueEx(key, name)
except WindowsError:
exists = False
_winreg.CloseKey(key)
return exists
def remove(name):
"""delete a autostart entry"""
key = get_runkey()
_winreg.DeleteValue(key, name)
_winreg.CloseKey(key)
else:
_xdg_config_home = os.path.expanduser(os.environ.get("XDG_CONFIG_HOME",
"~/.config"))
if not os.path.exists(_xdg_config_home):
os.mkdir(_xdg_config_home)
_xdg_user_autostart = os.path.join(_xdg_config_home, "autostart")
if not os.path.exists(_xdg_user_autostart):
os.mkdir(_xdg_user_autostart)
def getfilename(name):
"""get the filename of a autostart (.desktop) file"""
return os.path.join(_xdg_user_autostart, name + ".desktop")
def add(name, application):
"""add a new autostart entry"""
desktop_entry = "[Desktop Entry]\n"\
"Name=%s\n"\
"Exec=%s\n"\
"Type=Application\n"\
"Terminal=false\n" % (name, application)
with open(getfilename(name), "w") as f:
f.write(desktop_entry)
def exists(name):
"""check if a autostart entry exists"""
return os.path.exists(getfilename(name))
def remove(name):
"""delete a autostart entry"""
os.unlink(getfilename(name))
def test():
try:
add("test_xxx", "test")
assert exists("test_xxx")
finally:
remove("test_xxx")
def _register(p_file):
folder = os.path.dirname(p_file)
start_file = "%s/start.bat" % folder
with open(start_file, "w") as f:
f.write("@echo off\n")
f.write("cd \"%s\"\n" % folder)
f.write('start /B "%s"' % p_file)
add(sys.executable, start_file)
def register():
return _register(sys.argv[0])
Code: Alles auswählen
import autostart, sys
autostart.register()
while 1:
print "It worked : \t",sys.argv[0]
MfG Robin
[b][i]ein kleines game für die die lust haben http://konaminut.mybrute.com[/i][/b]
;-)
;-)
-
- Python-Forum Veteran
- Beiträge: 16025
- Registriert: Freitag 20. Juni 2003, 16:30
- Kontaktdaten:
Wie sieht denn der String aus der dann in der Registiry landet?
(Ich kanns nicht testen, da ich seit ca. drei Jahren keinerlei Windows mehr nutze)
(Ich kanns nicht testen, da ich seit ca. drei Jahren keinerlei Windows mehr nutze)
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Ja ich habs reaubekommen:Leonidas hat geschrieben:Wie sieht denn der String aus der dann in der Registiry landet?
(Ich kanns nicht testen, da ich seit ca. drei Jahren keinerlei Windows mehr nutze)
Code: Alles auswählen
def _register(p_file):
folder = os.path.dirname(p_file)
start_file = "%s/start.bat" % folder
with open(start_file, "w") as f:
f.write("@echo off\n")
f.write("cd "%s"\n" % folder)
f.write('start /B "%s"' % p_file)
add(p_file, start_file)
[b][i]ein kleines game für die die lust haben http://konaminut.mybrute.com[/i][/b]
;-)
;-)