windows 버전 체크

bool is_version_xp()

{

OSVERSIONINFO osvi = {};

    BOOL bIsWindowsXPorLater;


    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);


    GetVersionEx(&osvi);


bIsWindowsXPorLater = ( (osvi.dwMajorVersion == 5.1) || (osvi.dwMajorVersion == 5.2)) ;

       //( (osvi.dwMajorVersion > 5) ||

       //( (osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) ));


    if(bIsWindowsXPorLater)

return true;

}



http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx

c++ 작업 스케줄러 동작 추가




작업 스케줄러를 사용하면

동작 탭에 등록된 작업을 수행하게 된다.


현재 등록되어 있는 작업의 경우 

c:\windows\system32\notepad.exe를 실행하는 작업만 등록되어 있는데


한가지 작업에서 여러가지 동작을 수행할 수 있다.

* 여러개로 등록된 동작은 순차적으로 동작 함.

예) 아래 그림에 있는 동작의 순서는 NOTEPAD.EXE가 종료 되면, winver.exe가 실행이 된다. 







동작을 생성하는 방법은

이미 만들었던 IActionCollection 인터페이스에 Create()로 새로운 동작을 추가해주는 것이다.


Create로 만들 수 있는 동작의 종류는 아래와 같다.


ValueMeaning
TASK_ACTION_EXEC
0

The action performs a command-line operation. For example, the action could run a script, start an executable, or, if the name of a document is provided, find its associated application and start the application with the document.

TASK_ACTION_COM_HANDLER
5

The action fires a handler.

TASK_ACTION_SEND_EMAIL
6

This action sends an email message.

TASK_ACTION_SHOW_MESSAGE
7

This action shows a message box.



그리고 맨 처음 동작 추가와 동일한 방식으로 

동작을 추가해 준다

  

    //  Create the action, specifying that it is an executable action.

    IAction *pAction1 = NULL;

    hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction1 );

    pActionCollection->Release();

    if( FAILED(hr) )

    {

        printf("\nCannot create the action: %x", hr );

        pRootFolder->Release();

        pTask->Release();

        CoUninitialize();

        return 1;

    }


    IExecAction *pExecAction1 = NULL;

    //  QI for the executable task pointer.

    hr = pAction1->QueryInterface( 

        IID_IExecAction, (void**) &pExecAction1 );

    pAction1->Release();

    if( FAILED(hr) )

    {

        printf("\nQueryInterface call failed for IExecAction: %x", hr );

        pRootFolder->Release();

        pTask->Release();

        CoUninitialize();

        return 1;

    }


//  Get the windows directory and set the path to notepad.exe.

wstring wstrWinVerExecutablePath = _wgetenv( L"WINDIR");

    wstrWinVerExecutablePath += L"\\SYSTEM32\\winver.exe";



    //  Set the path of the executable to notepad.exe.

    hr = pExecAction1->put_Path( _bstr_t( wstrWinVerExecutablePath.c_str() ) );

    pExecAction1->Release();

    if( FAILED(hr) )

    {

        printf("\nCannot set path of executable: %x", hr );

        pRootFolder->Release();

        pTask->Release();

        CoUninitialize();

        return 1;

    }

 


c++ 작업 스케줄러 > 가장 높은 수준의 권한으로 실행

예제에는 가장 높은 수준의 권한으로 실행시키는 옵션이 없다.




ITaskSettings 에서 priority 메소드를 이용해서 

권한을 HIGH_PRIORITY_CLASS로 부여해도 저 체크 박스는 여전히 체크가 되어 있지 않음..


현재 사용중인 인터페이스에서

작업의 속성을 변경 시킬 수 있는 옵션을 모두 찾았는데 못 찾았음...


사용중이 아니여서 찾을 수가 없었다 

작업 정의를 구성요소를 다시 살펴 본 결과


작업정의
Actions작업에서 수행하는 임무를 정의하는 한 개 이상의 동작입니다.
Triggers작업이 시작할 때를 나타내는 한 개 이상의 트리거입니다.
Principal권한 부여와 감사는 보안 컨텍스트에 바탕을 둡니다.
Settings이러한 설정으로 런타임 동작을 제어하고 작업을 제한할 수 있습니다.
Data동작에 사용할 수 있는 문자열입니다.
RegistrationInfo관리 기록 정보입니다.


저런게 있었음 저 Principal

을 이용하여 가장 높은 수준의 권한으로 실행 가능하다


사용 방법은


IPrincipal의 인터페이스 포인터를 반환 받아

put_RunLevel 메소드를 이용하여 가장 높은 수준의 권한으로 실행하도록 설정한다.

그리고 받은 포인터는 해제 한다.


IPrincipal *pPrincipal = NULL;

pTask->get_Principal(&pPrincipal);


pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST);


pPrincipal->Release();




속성 값은 아래와 같다

ValueMeaning
TASK_RUNLEVEL_LUA
0

Tasks will be run with the least privileges.

TASK_RUNLEVEL_HIGHEST
1

Tasks will be run with the highest privileges.




TASK_RUNLEVEL_HIGHEST 로 설정하면

가장 높은 수준의 권한으로 실행 가능하다


'c/c++' 카테고리의 다른 글

windows 버전 체크  (0) 2014.03.11
c++ 작업 스케줄러 동작 추가  (0) 2014.03.05
c++ 관리자 권한으로 프로그램 실행시키는 방법  (0) 2014.03.03
스레드 생성  (0) 2013.04.05
정규식 표현  (0) 2013.03.27

ITaskSettings interface

Properties

The ITaskSettings interface has these properties.

PropertyAccess typeDescription

AllowDemandStart(요청 시 작업이 실행되도록 허용)

Read/write

Gets or sets a Boolean value that indicates that the task can be started by using either the Run command or the Context menu.

사용 예)

put_AllowDemandStart(VARIANT_FALSE);

AllowHardTerminate(요청할 때 실행 중인 작업이 끝나지 않으면 강제로 작업 중지)

Read/write

Gets or sets a Boolean value that indicates that the task may be terminated by using TerminateProcess.

사용 예)

put_AllowHardTerminate(VARIANT_FALSE); // 작업 중지

Compatibility

Read/write

Gets or sets an integer value that indicates which version of Task Scheduler a task is compatible with.

DeleteExpiredTaskAfter

Read/write

Gets or sets the amount of time that the Task Scheduler will wait before deleting the task after it expires.

DisallowStartIfOnBatteries(컴퓨터의 AC 전원이 켜져 있는 경우에만 작업 시작)

Read/write

Gets or sets a Boolean value that indicates that the task will not be started if the computer is running on battery power.

Enabled

Read/write

Gets or sets a Boolean value that indicates that the task is enabled. The task can be performed only when this setting istrue.

ExecutionTimeLimit

Read/write

Gets or sets the amount of time that is allowed to complete the task.

Hidden(숨김)

Read/write

Gets or sets a Boolean value that indicates that the task will not be visible in the UI by default.

사용 예)

put_Hidden(VARIANT_TRUE)

IdleSettings

Read/write

Gets or sets the information that specifies how the Task Scheduler performs tasks when the computer is in an idle state.

MultipleInstances

Read/write

Gets or sets the policy that defines how the Task Scheduler handles multiple instances of the task.

NetworkSettings

Gets or sets the network settings object that contains a network profile identifier and name. If theRunOnlyIfNetworkAvailable property of ITaskSettings is trueand a network propfile is specified in the NetworkSettingsproperty, then the task will run only if the specified network profile is available.

Priority

Read/write

Gets or sets the priority level of the task.

RestartCount(다음 횟수까지 다시 시작 시도)

Read/write

Gets or sets the number of times that the Task Scheduler will attempt to restart the task.

사용 예)

put_RestartCount(10);

RestartInterval(작업이 실패하는 경우 다시 시작 간격)

Read/write

Gets or sets a value that specifies how long the Task Scheduler will attempt to restart the task.

사용 예)

put_RestartInterval(_bstr_t(L"PT5M"));

RunOnlyIfNetworkAvailable(다음 네트워크 연결을 사용할 수 있는 경우에만 시작)

Read/write

Gets or sets a Boolean value that indicates that the Task Scheduler will run the task only when a network is available.

put_RunOnlyIfNetworkAvailable(VARIANT_TRUE)

StartWhenAvailable(예약된 시작 시간을 놓친 경우 가능한 대로 빨리 작업 시작)


Read/write

Gets or sets a Boolean value that indicates that the Task Scheduler can start the task at any time after its scheduled time has passed.

put_StartWhenAvailable(VARIANT_TRUE);

StopIfGoingOnBatteries()

(컴퓨터 배터리 전원으로 전환되는 경우 중지)

Read/write

Gets or sets a Boolean value that indicates that the task will be stopped if the computer switches to battery power.


WakeToRun(이 작업을 실행하기 위해 절전 모드 종료)

Read/write

Gets or sets a Boolean value that indicates that the Task Scheduler will wake the computer before it runs the task.

put_WakeToRun(VARIANT_TRUE);

XmlText

Read/write

Gets or sets an XML-formatted definition of the task settings.

 

'c/c++ > 레퍼런스' 카테고리의 다른 글

ILogonTrigger interface  (0) 2014.03.03
Shellexecute()  (0) 2013.02.06
PathFindSuffixArray 경로에 찾고자 하는 문자열 있는지 확인  (0) 2013.01.16

RegisterTaskDefinition 80070534 error

작업 스케줄러를 이용하기 위하여 MSDN에서 예제를 찾아보았다.


Logon Trigger Example (C++)

http://msdn.microsoft.com/en-us/library/aa381911(v=vs.85).aspx



이 샘플 코드를 실행하면 




아래와 같은 80070534 에러 코드가 발생한다.


The ITaskFolder::RegisterTaskDefinition method returns error 80070534 when called by the System account with the user parameter equal to NULL, the password parameter equal to NULL, and the logonType parameter equal to TASK_LOGON_SERVICE_ACCOUNT.


이는 로그온 트리거를 등록할때

사용자 계정이 등록되어 있지 않아서 발생한다.


예제에서는

특정 사용자가 로그온 할때 동작시키기 위하여


 hr = pLogonTrigger->put_UserId( _bstr_t( L"DOMAIN\\UserName" ) );

 

가 포함되어 있어서, 저 "DOMAIN\\UserName" 부분을 실제 실행시키려는 컴퓨터의 계정 이름으로 변경하거나,

모든 사용자가 로그온할 때 사용시키기를 원하면 put_UserId를 입력시키지 않아도 된다.



c++ 관리자 권한으로 프로그램 실행시키는 방법

관리자 권한이 필요한 프로그램이 있다.

예를들어 레지스트리를 조작해야 한다거나, 서비스를 설치 및 실행 시켜주어야 할 경우


사용자 계정에 UAC가 켜져있을 경우에 

관리자 권한이 필요한 프로그램을 그냥 실행하면 원하는 결과를 얻지 못하게 된다.

ex)

UAC가 켜져 있는 관리자 계정에서 

일반 프로그램이 서비스를 설치

==> 실패 OpenSCM 

GetLastError () 값 ERROR_ACCESS_DENIED : 5


따라서 이런 프로그램의 경우 관리자 권한으로 프로그램을 실행시켜주어야 한다







관리자 권한으로 프로그램을 실행시켜주는 방법


1. 사용자가 해당하는 프로그램을 마우스 오른쪽 클릭하여 실행시켜주는 방법이 있다.


하지만 사용자가 더블 클릭으로 걍 실행하면?? gg





2. 컴파일 속성의 변경으로 사용자가 마우스 왼쪽 클릭을 하지 않고 관리자 권한으로 실행시킬 수 있는 방법이 있다.


속성 > 구성 속성 > 링커 > 매니페스트 파일 > UAC 실행 수준

여기서 UAC 실행 수준의 값을 requireAdministrator 로 변경해주면 된다.



requireAdministrator로 값이 설정된 프로그램의 경우 

사용자가 프로그램을 실행 시키면  마우스 오른쪽 버튼을 클릭하지 않아도

사용자가 실행할때 관리자 권한으로 실행할 것인지 묻는 창이 나온다.


예를 누르면 관리자 권한으로 프로그램이 실행되고, 

아니요를 누르면 프로그램은 실행되지 않는다





'c/c++' 카테고리의 다른 글

c++ 작업 스케줄러 동작 추가  (0) 2014.03.05
c++ 작업 스케줄러 > 가장 높은 수준의 권한으로 실행  (0) 2014.03.05
스레드 생성  (0) 2013.04.05
정규식 표현  (0) 2013.03.27
스레드 생성  (0) 2013.03.26

ILogonTrigger interface


Properties

The ILogonTrigger interface has these properties.


PropertyAccess typeDescription

Delay (작업 지연 시간)

Read/write

Gets or sets a value that indicates the amount of time between when the user logs on and when the job is started.

Enabled(사용)

Read/write

Inherited from the ITrigger interface. Gets or sets a Boolean value that indicates whether the trigger is enabled.

EndBoundary(만료)

Read/write

Inherited from the ITrigger interface. Gets or sets the date and time when the trigger is deactivated. The trigger cannot start the task after it is deactivated.


사용 예)

put_EndBoundary(_bstr_t(L"2015-05-02T08:00:00"))

ExecutionTimeLimit (다음 기간 이상 실행되는 작업 중지)

Read/write

Inherited from the ITrigger interface. Gets or sets the maximum amount of time that the task launched by this trigger is allowed to run.

Id

Read/write

Inherited from the ITrigger interface. Gets or sets the identifier for the trigger.

Repetition (작업 반복 간격)

Read/write

Inherited from the ITrigger interface. Gets or sets a value that indicates how often the task is run and how long the repetition pattern is repeated after the task is started.

StartBoundary (활성화)

Read/write

Inherited from the ITrigger interface. Gets or sets the date and time when the trigger is activated.


사용 예)

put_StartBoundary(_bstr_t(L"2014-01-01T12:05:00"));

Type(작업 시작)

Read-only

Inherited from the ITrigger interface. Gets the type of the trigger.

TASK_TRIGGER_EVENT 이벤트 상태

TASK_TRIGGER_TIME 매일 지정된 시간

TASK_TRIGGER_DAILY 매일

TASK_TRIGGER_WEEKLY 매주

TASK_TRIGGER_MONTHLY 매달

TASK_TRIGGER_MONTHLYDOW 매달 지정된 날 

TASK_TRIGGER_IDLE 유휴 상태

TASK_TRIGGER_REGISTRATION 등록 되었을 때

TASK_TRIGGER_BOOT 시작할 때

TASK_TRIGGER_LOGON 로그온할 때

TASK_TRIGGER_SESSION_STATE_CHANGE 세션 상태 변경

UserId(특정 사용자)

Read/write

Gets or sets the identifier of the user.

NULL 모든 사용자 put_UserId() 로 사용자를 지정해주지 않으면 됨


 

'c/c++ > 레퍼런스' 카테고리의 다른 글

ITaskSettings interface  (0) 2014.03.04
Shellexecute()  (0) 2013.02.06
PathFindSuffixArray 경로에 찾고자 하는 문자열 있는지 확인  (0) 2013.01.16

ㅇㅇ



장미와 찔레

저자
조동성 지음
출판사
IWELL | 2007-10-05 출간
카테고리
자기계발
책소개
당신은 장미꽃인생인가, 찔레꽃인생인가? 긴 안목으로 인생을 설계...
가격비교


'기록 > ' 카테고리의 다른 글

나는 죽을 때까지 재미있게 살고싶다  (0) 2014.10.18
2014 책  (0) 2014.08.06
인생학교: 일  (0) 2013.04.23
스크럼과 XP  (3) 2013.03.11
뜨거운 침묵  (0) 2013.02.25

dddd

http://blog.naver.com/ldh9677/90021758587


http://kimonthetable.tistory.com/category

'기록 > 읽고 싶은 책' 카테고리의 다른 글

BOOK  (0) 2013.02.25

d



아이언맨 3 (2013)

Iron Man 3 
7.9
감독
쉐인 블랙
출연
로버트 다우니 주니어, 기네스 팰트로, 돈 치들, 가이 피어스, 벤 킹슬리
정보
액션, SF | 미국 | 130 분 | 2013-04-25


'기록' 카테고리의 다른 글

실버라이닝 플레이북  (0) 2013.04.23
먹고 기도하고 사랑하라  (6) 2013.02.15
4월 3째주  (0) 2012.04.23
화차  (0) 2012.03.10
범죄와의 전쟁  (0) 2012.03.10