시작에 다른 프로그램 추가

시작에 다른 프로그램 추가

컴퓨터를 시작할 때 완전히 다른 프로그램을 어떻게 추가합니까? 이런 일이 있을까요?

My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, "C:\APPLICATIONSPATH.fileextension")

추신: 멍청해서 죄송합니다.

답변1

시작 프로그램을 추가하는 방법에는 여러 가지가 있습니다.

먼저 어떤 OS를 사용하고 계시나요? 겉보기에는 Windows 버전인가요?

그리고 어떤 프로그래밍 언어를 사용하고 싶으신가요? C 샤프?

레지스트리에 쓸 수 있는 권한이 있다고 가정하면 작성한 내용이 대부분 정확해 보입니다. 테스트해보셨나요? 다음에 시작할 때만 프로그램이 실행되도록 하는 RunOnce 하위 키도 있습니다. 나는 이전에 당신이 하려는 일을 실제로 해봤지만 지금은 제한된 권한이 있는 컴퓨터를 사용하고 있기 때문에 당신이 작성한 내용이 완전히 올바른지 확인할 수 없습니다. 아이디어는 괜찮을 것 같지만 :)

Windows 시작 메뉴 "시작" 폴더에 대한 바로가기를 작성할 수도 있습니다. 짧은 코드를 작성하여 실행하려는 응용 프로그램에 대한 바로 가기 파일을 만든 다음 올바른 시작 디렉터리에 바로 가기 파일을 쓰려고 시도할 수 있습니까? 바로가기 파일이 아니라면 훨씬 쉬운 스크립트 파일을 작성하세요. 아마도 다음과 같을 것입니다:

@echo off
echo Running a startup program!
pause 
::load program
start /b "" "C:\APPLICATIONSPATH.fileextension"

프로그래밍 방식으로 이를 확장명이 .vbs인 파일에 씁니다. 이렇게 하면 컴퓨터에 능숙하지 않은 사용자가 시작 항목을 수동으로 제거하려는 경우 쉽게 볼 수 있습니다. (이 방법은 관리 권한이 필요 없이 작동할 수 있는 방법이라고 생각합니다. 레지스트리에 쓰는 것의 유용한 대안이 될 수 있습니까?)

Windows 8을 사용하는 경우 이 시작 폴더는 더 이상 시작 메뉴 아래에 존재하지 않습니다. 대신 C:\Users\YOURUSER\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup에서 찾을 수 있습니다.

또는 Windows 실행 프롬프트를 사용하여 Win+ R 및 다음을 실행합니다 .shell:startup

여기에 이미지 설명을 입력하세요

여기를 살펴보세요윈도우 8

답변2

저는 레지스트리 방법을 통해 Windows 시작에 외부 응용 프로그램을 추가하거나 제거하는 방법을 용이하게 하는 이 모듈을 개발했습니다.

시작 범위(Run/RunOnce), 사용자 범위(현재 사용자/모든 사용자), 레지스트리 범위(x86/x64)를 다루며 "보안 모드" Windows 로그온에 대한 우회를 추가할 수도 있습니다.

사용 예:

WinStartupUtil.Add(UserScope.CurrentUser, StartupScope.Run, RegistryScope.System32,
                   title:="Application Title",
                   filePath:="C:\Application.exe",
                   arguments:="/Arg1",
                   secureModeByPass:=True)

WinStartupUtil.Remove(UserScope.CurrentUser, StartupScope.Run, RegistryScope.System32,
                      title:="Application Title",
                      throwOnMissingValue:=True)

소스 코드:

' ***********************************************************************
' Author   : Elektro
' Modified : 12-October-2015
' ***********************************************************************
' <copyright file="WinStartupUtil.vb" company="Elektro Studios">
'     Copyright (c) Elektro Studios. All rights reserved.
' </copyright>
' ***********************************************************************

#Region " Option Statements "

Option Explicit On
Option Strict On
Option Infer Off

#End Region

#Region " Imports "

Imports System
Imports Microsoft.Win32

#End Region

#Region " WinStartup Util "

''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Adds or removes an application from Windows Startup.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
Public Module WinStartupUtil

#Region " Constants "

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' The 'Run' registry subkey path.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    Public Const RunSubKeyPath As String = "Software\Microsoft\Windows\CurrentVersion\Run"

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' The 'Run' registry subkey path for x86 appications on x64 operating system.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    Public Const RunSubKeyPathSysWow64 As String = "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' The 'RunOnce' registry subkey path.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    Public Const RunOnceSubKeyPath As String = "Software\Microsoft\Windows\CurrentVersion\RunOnce"

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' The 'RunOnce' registry subkey path for x86 appications on x64 operating system.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    Public Const RunOnceSubKeyPathSysWow64 As String = "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce"

#End Region

#Region " Enumerations "

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' Specifies an user scope.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    Public Enum UserScope As Integer

        ''' <summary>
        ''' 'HKEY_CURRENT_USER' root key.
        ''' </summary>
        CurrentUser = &H1

        ''' <summary>
        ''' 'HKEY_LOCAL_MACHINE' root key.
        ''' </summary>
        AllUsers = &H2

    End Enum

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' Specifies a Startup scope.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    Public Enum StartupScope As Integer

        ''' <summary>
        ''' 'Run' registry subkey.
        ''' </summary>
        Run = &H1

        ''' <summary>
        ''' 'RunOnce' registry subkey.
        ''' </summary>
        RunOnce = &H2

    End Enum

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' Specifies a registry scope.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    Public Enum RegistryScope As Integer

        ''' <summary>
        ''' 'System32' registry subkey.
        ''' </summary>
        System32 = &H1

        ''' <summary>
        ''' 'SysWow64' registry subkey.
        ''' </summary>
        SysWow64 = &H2

    End Enum

#End Region

#Region " Public Methods "

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' Adds an application to Windows Startup.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <param name="userScope">
    ''' The user scope.
    ''' </param>
    ''' 
    ''' <param name="startupScope">
    ''' The startup scope.
    ''' </param>
    ''' 
    ''' <param name="registryScope">
    ''' The registry key scope.
    ''' </param>
    ''' 
    ''' <param name="title">
    ''' The registry entry title.
    ''' </param>
    ''' 
    ''' <param name="filePath">
    ''' The application file path.
    ''' </param>
    ''' 
    ''' <param name="secureModeByPass">
    ''' If set to <see langword="True"/>, the file is ran even when the user logs into 'Secure Mode' on Windows.
    ''' </param>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <exception cref="System.ArgumentNullException">
    ''' title or filePath
    ''' </exception>
    ''' ----------------------------------------------------------------------------------------------------
    <DebuggerHidden>
    <DebuggerStepThrough>
    Public Sub Add(ByVal userScope As UserScope,
                   ByVal startupScope As StartupScope,
                   ByVal registryScope As RegistryScope,
                   ByVal title As String,
                   ByVal filePath As String,
                   Optional ByVal arguments As String = "",
                   Optional secureModeByPass As Boolean = False)

        If String.IsNullOrEmpty(title) Then
            Throw New ArgumentNullException(paramName:="title")

        ElseIf String.IsNullOrEmpty(filePath) Then
            Throw New ArgumentNullException(paramName:="filePath")

        Else
            If secureModeByPass Then
                title = title.TrimStart("*"c).Insert(0, "*")
            End If

            Dim regKey As RegistryKey = Nothing
            Try
                regKey = WinStartupUtil.GetRootKey(userScope).OpenSubKey(GetSubKeyPath(startupScope, registryScope), writable:=True)
                regKey.SetValue(title, String.Format("""{0}"" {1}", filePath, arguments), RegistryValueKind.String)

            Catch ex As Exception
                Throw

            Finally
                If regKey IsNot Nothing Then
                    regKey.Close()
                End If

            End Try

        End If

    End Sub

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' Removes an application from Windows Startup.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <param name="userScope">
    ''' The user scope.
    ''' </param>
    ''' 
    ''' <param name="startupScope">
    ''' The startup scope.
    ''' </param>
    ''' 
    ''' <param name="registryScope">
    ''' The registry scope.
    ''' </param>
    ''' 
    ''' <param name="title">
    ''' The registry entry to find.
    ''' </param>
    ''' 
    ''' <param name="throwOnMissingValue">
    ''' if set to <see langword="true"/>, throws an exception on missing value.
    ''' </param>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <exception cref="System.ArgumentNullException">
    ''' title
    ''' </exception>
    ''' 
    ''' <exception cref="System.ArgumentException">
    ''' Registry value not found.;title
    ''' </exception>
    ''' ----------------------------------------------------------------------------------------------------
    <DebuggerHidden>
    <DebuggerStepThrough>
    Friend Sub Remove(ByVal userScope As UserScope,
                      ByVal startupScope As StartupScope,
                      ByVal registryScope As RegistryScope,
                      ByVal title As String,
                      Optional ByVal throwOnMissingValue As Boolean = False)

        If String.IsNullOrEmpty(title) Then
            Throw New ArgumentNullException(paramName:="title")

        Else
            Dim valueName As String = String.Empty
            Dim regKey As RegistryKey = Nothing

            Try
                regKey = WinStartupUtil.GetRootKey(userScope).OpenSubKey(GetSubKeyPath(startupScope, registryScope), writable:=True)

                If (regKey.GetValue(title, defaultValue:=Nothing) IsNot Nothing) Then
                    valueName = title

                ElseIf (regKey.GetValue(title.TrimStart("*"c).Insert(0, "*"), defaultValue:=Nothing) IsNot Nothing) Then
                    valueName = title.TrimStart("*"c).Insert(0, "*")

                ElseIf throwOnMissingValue Then
                    Throw New ArgumentException(paramName:="title", message:="Registry value not found.")

                End If

                regKey.DeleteValue(valueName, throwOnMissingValue)

            Catch ex As Exception
                Throw

            Finally
                If regKey IsNot Nothing Then
                    regKey.Close()
                End If

            End Try

        End If

    End Sub

#End Region

#Region " Private Methods "

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' Gets a <see cref="RegistryKey"/> instance of the specified root key.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <param name="userScope">
    ''' The user scope.
    ''' </param>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <returns>
    ''' A <see cref="RegistryKey"/> instance of the specified root key.
    ''' </returns>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <exception cref="System.ArgumentException">
    ''' Invalid enumeration value.;userScope
    ''' </exception>
    ''' ----------------------------------------------------------------------------------------------------
    <DebuggerHidden>
    <DebuggerStepThrough>
    Private Function GetRootKey(ByVal userScope As UserScope) As RegistryKey

        Select Case userScope

            Case WinStartupUtil.UserScope.CurrentUser
                Return Registry.CurrentUser

            Case WinStartupUtil.UserScope.AllUsers
                Return Registry.LocalMachine

            Case Else
                Throw New ArgumentException("Invalid enumeration value.", "userScope")

        End Select ' userScope

    End Function

    ''' ----------------------------------------------------------------------------------------------------
    ''' <summary>
    ''' Gets the proper registry subkey path from the parameters criteria.
    ''' </summary>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <param name="startupScope">
    ''' The startup scope.
    ''' </param>
    ''' 
    ''' <param name="registryScope">
    ''' The registry key scope.
    ''' </param>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <returns>
    ''' The registry subkey path.
    ''' </returns>
    ''' ----------------------------------------------------------------------------------------------------
    ''' <exception cref="System.ArgumentException">
    ''' Invalid enumeration value.;startupScope or 
    ''' Invalid enumeration value.;registryScope
    ''' </exception>
    ''' ----------------------------------------------------------------------------------------------------
    <DebuggerHidden>
    <DebuggerStepThrough>
    Private Function GetSubKeyPath(ByVal startupScope As StartupScope,
                                   ByVal registryScope As RegistryScope) As String

        Select Case registryScope

            Case WinStartupUtil.RegistryScope.System32

                Select Case startupScope

                    Case WinStartupUtil.StartupScope.Run
                        Return WinStartupUtil.RunSubKeyPath

                    Case WinStartupUtil.StartupScope.RunOnce
                        Return WinStartupUtil.RunOnceSubKeyPath

                    Case Else
                        Throw New ArgumentException("Invalid enumeration value.", "startupScope")

                End Select ' startupScope

            Case WinStartupUtil.RegistryScope.SysWow64

                Select Case startupScope

                    Case WinStartupUtil.StartupScope.Run
                        Return WinStartupUtil.RunSubKeyPathSysWow64

                    Case WinStartupUtil.StartupScope.RunOnce
                        Return WinStartupUtil.RunOnceSubKeyPathSysWow64

                    Case Else
                        Throw New ArgumentException("Invalid enumeration value.", "startupScope")

                End Select ' startupScope

            Case Else
                Throw New ArgumentException("Invalid enumeration value.", "registryScope")

        End Select ' registryScope

    End Function

#End Region

End Module

#End Region

관련 정보