//cache 运行路径缓存 import fsys; import fsys.version; import fsys.lnk; import win.reg; namespace process.cache{ list = function(appPath){ var lst = {}; if(appPath){ var reg = ..win.reg("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\"); for(name,writeTime in reg.eachKey() ){ var subKey = reg.open(name); if(!subKey) continue; var p = subKey.queryValue(""); if(#p) lst[..string.expand(p)] = true; subKey.close() } reg.close(); var reg = ..win.reg("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"); for(name,writeTime in reg.eachKey() ){ var subKey = reg.open(name); if(!subKey) continue; var p = subKey.queryValue(""); if(#p) lst[..string.expand(p)] = true; subKey.close() } reg.close(); } var regPaths; if(_WIN10_LATER){ regPaths = { "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store"; "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FeatureUsage\AppSwitched"; "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted"; "HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"; } } else{ regPaths = { _WINXP ? "HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam\MUICache" : "HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache" } } for(i=1;#regPaths;1){ var reg = ..win.reg(regPaths[i],true); if(!reg) continue; for(fullpath,unusedValue,t in reg.eachValue()) { fullpath = ..string.match(fullpath,"([a-zA-Z\{].+\.<@@exe@>)"); if(fullpath) lst[fullpath] = true; } reg.close(); } var ret = {}; for(k,v in lst) ..table.push(ret,k); return ret; } each = function(){ var lst = list(); var k,v; return function(){ k,v = ..table.next(lst,k); return v; }; } find = function(filePattern,namePattern,searchLnk){ if(filePattern){ import process; var prcs = ..process.find(filePattern); if(prcs){ var path = prcs.getPath(); if( #path ){ if(!namePattern) return path; var ver = ..fsys.version.getInfo(cPath) if( ver && ver.productName && (!..string.cmpMatch( ver.productName ,namePattern ) )){ return path; } } } } if( (namePattern === null) && filePattern && !..string.indexAny(filePattern,"\/" ) ){ var filename = filePattern; if(!..string.endsWith(filename,".exe",true)){ filename = filename + ".exe"; } var path = ..win.reg.query("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\"+filename,""); if(..io.exist(path) ) return path; var path = ..win.reg.query("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"+filename,""); if(..io.exist(path) ) return path; } var paths = list(e); for(i=1;#paths;1){ var cPath = paths[i]; if( ( filePattern && !..string.cmpMatch( ..io.splitpath(cPath).file ,filePattern ) ) ) continue ; if( ..string.find(cPath,"<@@install@>|<@@setup@>") ) continue; if(!..io.exist(cPath)) continue; if(namePattern){ var ver = ..fsys.version.getInfo(cPath) if( ver && ver.productName ){ var name = ver.productName; if( ..string.match(name,"Microsoft.+Windows.+Operating.+System") ) continue; if(!..string.cmpMatch( name ,namePattern ) )continue ; } else { continue; } } return cPath; } if(searchLnk!==false){ return ..fsys.lnk.search(filePattern,namePattern); } } } /**intellisense() process.cache = 用于搜索运行过的程序 process.cache.each() = @for(path in ??.each() ){ __/*遍历最近运行过的程序路径,\npath 为程序路径,可能为已删除的路径*/ } process.cache.list() = 返回最近运行的应用程序路径数组,\n返回数组可能包含已删除的程序\n\n如果参数 @1 为 true ,\n则允许在列表中包含在 AppPath 注册的应用程序路径 process.cache.find(.( = 查找并返回当前正在运行,或已经运行过的程序。\n此函数会优先返回正在运行且匹配搜索条件的程序路径。\n如果未找到则会搜索运行过的程序,或在 AppPath 注册过的有效程序路径。\n继续搜索时仅查找 exe 后缀的路径,忽略文件名包含 Install,Setup 等单词的程序。 process.cache.find(.("文件名","版本信息产品名称",是否搜索快捷方式) = 查找并返回运行过或在 AppPath 注册过的有效程序路径。\n忽略大小写比较,并支持模式匹配语法,\n文件名与产品名称必须至少指定一个,\n越是指定严格的文件名匹配条件搜索越快。\n参数@3 为 false 不搜索快捷方式,可加快返回速度 end intellisense**/