Windows 从自定义浏览器栏按钮创建新文件
我想在Windows资源管理器工具栏上创建一个自定义按钮,以创建一个新的空白文本文档,类似于已有的“新建文件夹”按钮 接下来,我可以创建我的按钮并使其运行自定义VBScript:Windows 从自定义浏览器栏按钮创建新文件,windows,vbscript,windows-explorer,Windows,Vbscript,Windows Explorer,我想在Windows资源管理器工具栏上创建一个自定义按钮,以创建一个新的空白文本文档,类似于已有的“新建文件夹”按钮 接下来,我可以创建我的按钮并使其运行自定义VBScript: Set WshShell = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") Set objFile = fso.CreateTextFile(WshShell.CurrentDire
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.CreateTextFile(WshShell.CurrentDirectory & "\NewTextDocument.txt", True)
objFile.Close
Wscript.Quit
但是,WshShell.CurrentDirectory
的值是C:\Windows\system32
。(我认为这是因为调用的命令是该目录中的wscript.exe
)
如何获取打开资源管理器窗口的目录?
--
有点相关:当我运行这个脚本时,我遇到了一个“权限被拒绝”错误。我假设这是因为system32
目录受到保护。是否有其他预防措施确保允许脚本创建文件
谢谢。您需要一种不同的方法 使用shell而不是文件系统来执行您想要的操作 这里有两个使用所需对象类型的示例脚本
'Const NETHOOD = &H14& 'fonts
'Const NETHOOD = &H12& 'Network
Const NETHOOD = &H11& 'My Comp
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETHOOD)
Set objFolderItem = objFolder.Self
Wscript.Echo objFolderItem.Path
Set colItems = objFolder.Items
For Each objItem in colItems
For x = 1 to 79
Properties = Properties & vbtab & objFolder.GetDetailsOf(ObjItem, x)
Next
Wscript.Echo objItem.Name" & Properties
Properties=""
Next
找到合适的窗口
Set objShell = CreateObject("Shell.Application")
Set AllWindows = objShell.Windows
For Each window in AllWindows
msgbox window.locationname
Next
我只知道一种方法——创建并注册inproc COM服务器,而不是VBScript。COM服务器必须实现IObjectWithSite、IIInitializeCommand、IObjectWithSelection、IExplorerCommand、IExplorerCommand状态。必须在ExplorerCommandHandler值中的HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\YouCommandName项下写入COM服务器的CLSID。并且可以获取IObjectWithSite.SetSite中的当前文件夹。