Windows 7 小工具 - 用于开发的编程语言
Windows 7 小工具的首选开发语言是哪一种?
我知道小工具使用 Xml、Html、CSS 和脚本(Java/VB),但我需要一些高级功能,例如:
- 写入/读取文件
- 获取正在运行的进程列表
- 将密钥发送到活动应用程序
对于上述任务,我将需要使用 Windows API,或者如果可能的话,使用 .NET。是否可以在 Gadget 中具备上述功能?
Which is the preferred development language for Windows 7 gadgets?
I know that a gadget uses Xml, Html, CSS and Script(Java/VB) but I need some advanced features such as:
- Writing/Reading a file
- Getting list of running processes
- Sending keys to an active application
For the above tasks, I will need to use the Windows API or, if possible, .NET. Is it possible to have the above features in a Gadget?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
ActiveXObject
类,JScript 可以使用各种 COM 对象。您可以使用 .NET 编写自己的互操作程序集,但这会带来几个问题:如果您决定确实需要编写程序集。我建议,如果您正在为小工具编写自己的程序集,那么它是小工具基本功能的扩展,并且您确保小工具在用户无法使用该程序集时具有可用的功能。
我的公司针对上述问题有一个尚未发布的解决方案,我们计划在不久的将来(即经过更多测试后)向所有 Windows 桌面小工具开发人员提供该解决方案。
至于您指定的高级功能,这些都可以使用一些内置的 Windows COM 对象来完成,这些对象已经注册并且不随您的小工具一起分发,因此它们不会遇到上述相同的问题。作为对您的具体要求的回答,这些示例包括:
FileSystemObject
可以使用 FileSystemObject 写入/读取文件。用于读取文件的 FileSystemObject 的基本示例是:
Windows Management Instrumentation (WMI)
WMI 具有广泛的用途。不过,它的某些部分需要管理权限(必须应用于 sidebar.exe)。 WMI 中的类之一是 Win32_Process可用于迭代正在运行的进程。请注意,在 JScript 中使用 WMI 比在 VBScript 中使用 WMI 困难得多,并且您在 Internet 上找到的大多数示例都是针对 VBScript 的(这使得移植代码变得很痛苦)。
Windows 脚本宿主 Shell
WshShell 对象 为Windows 桌面小工具的限制,包括 SendKeys方法。尽管该方法不能用于专门向应用程序发送密钥,但可以使用 AppActivate 方法,然后使用 SendKeys 模拟激活的应用程序中的击键。
我希望这有帮助:-)
There are various COM objects available to JScript using the
ActiveXObject
class. You can write your own interop assembly using .NET but this introduces several problems:If you decide you really need to write an assembly. I would advise that if you are writing your own assembly for a gadget that it is an extension to the basic functionality of your gadget and that you ensure the gadget has features available should the user be unable to use the assembly.
My company has an as-of-yet unreleased solution to the above issues which we are planning on making available to all Windows Desktop Gadget developers in the near future (ie after more testing).
As for the advanced features you specified, these can all be done using some built-in Windows COM objects, which are already registered and aren't distributed with your gadget so they don't suffer the same issues noted above. As an answer to your specific requirements, examples of these are:
FileSystemObject
Writing/Reading files can be done using FileSystemObject. A basic example of FileSystemObject for reading files is:
Windows Management Instrumentation (WMI)
WMI has an enourmous range of purposes. Certain parts of it will require administrative rights, though (which must be applied to sidebar.exe). One of the classes within WMI is Win32_Process which can be used to iterate through running processes. Note that it's much more difficult to use WMI in JScript than it is in VBScript and most examples you find on the internet are for VBScript (which makes porting the code a pain).
Windows Script Host Shell
The WshShell Object provides another great extension to the limitations of Windows Desktop Gadgets, including the SendKeys method. Although the method cannot be used to send a key to an application specifically, it's possible to activate the application with the AppActivate method and then use SendKeys to emulate keystrokes in the activated application.
I hope that helps :-)