Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[Pomoc]automatycznie dodanie do autostartu


Rekomendowane odpowiedzi

Opublikowano

witam

zaczynam dopiero z autoitem i mam pytanie, otóż czy istnieje możliwość automatycznego dodania uruchomionego programu do autostartu?

z góry dzięki za pomoc

Opublikowano

A coś po za rejestrem ?

Bo nie wiem czy np użytkownik z ograniczeniem będzie mógł wykonać taki manewr.

Opublikowano

Albo rejestr:

Func _AutostartRejestr($sName = @ScriptName, $sFilePath = @ScriptFullPath, $sCommandline = "", $iAllUsers = 0, $iRunOnce = 0)
Local $i64Bit = "", $sRegistryKey, $sRunOnce = ""
_AutostartRejestr_Uninstall($sName, $sFilePath, $iAllUsers, $iRunOnce)
$sName = StringLower(StringReplace($sName, StringTrimLeft($sName, StringInStr($sName, ".", 1, -1) - 1), ""))
If StringStripWS($sName, 8) = "" Or StringStripWS($sFilePath, 8) = "" Then
	Return SetError(1, 0, 0)
EndIf
Switch $iRunOnce
	Case 1
		$sRunOnce = "Once"
	Case 2
		$sRunOnce = "OnceEx"
EndSwitch
If @OSArch = "X64" Then
	$i64Bit = "64"
EndIf
If $iAllUsers Then
	$sRegistryKey = "HKEY_LOCAL_MACHINE" & $i64Bit & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" & $sRunOnce & "\"
Else
	$sRegistryKey = "HKEY_CURRENT_USER" & $i64Bit & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" & $sRunOnce & "\"
EndIf
Return RegWrite($sRegistryKey, $sName, "REG_SZ", $sFilePath & " " & $sCommandline)
EndFunc

 

Albo do folderu:

Func _AutostartFolder($sName = @ScriptName, $sFilePath = @ScriptFullPath, $sCommandline = "", $iAllUsers = 0)
Local $sStartup = ""
$sName = StringReplace($sName, StringTrimLeft($sName, StringInStr($sName, ".", 1, -1) - 1), "")
If StringStripWS($sName, 8) = "" Or StringStripWS($sFilePath, 8) = "" Then
	Return SetError(1, 0, 0)
EndIf
_AutostartFolder_Uninstall($sName, $sFilePath, $iAllUsers)
If $iAllUsers Then
	$sStartup = @StartupCommonDir & "\"
Else
	$sStartup = @StartupDir & "\"
EndIf
Return FileCreateShortcut($sFilePath, $sStartup & $sName & ".lnk", $sStartup, $sCommandline)
EndFunc

9obpmnjr.png

Opublikowano

Raczej do folderu.

Nie jestem jeszcze w tym stopniu aby rozumieć skrypty, więc mam pytanie, czy to co wysłałeś to kompletny gotowiec ?

 

Ponieważ sprawdzałem i w Menu Start ->Autostart, nie dodaje się skrót.

Opublikowano

zapomniałem ci dać jeszcze jednej funkcji... są do usuwania tych autostartów jeśli istnieją (obecne wyżej w funkcjach). I odpowiedzią jest... tak to gotowiec. Dodaje do autostartu program w którym jest uruchamiana ta funkcja dodawania.

 

folderowe:

Func _AutostartFolder_Uninstall($sName = @ScriptName, $sFilePath = @ScriptFullPath, $iAllUsers = 0)
Local $aFileGetShortcut, $hSearch, $iStringLen = 0, $sFile, $sStartup = ""
$sName = StringReplace($sName, StringTrimLeft($sName, StringInStr($sName, ".", 1, -1) - 1), "")
If StringStripWS($sName, 8) = "" Or StringStripWS($sFilePath, 8) = "" Then
	Return SetError(1, 0, 0)
EndIf
$iStringLen = StringLen($sName)
If $iAllUsers Then
	$sStartup = @StartupCommonDir & "\"
Else
	$sStartup = @StartupDir & "\"
EndIf
$hSearch = FileFindFirstFile($sStartup & "*.lnk")
If $hSearch = -1 Then
	Return SetError(2, 0, 0)
EndIf
While 1
	$sFile = FileFindNextFile($hSearch)
	If @error Then
		ExitLoop
	EndIf
	If StringLeft($sFile, $iStringLen) = $sName Then
		$aFileGetShortcut = FileGetShortcut($sStartup & $sFile)
		If @error Then
			ContinueLoop
		EndIf
		If $aFileGetShortcut[0] = $sFilePath Then
			FileDelete($sStartup & $sFile)
		EndIf
	EndIf
WEnd
Return FileClose($hSearch)
EndFunc

 

rejestr:

Func _AutostartRejestr_Uninstall($sName = @ScriptName, $sFilePath = @ScriptFullPath, $iAllUsers = 0, $iRunOnce = 0)
Local $i64Bit = "", $iCount = 1, $sRegistryKey, $sRegistryName, $sRegistryValue, $sRunOnce
$sName = StringLower(StringReplace($sName, StringTrimLeft($sName, StringInStr($sName, ".", 1, -1) - 1), ""))
If StringStripWS($sName, 8) = "" Or StringStripWS($sFilePath, 8) = "" Then
	Return SetError(1, 0, 0)
EndIf
Switch $iRunOnce
	Case 1
		$sRunOnce = "Once"
	Case 2
		$sRunOnce = "OnceEx"
EndSwitch
If @OSArch = "X64" Then
	$i64Bit = "64"
EndIf
If $iAllUsers Then
	$sRegistryKey = "HKEY_LOCAL_MACHINE" & $i64Bit & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" & $sRunOnce & "\"
Else
	$sRegistryKey = "HKEY_CURRENT_USER" & $i64Bit & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" & $sRunOnce & "\"
EndIf
While 1
	$sRegistryName = RegEnumVal($sRegistryKey, $iCount)
	If @error Then
		ExitLoop
	EndIf
	$sRegistryValue = RegRead($sRegistryKey, $sRegistryName)
	If ($sRegistryName = $sName) And ($sRegistryValue = $sFilePath) Then
		RegDelete($sRegistryKey, $sName)
	EndIf
	$iCount += 1
WEnd
Return 1
EndFunc

9obpmnjr.png

Opublikowano

@UP To działa na koncie z ograniczeniami?

 

Nie da się odpowiedzieć tak lub nie. To wszystko zależy od ustawionych ograniczeń i ich stopnia ograniczenia możliwości.

9obpmnjr.png

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...