Getting errors when running shell explorer Share command

Hello everyone, I am trying to integrate some windows features into my node application. I am getting an error however. My code is as follows:

[pre]$shell = new-object -com “Shell.Application”;

$folder = $shell.Namespace(“C:\Users\igweo”);

$item = $folder.Parsename(“NailsMAIN.jpg”);

$verb = $item.Verbs() | ? {$_.Name -eq ‘Share’};

if ($verb) { $verb.DoIt(); };[/pre]

But I get the following error:

[pre] STDERR:Invalid window handle. (Exception from HRESULT: 0x80070578)

STDERR:At line:1 char:14

  • if ($verb) { $verb.DoIt(); };
  • CategoryInfo : OperationStopped: (:slight_smile: [], COMException
  • FullyQualifiedErrorId : System.Runtime.InteropServices.COMException[/pre]

I want a pop up similar to https://preview.redd.it/cde4vaf008y21.png?width=640&crop=smart&auto=webp&s=4f1d6d83c6ee7ab5ae0a011339147c6df5936a19.Not sure what to do. Every other command works OK. Please help.

Hey daibatzu47

I try below code and it was working in my side.If you give me more infomation what you are trying to achive, I may help you more.

Code:
$shell = new-object -com “Shell.Application”;
$folder = $shell.Namespace(“C:\Users\igweo”);
$item = $folder.Parsename(“NailsMAIN.jpg”);
$verb = $item.Verbs() | ? {$_.Name -like ‘Share’};
if ($verb) { $verb.DoIt(); };

 

Thanks,
Nitesh