関連付けと異なるアプリでファイルを実行する
まずはたとえば拡張子.txtに関連付けられたアプリケーションを探す。
HKCUではVistaや7とXPとではパスが途中から異なっている。
引数の"%1"を実際の開きたいファイルパスに置換し、そのままRun()。
wsh = new ActiveXObject("WScript.Shell");HKCRから取得されるのはメモ帳。
rootTxtExePath = wsh.RegRead(
'HKCR\'+ wsh.RegRead('HKCR\.txt\') +'\shell\open\command\'
);
%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/,'開きたいファイルのパス'));