2

Explorer, right click a single file, properties...

Shows File Properties Dialog.

I am hoping there is a direct way to do this from the command line, which explains my complete lack of research on how to do it with the win api :)

Mark Robbins
  • 2,427
  • 3
  • 24
  • 33
  • From command line you have to use a VBScript, unfortunately with RunDll32 there isn't any function you can call for this. Programmatically...you can use `properties` verb for `ShellExecute`. – Adriano Repetti May 21 '14 at 10:35
  • http://stackoverflow.com/questions/7985122/show-explorers-properties-dialog-for-a-file-in-windows or http://stackoverflow.com/questions/1936682/how-do-i-display-a-files-properties-dialog-from-c and so on – David Heffernan May 21 '14 at 12:20
  • [How can I launch a file properties dialog from the command line?](http://superuser.com/q/13290) – Cody Gray - on strike May 21 '14 at 12:48

1 Answers1

0

Answering my own question. I put together this script from the links provided. There is probably a more direct way -- this has a Frankenstein-like aura to it, but it works. The drawback is that there is a hack to keep the dialog open (sleep the script) that can be changed to two different methods. This script will exec any verb, as well as list the verbs.

Usage: save script as shareGUI.js, call with cscript shareGUI.js <args>

Examples:

cscript shareGUI.js C:\path\to\file.txt will list verbs

cscript shareGUI.js <verb> C:\path\to\file.txt will execute given verb

cscript shareGUI.js "Properties" C:\path\to\file.txt will show properties dialog

Include usual disclaimers in bold type.

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);
}
Mark Robbins
  • 2,427
  • 3
  • 24
  • 33
  • In `runTheVerb` the lines `var focus_way=false; if (focus_way) { ...` look a little odd. Why check `focus_way`, if it's always `false` anyway? Was this just put in for debugging purposes (i.e. a simple dev switch)? – Hendrik Jul 20 '16 at 14:39
  • @hendrik Yes, thats a dev switch. – Mark Robbins Sep 30 '16 at 11:01
  • If you want to show the Properties dialog, this approach only works, if you specify the localized name of *Properties*, i.e. on a German system you'd need to call *Eigenschaften*. If you invoke the verb with `folderItem.invokeVerb("Properties");` instead of `verb.DoIt()`, you can get around this, as `"Properties"` is always defined when called this way. – Hendrik Jun 28 '17 at 18:02