Code: Alles auswählen
import win32api
import pythoncom
import ctypes
from win32com.shell import shell, shellcon
import sys
import os
def Username():
return win32api.GetUserName()
global name
name=sys.executable.split("//")[-1]
if type(name)==str:
name=sys.executable.split("\\")[-1]#bei mir hatte ich schonmal das Problem, dass die pfäde plötzlich \ so waren...
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:
print "Es ist schon in der Autostart"
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)