批处理之家's Archiver

raymai97 发表于 2011-11-15 23:42

批处理无3方显示“打开文件对话框”

特点:NO临时文件,只一个批处理文件,HTA+BAT集于一身
原理:调用mshta打开自己,并把结果通过注册项反馈给批处理,批处理检测后会删除注册项

不多说,代码上:[code]@echo off
goto a
<html>
<body>
<input type='file' id='f' />
<script type='text/javascript'>
var f = document.getElementById('f');
f.click();
var shell = new ActiveXObject('WScript.Shell');
shell.RegWrite('HKEY_CURRENT_USER\\Volatile Environment\\msg', f.value);
window.close();
</script>
</body>
</html>

:a
set -reg=reg delete "HKCU\Volatile Environment" /v "msg" /f
echo,任意键选择文件
echo,
pause>nul
%-reg%>nul 2>nul
mshta "%~dpnx0"
for /f "tokens=2*" %%i in ('reg query "HKCU\Volatile Environment" /v "msg"') do (
set fname=%%j
)
::不能if x==x (x) else (y),否则选择有括号的文件时就会KO
if "%fname%"=="" echo,你没有选择文件
if not "%fname%"=="" echo,你选择了%fname%。
%-reg%>nul 2>nul
echo,
pause>nul[/code]

920168 发表于 2011-11-16 09:09

特来支持!!

garyng 发表于 2011-11-16 09:55

还是一句:RayMai究竟是RayMai啊!

收藏了。。

是HTML+BAT吧?

raymai97 发表于 2011-11-16 11:57

[b]回复 [url=http://bathome.net/redirect.php?goto=findpost&pid=96669&ptid=14699]3#[/url] [i]garyng[/i] [/b]


    hta来的,改成html就不能写入注册表了

garyng 发表于 2011-11-16 12:09

[b]回复 [url=http://bbs.bathome.net/redirect.php?goto=findpost&pid=96673&ptid=14699]4#[/url] [i]raymai97[/i] [/b]


    哦哦~
我对这东不解啊。。。

defanive 发表于 2011-11-16 13:10

[code]@echo off
for /f %%a in ('^(type "%~f0"^&echo;x^)^|find /c /v ""') do set "nLine=%%a"
setlocal enabledelayedexpansion
(for /l %%a in (2,1,%nLine%) do set /p Line_%%a=&set "Exec=!Exec!&echo;^!Line_%%a^!")<"%~f0"
:loop
>"%~f0" (type nul%Exec%)
mshta vbscript:execute("set oDlg=CreateObject(""MSComDlg.CommonDialog""):oDlg.MaxFileSize=260:oDlg.Flags=4:oDlg.Action=1:CreateObject(""Scripting.FileSystemObject"").OpenTextFile(""%~f0"",8).Write(""_""&oDlg.FileName):self.close")
<"%~f0" (for /l %%a in (1,1,%nLine%) do set /p Data=)
echo File Path: %Data:~1%
pause
goto :loop
::Data[/code]稍微写了一段,批处理自身应该不算临时文件吧,:)

canyuexiaolang 发表于 2011-11-16 13:10

win2003.....有点慢...该机子事?

defanive 发表于 2011-11-16 13:12

6L的代码基于清除批处理自身最后一行的研究成果,将批处理自己作为临时文件使用

raymai97 发表于 2011-11-16 13:37

[b]回复 [url=http://bathome.net/redirect.php?goto=findpost&pid=96686&ptid=14699]8#[/url] [i]defanive[/i] [/b]


    defanive你是用xp吧?commondialog我不是没有试过,在win7下不行啊~

raymai97 发表于 2011-11-16 13:38

[b]回复 [url=http://bathome.net/redirect.php?goto=findpost&pid=96685&ptid=14699]7#[/url] [i]canyuexiaolang[/i] [/b]


    这个会调用到ie的东西,所以会比较慢~

defanive 发表于 2011-11-16 23:19

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=96695&ptid=14699]9#[/url] [i]raymai97[/i] [/b]
Win7…回去改一下换成html控件执行好了

xj7199 发表于 2011-11-17 12:28

支持大大,能不能写一个保存的文件对话框呀。

cjiabing 发表于 2011-11-17 14:07

有创意,不过有个问题必须解决,就是如何把结果传回批处理,而不显示那些多余的东西?
[quote]任意键选择文件


错误: 系统找不到指定的注册表项或值
你没有选择文件[/quote]

cjiabing 发表于 2011-11-17 14:07

有创意,不过有个问题必须解决,就是如何把结果传回批处理,而不显示那些多余的东西?
[quote]任意键选择文件


错误: 系统找不到指定的注册表项或值
你没有选择文件[/quote]

cjiabing 发表于 2011-11-17 16:08

[code]<html>
<body>
<script language="javascript">
{
document.execCommand('Open');
Editor.focus();
}
</script>
</body>[/code]
没学过JS,搞了蛮久,还是不得。不懂如何document.write输出到文本。

920168 发表于 2011-11-17 16:52

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=96812&ptid=14699]15#[/url] [i]cjiabing[/i] [/b][code]<html>
<head>
<title>创建文本文件</title>
</head>
<body>
<hr>
<script language="JavaScript">
var fso,f1,pa;
var pa= "d:\\Fastcopy\\st.txt"
var ForReading=1;
fso=new ActiveXObject("Scripting.FileSystemObject");
f1=fso.CreateTextFile(pa,true);
f1.WriteLine("Hello World!");
f1.WriteLine("Hello World1!");
f1.WriteBlankLines(1);
f1.Close();
document.write("创建文本文件: " + pa + "<br>");
</script>
</body>
</html>[/code]

cjiabing 发表于 2011-11-17 19:42

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=96825&ptid=14699]16#[/url] [i]920168[/i] [/b]

非常感谢,不过我想问的重点是:如何把document.execCommand('Open')获得的路径输出到其它文档,比如楼主的注册表。

raymai97 发表于 2011-11-17 20:46

[b]回复 [url=http://bathome.net/redirect.php?goto=findpost&pid=96795&ptid=14699]13#[/url] [i]cjiabing[/i] [/b]

为何我这里没有这个问题的?而且我记得我已经加了“>nul 2>nul”,难道这样也隐蔽不到错误信息?

cjiabing 发表于 2011-11-17 21:34

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=96847&ptid=14699]18#[/url] [i]raymai97[/i] [/b]


    我也不知道怎么会这样,但就是提示找不到注册表。

lxzzr 发表于 2011-11-21 10:21

explorer.exe的命令行参数不是有相似的效果么?

cjiabing 发表于 2011-11-21 13:53

一语惊醒梦中人

LJY4.0 发表于 2022-5-3 20:28

回复 8# defanive
64位不行,那个部件不能创建对象

LJY4.0 发表于 2022-5-3 20:29

[b]回复 [url=http://www.bathome.net/redirect.php?goto=findpost&pid=96850&ptid=14699]19#[/url] [i]cjiabing[/i] [/b]
可能没权限,只是猜测

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.