시작시 Windows 7에서 관리자로 프로그램을 자동으로 실행하는 방법은 무엇입니까?
자녀 활동을 모니터링하기 위해 나만의 자녀 보호 앱을 만들었습니다. 앱의 유일한 GUI는 작업 표시 줄 아이콘입니다. 이 프로그램은 관리자로 설치됩니다. 이 프로그램이 Windows 시작시 관리자로 자동 시작되어 표준 사용자가 작업 관리자에서 프로그램을 죽일 수 없도록하고 싶습니다.
다음 위치에서 레지스트리 키를 만들 수 있습니다.
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
Windows가 시작될 때 자동으로 실행되도록합니다. 문제는 프로그램이 로그인 된 (표준) 사용자로 시작된다는 것입니다.
관리자 모드에서 실행하려면 어떻게해야합니까? 이것이 Win7에서 가능합니까?
시스템에 대한 관리 액세스 권한이 있고 해당 계정에 의해 시작된 프로세스에 부여되는 최고 권한이있는 사용자 계정을 사용하여 사용자 로그인 후 시작되도록 작업 스케줄러에 연결해야합니다.
이것은 일반 사용자로 로그인 할 때 관리 권한으로 프로세스를 자동 시작하는 데 사용되는 구현입니다.
올바르게 작동하려면 상승 된 권한이 필요한 'OpenVPN GUI'도우미 프로세스를 시작하는 데 사용했습니다. 따라서 레지스트리 키에서 제대로 시작되지 않습니다.
명령 줄에서 수행하려는 작업에 대한 XML 설명으로 작업을 만들 수 있습니다. 예를 들어, 내 시스템에서 내 보낸 다음 로그인하면 가장 높은 권한으로 메모장이 시작됩니다.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2015-01-27T18:30:34</Date>
<Author>Pete</Author>
</RegistrationInfo>
<Triggers>
<LogonTrigger>
<StartBoundary>2015-01-27T18:30:00</StartBoundary>
<Enabled>true</Enabled>
</LogonTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>CHUMBAWUMBA\Pete</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>"c:\windows\system32\notepad.exe"</Command>
</Exec>
</Actions>
</Task>
다음을 사용하여 관리자 명령 프롬프트에 의해 등록됩니다.
schtasks /create /tn "start notepad on login" /xml startnotepad.xml
이 답변은 실제로 프로그래밍 질문이 아니기 때문에 다른 stackexchange 사이트 중 하나로 옮겨 져야합니다.
schtasks /create /sc onlogon /tn MyProgram /rl highest /tr "exeFullPath"
이건 불가능 해.
그러나 관리 사용자로 실행되는 서비스를 만들 수 있습니다.
The service can run automatically at startup and communicate with your existing application.
When the application needs to do something as an administrator, it can ask the service to do it for it.
Remember that multiple users can be logged on at once.
I think that using the task scheduler to autostart programs is not very user friendly, and sometimes it has had side effects for me (e.g. tray icon for a program is not added).
To remedy this, I have made a program called Elevated Startup that first relaunches itself with administrator privileges, then it launches all files in a directory. Since Elevated Startup is now elevated, all the programs it then launches is also given administrator privileges. The directory is on the start menu next to the classic Startup directory, and works very much the same.
You may encounter one UAC dialog when the program relaunches itself, depending on your UAC settings.
You can get the program here: https://stefansundin.github.io/elevatedstartup/
Setting compatibility of your application to administrator (Run theprogram as an administrator)
.
Plug it into task scheduler
, then turn off UAC
.
You can do this by installing the task while running as administrator via the TaskSchedler library. I'm making the assumption here that .NET/C# is a suitable platform/language given your related questions.
This library gives you granular access to the Task Scheduler API, so you can adjust settings that you cannot otherwise set via the command line by calling schtasks
, such as the priority of the startup. Being a parental control application, you'll want it to have a startup priority of 0 (maximum), which schtasks
will create by default a priority of 7.
Below is a code example of installing a properly configured startup task to run the desired application as administrator indefinitely at logon. This code will install a task for the very process that it's running from.
/*
Copyright © 2017 Jesse Nicholson
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/// <summary>
/// Used for synchronization when creating run at startup task.
/// </summary>
private ReaderWriterLockSlim m_runAtStartupLock = new ReaderWriterLockSlim();
public void EnsureStarupTaskExists()
{
try
{
m_runAtStartupLock.EnterWriteLock();
using(var ts = new Microsoft.Win32.TaskScheduler.TaskService())
{
// Start off by deleting existing tasks always. Ensure we have a clean/current install of the task.
ts.RootFolder.DeleteTask(Process.GetCurrentProcess().ProcessName, false);
// Create a new task definition and assign properties
using(var td = ts.NewTask())
{
td.Principal.RunLevel = Microsoft.Win32.TaskScheduler.TaskRunLevel.Highest;
// This is not normally necessary. RealTime is the highest priority that
// there is.
td.Settings.Priority = ProcessPriorityClass.RealTime;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.WakeToRun = false;
td.Settings.AllowDemandStart = false;
td.Settings.IdleSettings.RestartOnIdle = false;
td.Settings.IdleSettings.StopOnIdleEnd = false;
td.Settings.RestartCount = 0;
td.Settings.AllowHardTerminate = false;
td.Settings.Hidden = true;
td.Settings.Volatile = false;
td.Settings.Enabled = true;
td.Settings.Compatibility = Microsoft.Win32.TaskScheduler.TaskCompatibility.V2;
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
td.RegistrationInfo.Description = "Runs the content filter at startup.";
// Create a trigger that will fire the task at this time every other day
var logonTrigger = new Microsoft.Win32.TaskScheduler.LogonTrigger();
logonTrigger.Enabled = true;
logonTrigger.Repetition.StopAtDurationEnd = false;
logonTrigger.ExecutionTimeLimit = TimeSpan.Zero;
td.Triggers.Add(logonTrigger);
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new Microsoft.Win32.TaskScheduler.ExecAction(Process.GetCurrentProcess().MainModule.FileName, "/StartMinimized", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(Process.GetCurrentProcess().ProcessName, td);
}
}
}
finally
{
m_runAtStartupLock.ExitWriteLock();
}
}
A program I wrote, farmComm, may solve this. I released it as open-source and Public Domain.
If it doesn't meet your criteria, you may be able to easily alter it to do so.
farmComm:
- Runs at boot-up under a service, which continues when users log in or out.
- In Session 0
- Under the user "NT AUTHORITY\SYSTEM."
- Spawns arbitrary processes (you choose);
- Also in Session 0
- "Invisibly," or without showing any user interface/GUI
- With access to graphics hardware (e.g. GPUs).
- Responds to the active session, even if it changes, including the Secure Desktop. This is how it:
- Only spawns processes after a user is idle for 8.5 minutes
- Terminates spawns when a user resumes from idle
The source scripts are available here:
https://github.com/r-alex-hall/farmComm
You should also consider the security implications of running a process as an administrator level user or as Service. If any input is not being validated properly, such as if it is listening on a network interface. If the parser for this input doesn't validate properly, it can be abused, and possibly lead to an exploit that could run code as the elevated user. in abatishchev's example it shouldn't be much of a problem, but if it were to be deployed in an enterprise environment, do a security assessment prior to wide scale deployment.
I think the task scheduler would be overkill (imho). There is a startup folder for win7.
C:\Users\miliu\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Just create a shortcut for your autostart Applicaton, edit the properties of the shortcut and have it always run as administrator.
Your kids could close it of course, but if they are tech-savvy they always find a way to keep you out. I know i did when i was younger.
Good luck!
'programing' 카테고리의 다른 글
HTML 본문에 JavaScript를 포함하는 것이 나쁜 습관입니까? (0) | 2020.09.25 |
---|---|
자바 : for 루프 초기화에서 여러 변수를 초기화 하시겠습니까? (0) | 2020.09.25 |
M_PI는 math.h에서는 작동하지만 Visual Studio의 cmath에서는 작동하지 않습니다. (0) | 2020.09.25 |
Uri.ToString ()과 Uri.AbsoluteUri의 차이점은 무엇입니까? (0) | 2020.09.25 |
ggplot2 객체에 대한 플롯 축의 범위를 어떻게 추출 할 수 있습니까? (0) | 2020.09.25 |