gpt4 book ai didi

windows - 以编程方式或从 Windows 中的命令行显示文件属性对话框

转载 作者:可可西里 更新时间:2023-11-01 10:46:19 24 4
gpt4 key购买 nike

资源管理器,右键单击单个文件,属性...

显示文件属性对话框。

我希望有一种从命令行直接执行此操作的方法,这解释了我完全没有研究如何使用 win api 执行此操作:)

最佳答案

回答我自己的问题。我从提供的链接中整理了这个脚本。可能有一种更直接的方法——它有一种科学怪人般的光环,但它确实有效。缺点是有一个 hack 可以保持对话框打开( sleep 脚本),可以更改为两种不同的方法。该脚本将执行任何动词,并列出动词。

用法:将脚本保存为shareGUI.js,用cscript shareGUI.js <args>调用

例子:

cscript shareGUI.js C:\path\to\file.txt将列出动词

cscript shareGUI.js <verb> C:\path\to\file.txt将执行给定的动词

cscript shareGUI.js "Properties" C:\path\to\file.txt将显示属性对话框

包括以粗体显示的常用免责声明。

var args = WScript.Arguments;
var usage="Usage: cscript shareGUI.js [verb] <fullpath>";
useage+="\n Function: Executes given verb on given file";
useage+="\n or lists available verbs";
useage+="\n Notes: Ampersands in property names are remove in listing";
useage+="\n Ampersands are not required when specifying verb";
useage+="\n Arguments: ";
useage+="\n verb (optional): Name of verb to be executed, case sensative";
useage+="\n if not provided, verbs are listed";
useage+="\n fullpath: FULLPATH Name of file or directory";
//
if ((args.Unnamed.length == 0) || (args.Named.Exists("?"))) {
QuitMsg(usage,0);
}
if (args.Unnamed.length > 2) {
QuitMsg(usage,0);
}
//
var tgt_;
var verb_;
if (args.Unnamed.length == 1) {
tgt_=args.Unnamed.Item(0);
verb_ = "";
}else if (args.Unnamed.length == 2) {
verb_ = args.Unnamed.Item(0);
tgt_=args.Unnamed.Item(1);
}
//
var shellApp = new ActiveXObject("Shell.Application");
QuitIfNull(shellApp,"System Error:Could not get Shell.Application ActiveXObject",2);
//
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
QuitIfNull(objFSO,"System Error:Could not get Scripting.FileSystemObject ActiveXObject",2);
//
var WSHshell = new ActiveXObject("Wscript.Shell");
QuitIfNull(WSHshell,"System Error:Could not get Wscript.Shell ActiveXObject",2);
//
var doList=verb_=="";
//
var isDir=objFSO.FolderExists(tgt_);
if (isDir) {
DoForFolder();
}else{
DoForFile();
}
WScript.Quit(0);// EXIT OK
// functions...
// redundant code prequel
function DoForFile(){
var objFile = objFSO.GetFile(tgt_);
QuitIfNull(objFile,"Error:Path \""+tgt_+"\" Not Found",3);
//
var folder = shellApp.NameSpace(objFSO.GetParentFolderName(objFile));
QuitIfNull(folder,"System Error:Could not get parent folder name of \""+tgt_+"\"",3);
//
var folderItem=folderItemFromFolder(tgt_,folder);
QuitIfNull(folderItem,"System Error:Could not folder item from parent folder of \""+tgt_+"\"",3);
//
if (doList) {
listItemVerbs(folderItem);
return;
}
var folderItemVerb=folderItemVerbFromFileItem(verb_,folderItem);
QuitIfNull(folderItemVerb,"System Error:Could not folder item verb from folder item \""+tgt_+"\"",3);
//
runTheVerb(folderItemVerb);
}
// redundant code redux
function DoForFolder(){
var folder = shellApp.NameSpace(tgt_);
QuitIfNull(folder,"System Error:Could not folder of \""+tgt_+"\"",2);
//
var folderItem=folder.Self;
QuitIfNull(folderItem,"System Error:Could not folder item of \""+tgt_+"\"",2);
//
if (doList) {
listItemVerbs(folderItem);
return;
}
var folderItemVerb=folderItemVerbFromFileItem(verb_,folderItem);
QuitIfNull(folderItemVerb,"System Error:Could not folder item verb from folder item \""+tgt_+"\"",3);
//
runTheVerb(folderItemVerb);
}
// HACK!! this part sucks, have to remain open else dialog dies
function runTheVerb(verb){
verb.DoIt();
WSH.Sleep(5000);
var focus_way=false;
if (focus_way) {
while (WSHshell.AppActivate("Properties")) {WSH.Sleep(2000)};
}else{ // forever way
WSH.Sleep(60*60*1000);// sleep for 60 minutes !
}
}
// match path and return folder item
function folderItemFromFolder(path,folder){
var folderItems = new Enumerator(folder.Items());
for (; ! folderItems.atEnd(); folderItems.moveNext()) {
var folderItem = folderItems.item();
if (folderItem.Path==tgt_) {
//WScript.Echo("tgt_:"+folderItem.Path);
//WScript.Quit(0);
return folderItem
}
}
return null;
}
// match verb name
function folderItemVerbFromFileItem(verb,folderItem){
verb=verb.replace('&','');
var folderItemVerbs = new Enumerator(folderItem.Verbs());
for (; ! folderItemVerbs.atEnd(); folderItemVerbs.moveNext()) {
var folderItemVerb = folderItemVerbs.item();
//WScript.echo("Verb:"+folderItemVerb );
var fix_n=folderItemVerb.Name.replace('&','');
if (fix_n == verb) {
return folderItemVerb;
}
}
return null;
}
// echo the verbs, ignore blanks, remove ampersands
function listItemVerbs(folderItem){
var folderItemVerbs = new Enumerator(folderItem.Verbs());
for (; ! folderItemVerbs.atEnd(); folderItemVerbs.moveNext()) {
var folderItemVerb = folderItemVerbs.item();
var fix_n=folderItemVerb.Name.replace('&','');
if (fix_n!="") {
WScript.echo(""+fix_n );
}
}
}
function QuitIfNull(who,why,how){
if (who==null) {
QuitMsg(why,how);
}
}
function QuitMsg(why,how){
WScript.Echo(why);
WScript.Quit(how);
}

关于windows - 以编程方式或从 Windows 中的命令行显示文件属性对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23780061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com