<

![endif]-->

fc2ブログ

関連付けと異なるアプリでファイルを実行する

まずはたとえば拡張子.txtに関連付けられたアプリケーションを探す。
wsh = new ActiveXObject("WScript.Shell");
rootTxtExePath = wsh.RegRead(
'HKCR\'+ wsh.RegRead('HKCR\.txt\') +'\shell\open\command\'
);
HKCRから取得されるのはメモ帳。
%SystemRoot%\system32\NOTEPAD.EXE %1 

HKCUではVistaや7とXPとではパスが途中から異なっている。
var commonPth ='HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'+
'\\FileExts\\.txt\\';

if(/Windows NT 6/.test(navigator.userAgent)){
try{
var txtExeId = wsh.RegRead(commonPth +'UserChoice\\Progid');
var txtExeCmd = wsh.RegRead('HKCU\\Software\\Classes\\'+
txtExeId +'\\shell\\open\\command\\');
}catch(e){}
}else{
try{
var txtExeId = wsh.RegRead(commonPth +'Application');
var txtExeCmd = wsh.RegRead('HKCU\\Software\\Classes\\Applications\\'+
txtExeId +'\\shell\\open\\command\\');
}catch(e){}
}
取得した実行コマンド
"C:\sakura\sakura.exe" "%1" 

引数の"%1"を実際の開きたいファイルパスに置換し、そのままRun()。
wsh.Run(txtExeCmd.replace(/%1/,'開きたいファイルのパス'));




comment

Secret

while(aho.atEndofStream)

笹部 政宏
笹部 政宏
mail




フリーソフツ
Category
はてブ
Monthly Archive
New Entry
New Comment
New Trackback
RSS
Copyright © Kittens flewby me All Rights Reserved.