Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 3개 있습니다.)
.NET Framework: 584. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (1) - 기본
; https://www.sysnet.pe.kr/2/0/10966

.NET Framework: 585. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (2) - 웹 브라우저가 다운로드 후 자동 실행
; https://www.sysnet.pe.kr/2/0/10967

.NET Framework: 586. C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (3) - "Open with" 목록에 등록
; https://www.sysnet.pe.kr/2/0/10969




C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (2) - 웹 브라우저가 다운로드 후 자동 실행

지난번에 연결한 파일 확장자(.1myext)에 해당하는 파일을,

C# - 파일 확장자에 연결된 프로그램을 등록하는 방법 (1) - 기본
; https://www.sysnet.pe.kr/2/0/10966

IIS 웹 서버에 올려놓고 web.config에 웹 브라우저가 다운로드할 수 있도록 확장자를 연결해 줍니다.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <staticContent>
            <mimeMap fileExtension=".1myext" mimeType="application/octet-stream" />
        </staticContent>
    </system.webServer>
</configuration>

이제 웹 브라우저에서 해당 파일을 열면 다음과 같이 다운로드 되었음을 알리는 창이 뜹니다.

yourext_web_browser_open_1.png

그런데, 웹 브라우저가 test.1myext 파일을 다운로드 받았으면 곧바로 우리가 등록한 프로그램을 실행해 주면 더 좋지 않을까요? 이를 위해 확장자 연결 프로그램 등록 시 "EditFlags" 값을 설정해 주시면 됩니다.

FILETYPEATTRIBUTEFLAGS
; https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/ne-shlwapi-filetypeattributeflags

Configuring Windows Explorer - Registry EditFlags
; http://mc-computing.com/winexplorer/WinExplorerEditFlags.htm

다양한 EditFlags 값 중에서 웹 브라우저에 안전하게 열 수 있도록 지정하는 값은 FTA_OpenIsSafe(0x00010000) 입니다.

FTA_OpenIsSafe - 0x00010000

Indicates that the file type's open verb can be safely invoked for downloaded files. This flag applies only to safe file types, as identified by AssocIsDangerous. To improve the user experience and reduce unnecessary user prompts when downloading and activating items, file type owners should specify this flag and applications that download and activate files should respect this flag.


그럼, 지난 예제 프로젝트에 관련 코드를 추가해야겠지요.

private static void ProcessFileExtReg(bool register)
{
    using (RegistryKey classesKey = Registry.CurrentUser.OpenSubKey(@"Software\Classes", true))
    {
        if (register == true)
        {
            // ...[생략]...

            using (RegistryKey typeKey = classesKey.CreateSubKey(extType))
            {
                typeKey.SetValue(null, fileTypeDesc);
                typeKey.SetValue("EditFlags", new byte[] { 00, 00, 01, 00 }, RegistryValueKind.Binary);
                // ...[생략]...
            }
        }
        // ...[생략]...
    }
}

이렇게 등록한 후, 다시 웹 브라우저에서 해당 파일을 주소창에 치고 들어가면 이번에는 다운로드 알림 창이 아닌, 다음과 같이 연결 프로그램이 직접 실행된 것을 볼 수 있습니다.

yourext_web_browser_open_2.png




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 7/17/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 46  47  48  49  50  51  [52]  53  54  55  56  57  58  59  60  ...
NoWriterDateCnt.TitleFile(s)
12319정성태9/10/20209433오류 유형: 647. smigdeploy.exe를 Windows Server 2016에서 실행할 때 .NET Framework 미설치 오류 발생
12318정성태9/9/20208970오류 유형: 646. OpenVPN - "TAP-Windows Adapter V9" 어댑터의 "Network cable unplugged" 현상
12317정성태9/9/202011252개발 환경 구성: 511. Beats용 Kibana 기본 대시 보드 구성 방법
12316정성태9/8/20209680디버깅 기술: 170. WinDbg Preview 버전부터 닷넷 코어 3.0 이후의 메모리 덤프에 대해 sos.dll 자동 로드
12315정성태9/7/202011938개발 환경 구성: 510. Logstash - FileBeat을 이용한 IIS 로그 처리 [2]
12314정성태9/7/202010336오류 유형: 645. IIS HTTPERR - Timer_MinBytesPerSecond, Timer_ConnectionIdle 로그
12313정성태9/6/202011668개발 환경 구성: 509. Logstash - 사용자 정의 grok 패턴 추가를 이용한 IIS 로그 처리
12312정성태9/5/202015669개발 환경 구성: 508. Logstash 기본 사용법 [2]
12311정성태9/4/202010814.NET Framework: 937. C# - 간단하게 만들어 보는 리눅스의 nc(netcat), json_pp 프로그램 [1]
12310정성태9/3/202010051오류 유형: 644. Windows could not start the Elasticsearch 7.9.0 (elasticsearch-service-x64) service on Local Computer.
12309정성태9/3/20209769개발 환경 구성: 507. Elasticsearch 6.6부터 기본 추가된 한글 형태소 분석기 노리(nori) 사용법
12308정성태9/2/202011066개발 환경 구성: 506. Windows - 단일 머신에서 단일 바이너리로 여러 개의 ElasticSearch 노드를 실행하는 방법
12307정성태9/2/202011839오류 유형: 643. curl - json_parse_exception / Invalid UTF-8 start byte
12306정성태9/1/20209957오류 유형: 642. SQL Server 시작 오류 - error code 10013
12305정성태9/1/202010905Windows: 172. "Administered port exclusions"이 아닌 포트 범위 항목을 삭제하는 방법
12304정성태8/31/20209849개발 환경 구성: 505. 윈도우 - (네트워크 어댑터의 우선순위로 인한) 열거되는 IP 주소 순서를 조정하는 방법
12303정성태8/30/202010010개발 환경 구성: 504. ETW - 닷넷 프레임워크 기반의 응용 프로그램을 위한 명령행 도구 etrace 소개
12302정성태8/30/20209983.NET Framework: 936. C# - ETW 관련 Win32 API 사용 예제 코드 (5) - Private Logger파일 다운로드1
12301정성태8/30/202010246오류 유형: 641. error MSB4044: The "Fody.WeavingTask" task was not given a value for the required parameter "IntermediateDir".
12300정성태8/29/20209687.NET Framework: 935. C# - ETW 관련 Win32 API 사용 예제 코드 (4) CLR ETW Consumer파일 다운로드1
12299정성태8/27/202010618.NET Framework: 934. C# - ETW 관련 Win32 API 사용 예제 코드 (3) ETW Consumer 구현파일 다운로드1
12298정성태8/27/202010312오류 유형: 640. livekd - Could not resolve symbols for ntoskrnl.exe: MmPfnDatabase
12297정성태8/25/20209504개발 환경 구성: 503. SHA256 테스트 인증서 생성 방법
12296정성태8/24/202010007.NET Framework: 933. C# - ETW 관련 Win32 API 사용 예제 코드 (2) NT Kernel Logger파일 다운로드1
12295정성태8/24/20209355오류 유형: 639. Bitvise - Address is already in use; bind() in ListeningSocket::StartListening() failed: Windows error 10013: An attempt was made to access a socket ,,,
12293정성태8/24/202010701Windows: 171. "Administered port exclusions" 설명
... 46  47  48  49  50  51  [52]  53  54  55  56  57  58  59  60  ...