惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
量子位
L
LINUX DO - 热门话题
Jina AI
Jina AI
J
Java Code Geeks
U
Unit 42
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
WordPress大学
WordPress大学
D
Docker
T
The Exploit Database - CXSecurity.com
博客园 - Franky
Project Zero
Project Zero
F
Full Disclosure
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
NISL@THU
NISL@THU
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
Simon Willison's Weblog
Simon Willison's Weblog
月光博客
月光博客
V
Visual Studio Blog
腾讯CDC
The Cloudflare Blog
V
V2EX
C
Cybersecurity and Infrastructure Security Agency CISA
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Security Latest
Security Latest
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
I
Intezer
S
Securelist
A
Arctic Wolf
小众软件
小众软件
P
Privacy International News Feed
Spread Privacy
Spread Privacy
The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyberwarzone
Cyberwarzone
T
Tailwind CSS Blog
Latest news
Latest news
H
Help Net Security
S
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Scott Helme
Scott Helme
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

博客园 - Eric-Liu

Docker Desktop for Windows ChatGLM本地部署 Llama本地部署 StableDiffusion本地部署 Python-CUDA-cuDNN安装 Python实现视频桌面 基于BERT进行文本分类 Python实现Windows下的视频壁纸 启用VTX技术支持启动android的虚拟机 - 报错 新机上岗 Core i7-4790 @ 3.60GHz 四核 / 16 GB ( 金士顿 DDR3 1866MHz ) / GeForce GTX 970 ( 4 GB / 七彩虹 ) VBS发送邮件-1 Oracle数据库编译存储过程挂死问题解决办法 Windows 7丢失用户、密码解决办法-我体验了! 批处理实现从Excel导入Oracle VirtualBox自动重启之谜 拆分五笔字库,提高导入到google拼音的速度 写个设置命令的VBS脚本工具。 - Eric-Liu - 博客园 CMD下一个命令遍历目录删除相同垃圾文件 SQL注入之脚本篇-FOR ACCESS数据库
Windows Gadget开发之运行外部程序 - Eric-Liu - 博客园
Eric-Liu · 2010-04-04 · via 博客园 - Eric-Liu

在Windows侧边栏工具开发时,想做一个和Windows一样的功能,基本上是以下两个功能:

1. 可以直接运行系统Path环境变量中列出路径下的程序

2. 可以直接运行UNC地址,URL网址和FTP地址,即支持常见的网络协议访问方式

其实gadget开发API中已有函数支持此功能的函数,只不过我开始选错了,我开始用的是

var winShell = new ActiveXObject("Shell.Application");
winShell.ShellExecute("\""+q+"\"");
winShell = null;

发现该方法只能运行程序,但是不支持参数传递,幸好有找到个替代产品,System.Shell.execute(appPath, null, null, open);

函数原型定义为:

execute Method

Launches an application.

Syntax

System.Shell.execute(strFile [, strArgs] [, strDir] [, strOperation])

Parameters

strFile

Required. String that specifies a Universal Naming Convention (UNC) path to an executable file, a filename, or a URL.

strArgs

Optional. If strFile specifies an executable file then String specifies the parameters to be passed to the application. For example, a UNC path such as System.Gadget.path + "\\MyFile.Txt".

Note  If strFile specifies a filename or URL, strArgs is unneccessary and should be blank, null, or an empty string.

strDir

Optional. String that specifies the UNC path for the default (working) directory of the executable file.

strOperation

Optional. String that specifies the action (or Microsoft Windows Shell verb) to be performed. The set of available verbs depends on the particular file or folder.

edit
Opens the file specified by strArgs for editing.
explore
Opens the folder specified by strDir for exploring.
find
Opens the folder specified by strDir for searching.
open
Opens the file specified by strArgs.
print
Prints the file specified by strArgs on the default printer.

Return Value

No return value.

Remarks

Supplying a path to a filename (with extension) or a URL for strFile will launch the default application associated with that file extension and load the filename specified.

Note  Alternatively, a path to a known application .exe can by supplied for strFile while strArgs, strDir, and strOperation are used to specify the rest of the file information.

strArgs, strDir, and strOperation can be assigned values in combination as required.

UNC paths should escape special characters with a '\'.

System.Shell.execute第一个参数是应用程序的路径,第二个参数是参数列表,第三个参数是应用程序工作目录,第四个是打开方式。

用上这个函数实现运行栏的功能还需要做一个命令行的解析工作,由于gadget工作在页面中,用javascript进行解析需要正则表达式来识别应用程序路径和参数列表,代码如下:

function retApp(str, retPart){
   var s = str;
   var re = new RegExp("[ \f\n\r\t\v]*(\".+\")|([^ \f\n\r\t\v]+)","ig");
   
   var arr = re.exec(s);
  if (retPart == 0) {
   return(RegExp.lastMatch);
  } else {
   return(RegExp.rightContext);
  }
  
   return("");
}

System.Shell.execute(retApp(q, 0), retApp(q, 1), null, open);

现在命令行解析有了,执行命令也有了,就可以接收 command.exe  args[] 这样的输入格式了,正则表达式将第一个出现的边界类字符串作为命令或程序路径的结束位置,后面所以的字符串作为命令的参数。