Created
February 11, 2023 09:06
-
-
Save lxfly2000/e901b9ab9977eab7e48750856870261e to your computer and use it in GitHub Desktop.
HTA程序示例
This file contains hidden or 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<HTA:Application id="hta" | |
Applicationname="Create Link" | |
border="thin" | |
borderstyle="normal" | |
caption="yes" | |
icon="logo.ico" | |
innerborder="no" | |
maximizebutton="no" | |
minimizebutton="yes" | |
showintaskbar="true" | |
singleinstance="yes" | |
contextmenu="no" | |
sysmenu="yes" | |
version="1.0" | |
windowstate="normal" | |
scroll="no"> | |
<!--border设为thin后就不能改变窗口大小了--> | |
<title>创建桌面快捷方式</title> | |
<style type="text/css"> | |
input{ | |
width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<p> | |
<label for="path">路径:</label><input id="path" type="file" accept="*"> | |
</p> | |
<p> | |
<label for="sname">名称:</label><input id="sname" maxlength=32> | |
</p> | |
<!--ONCLICK默认采用JS,若要用VBS需加VBSCRIPT:--> | |
<button onclick="CreateLink()">创建</button> | |
<button onclick="window.close()">取消</button> | |
</body> | |
<!--JS区分大小写,而VBS不区分,text/vbscript可以简写为text/vbs--> | |
<script type="text/vbscript"> | |
'Sub无返回值,Function用函数名字作返回值 | |
Sub SetWindowSize(w,h) | |
ResizeTo w*Screen.DeviceXDPI/96,h*Screen.DeviceYDPI/96 | |
End Sub | |
</script> | |
<!--不加type属性,text/jscript和text/javascript等效--> | |
<script type="text/jscript"> | |
function window.onload(){ | |
SetWindowSize(400,300);//调用VBS函数不区分大小写 | |
//alert(hta.commandLine);//获取Windows命令行 | |
//alert(location.search);//获取URL参数 | |
} | |
function CreateLink(){ | |
var p=path.value;//此处的FILE INPUT是可以获取完整路径的 | |
var n=sname.value; | |
if(p==""||n==""){ | |
alert("名称或路径不能为空。");//此处不能使用WScript | |
return; | |
} | |
var illegalChar="\\/:*?\"<>|"; | |
if(new RegExp("[\\"+illegalChar+"]").test(n)){ | |
alert("名称中不能含有下列字符:\n"+illegalChar); | |
return; | |
} | |
//COM组件的变量和方法都不区分大小写 | |
var c=new ActiveXObject("WScript.Shell").createShortcut(n+".lnk"); | |
c.targetPath=p; | |
c.save(); | |
close(); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment