# 한컴이 정상적이지 못한 방법으로 종료되거나, 실체는 없이 프로세스상에서 남아있을 때 예외처리

**URL:** <https://forum.developer.hancom.com/t/topic/1295>\
**Category:** 한글 오토메이션\
**Created:** [1월 24, 2024, 2:15오전 UTC](https://forum.developer.hancom.com/t/topic/1295 "2024-01-24T02:15:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user34](https://avatars.discourse-cdn.com/v4/letter/u/e274bd/32.png) [@user34](https://forum.developer.hancom.com/u/user34)\
**Post date:** [1월 24, 2024, 2:15오전 UTC](https://forum.developer.hancom.com/t/topic/1295/1 "2024-01-24T02:15:48Z")

</div>

if **name** == ‘ **main** ’:  
기존한컴=0  
바인딩내용 = pythoncom.CreateBindCtx(0)  
실행중객체테이블 = pythoncom.GetRunningObjectTable()  
실행중객체이름들 = 실행중객체테이블.EnumRunning()

```
for 실행중객체이름 in 실행중객체이름들:
    이름 = 실행중객체이름.GetDisplayName(바인딩내용,실행중객체이름)
    if 이름[:10] == '!HwpObject':
        찾은거 = 실행중객체테이블.GetObject(실행중객체이름)
        한컴 = EnsureDispatch(찾은거.QueryInterface(pythoncom.IID_IDispatch))
        try:
            기본=기본(한컴)
            기본.대상.HAction.Run("MoveRight")
            기본.대상.HAction.Run("MoveLeft")
            기존한컴=1
        except:
            한컴 = EnsureDispatch("hwpframe.hwpobject") 
            한컴.XHwpWindows.Item(0).Visible = True 
            기본=기본(한컴)
            기본.문서여백(20,20,15,15,10,10)                
        
if 기존한컴 == 0:
    한컴 = EnsureDispatch("hwpframe.hwpobject") 
    한컴.XHwpWindows.Item(0).Visible = True 
    기본=기본(한컴)
    기본.문서여백(20,20,15,15,10,10)

```

한컴이 안켜져있거나  
정상적으로 한컴이 켜져있을 때는 컨트롤을 가져올 수 있는데…

한컴이 정상적이지 못한 방법으로 종료되거나, 실체는 없이 프로세스상에서 남아있을 때는  
한컴창은 실행이 되나… 컨트롤을 가져올 수 없습니다.

개선방법이 없을까요?

---

<div class="post-metadata">

**Author:** ![cwy](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@cwy](https://forum.developer.hancom.com/u/cwy)\
**Post date:** [1월 25, 2024, 5:00오전 UTC](https://forum.developer.hancom.com/t/topic/1295/2 "2024-01-25T05:00:40Z")

</div>

안녕하세요. 한컴디벨로퍼입니다.

현재 담당자가 내용을 확인하고 있습니다. 조금만 기다려 주세요.

한컴디벨로퍼를 이용해 주셔서 감사합니다.

---

<div class="post-metadata">

**Author:** ![bhjung](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.developer.hancom.com/bhjung/32/259_2.png) [@bhjung](https://forum.developer.hancom.com/u/bhjung)\
**Post date:** [1월 26, 2024, 5:31오전 UTC](https://forum.developer.hancom.com/t/topic/1295/3 "2024-01-26T05:31:00Z")

</div>

안녕하세요 ^^  
아쉽지만 원하시는대로 개선 방법은 따로 없을것 같습니다.  
API 를 실행후 오류가 발생하는 object인 경우 사용하지 않고  
새롭게 HwpObject를 생성하는 방식으로 진행해야할것 같습니다.  
감사합니다.
