2012-12-12 2 views
1

저는 여러 응용 프로그램을 시작하려는 .hta (javascript 포함)를 만들고 있습니다.hta/javascript 상대 경로로 응용 프로그램을 실행하는 방법

<script type="text/javascript" language="javascript"> 
    function RunFile(path) { 
    var relpath = window.location.href; 
    var fullpath = relpath + path; 

    WshShell = new ActiveXObject("WScript.Shell"); 
    WshShell.Run(fullpath, 1, false); 
    } 

    RunFile("\file.exe"); 
</script> 

답변

2

window.location.href이 너무 파일 이름과 프로토콜을 포함 : 난 내를 .hta을 실행할 때

는하지만 난 오류 메시지가이 코드입니다

파일을 찾을 수 없습니다 얻을. / 대신 \

var relpath = window.location.pathname.replace(/\\/g,'/').split('/'); 
relpath.pop();// JScript: relpath.length = relpath.length - 1; 
relpath = relpath.join('/') + '/'; 

공지 사항 사용, 그리고 /relpath을 끝내고도 편리합니다, 그래서 당신은 인수를 함수에 추가 할 필요가 없습니다 :이보십시오.

편집

난 당신이, 어쩌면이 (Windows Sripting Technologies에서 인용) 파일없이 위치를 얻기로 무슨 뜻인지 잘 모르겠어요 :

활성 프로세스가 예를 들어 실행 HTA입니다
"The CurrentDirectory returns a string that contains the fully qualified path of 
the current working directory of the active process." 

, 그래서 이것은 파일 이름없이 HTA 파일의 로컬 경로를 제공합니다.

currentDirectoryWScript.Shell의 속성이므로 코드에 WshShell과 함께 사용할 수도 있고 작업 디렉토리를 설정할 수도 있습니다.

+0

파일 자체가없는 위치를 얻는 방법이 있습니까? – user1644062

+0

Ehh ... 내 코드는 그렇게합니다. 아니면'window.location' 객체없이 경로를 얻으려고합니까? – Teemu

+0

대단히 많은 코드 작업을 해주셔서 감사합니다. 그러나 _ 대신에 맵 이름에 공백을 넣으면 동일한 오류가 발생합니다. – user1644062

관련 문제