ローカルエリアネットワーク内の、どのPCからでもアクセスできる形式のファイル(フォルダ)Pathをさくっと取得するためのWSH。
WSFっていうべき?
SendToフォルダに入れて使ってます。
引数が1つの場合はVBScriptによるinputboxでのPath表示。
引数が複数の場合はテキストファイルにしてメモ帳で開きます。
SendToフォルダに入れて使ってます。
引数が1つの場合はVBScriptによるinputboxでのPath表示。
引数が複数の場合はテキストファイルにしてメモ帳で開きます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<job> | |
<script language="VBScript"> | |
function vbInputBox(prompt, title, def) | |
vbInputBox = inputbox(prompt, title, def) | |
end function | |
</script> | |
<script language="JScript"> | |
arg=WScript.Arguments | |
if(!arg.length){WScript.Quit()} | |
jsInputBox = function(p,t,d){ | |
return vbInputBox(p, t?t:WScript.ScriptName, d?d:'') | |
} | |
fs = new ActiveXObject('Scripting.fileSystemObject') | |
shell = new ActiveXObject('WScript.Shell') | |
gsf2 = fs.GetSpecialFolder(2) | |
Write = function(path,v){with(fs.CreateTextFile(path)){Write(v);Close()}} | |
WshNetwork = WScript.CreateObject("WScript.Network") | |
// ネットワークドライブのドライブ文字vsネットワークパスの組み合わせを取得する | |
drives = WshNetwork.EnumNetworkDrives() | |
objDrive={} | |
for(var i=0,L=drives.length;i<L;i+=2){ | |
objDrive[drives.Item(i)] = drives.Item(i+1) | |
} | |
getPathUNC = function(p){ | |
if(unc = objDrive[fs.GetDriveName(p)]){ | |
return unc + p.replace(/^[A-Z]:/,'') | |
}else{ | |
return 共有(p) | |
} | |
} | |
// 共有設定しているフォルダ内のファイルにも対応する | |
arr共有=[] | |
objEnum = new Enumerator(WScript.CreateObject("WbemScripting.SWbemLocator").ConnectServer().ExecQuery("Select * From Win32_Share")) | |
for(i=0; !objEnum.atEnd() ;objEnum.moveNext()){ | |
item = objEnum.item() | |
if(!item.path){continue} // IPC$はpath無いので何にでもマッチしてしまう | |
arr共有[i++] = {path:item.path, name:item.name} | |
} | |
arr共有len = arr共有.length | |
reg = /[\\\/]$/ | |
共有=function(path){ | |
for(var i=0;i<arr共有len;i++){ | |
// index=0以外は無視 | |
if(path.indexOf(arr共有[i].path)){continue} | |
var head='\\\\'+WshNetwork.computerName+'\\'+arr共有[i].name | |
return head+(head.match(reg)?'':'\\')+path.slice(arr共有[i].path.length, path.length) | |
} | |
return path | |
} | |
if(arg.length==1){ | |
jsInputBox('getPath',0,getPathUNC(arg(0))) | |
WScript.Quit() | |
} | |
str = '' | |
for(i=0,L=arg.length;i<L;i++){ str += getPathUNC(arg(i)) + '\r\n' } | |
path = gsf2+'\\'+fs.getTempName() | |
Write(path, str) | |
shell.run('notepad '+path, 1, true) | |
fs.DeleteFile(path) | |
</script> | |
</job> |
0 件のコメント:
コメントを投稿