如果进程尚未运行,则让 javascript 运行该进程
如果已经没有运行,我想让 Javascript 运行说 cmd.exe。
我希望有一种方法可以让 javascript 查看正在运行的进程,然后如果该名称在列表中则不要运行。但如果它没有运行该过程。
I want to have Javascript run say cmd.exe if there is already not one running.
I was hoping there is a way to have javascript look at running processes and then if the name is in the list dont run. but if it's not run the process.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JavaScript 并不是编写操作系统级过程控制脚本的最佳途径。如果 javascript 能够直接访问您的操作系统,那么浏览互联网将面临极大的安全风险。
Internet Explorer 确实有一种从 JavaScript 编写 Windows 脚本的机制,但您必须调整安全设置才能允许这种情况发生。其他浏览器甚至不提供这种可能性。
从安全警告中选择“允许阻止的内容”后,此代码将在 Internet Explorer 中执行 notepad.exe:
docs: http://msdn.microsoft.com/en-us/library/aew9yb99%28v=vs.85%29.aspx
因此,我们可以使用此方法来列出活动进程<并在适当的情况下启动一个:
请记住,这是一个概念的证明 - 实际上,我不会建议您永远、永远、永远这样做。它是特定于浏览器的、危险的、可利用的并且通常是不好的做法。 Web 语言适用于 Web 应用程序,尽管 Microsoft 可能想告诉您,JavaScript 并不是一种操作系统脚本语言。 :)
Javascript is not the best route for scripting OS-level process control. If javascript were able to have such direct access to your operating system, it would be an extreme security risk to ever browse the internet.
Internet Explorer does have a mechanism to script Windows from javascript, but you would have to adjust your security settings to allow this to occur. Other browsers do not even offer the possibility.
This code will execute notepad.exe in Internet Explorer, after choosing to "Allow blocked content" from the security warning:
docs: http://msdn.microsoft.com/en-us/library/aew9yb99%28v=vs.85%29.aspx
So, we can use this method to both list active processes and to start one if it is appropriate:
Keep in mind, this is proof of a concept - in practice I would not suggest you ever, ever, ever do this. It is browser-specific, dangerous, exploitable, and generally bad practice. Web languages are for web applications, javascript is not intended to be a OS scripting language despite what Microsoft might want to tell you. :)