Help for getting owner properties from a file on a server

Get help with using AutoHotkey and its commands and hotkeys
ShawnT
Posts: 11
Joined: 07 Mar 2017, 15:19

Help for getting owner properties from a file on a server

21 Feb 2019, 15:42

took some code from this post and have tried to set it up to look at a folder on my server but id seem to error out. I have tested it on files on my computer and it seems to work fine.

Error: 0x80041002 -

Source: SWbemServicesEX

Description: Not Found

Help File: (null)

HelpContext: 0



Specifically: Get



on line 14



FolderSecuritySettings := ComObjGet("winmgmts:").Get("Win32_LogicalFileSecuritySetting='" . A_loopfilefullpath . "'")



Any help would be appreciated, thanks!!


Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.

; #Warn ; Enable warnings to assist with detecting common errors.

SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

 

 

ShawnCounter := 1

RobertCounter := 1

LynkCounter := 1

StephenCounter := 1

LenCounter := 1

 

loop, \\192.168.168.1\plats\PDF DRAWINGS\*.PDF {

FolderSecuritySettings := ComObjGet("winmgmts:").Get("Win32_LogicalFileSecuritySetting='" . A_loopfilefullpath . "'")

VarSetCapacity(objRef, A_PtrSize, 0)

 

if !FolderSecuritySettings.GetSecurityDescriptor(ComObjParameter(0x4009, &objRef, 1)) {

objRef := NumGet(objRef)

SD := ComObj(objRef)

owner := SD.Owner.Domain . "\" . SD.Owner.Name

msgbox %owner%

ObjRelease(objRef)

if (owner = "EPSI\stoews"){

++ShawnCounter

}else if (owner = "EPSI\rtornhom"){

++RobertCounter

}else if (owner = "EPSI\drafter2"){

++LynkCounter

}else if (owner = "EPSI\drafter"){

++StephenCounter

}else if (owner = "EPSI\lmark"){

++LenCounter

}

}

}

msgbox Shawn %ShawnCounter% `nLen %LenCounter% `nBob %RobertCounter% `nLynk %LynkCounter% `nStephen %StephenCounter%


THANKS!



Shawn Toews
User avatar
JoeWinograd
Posts: 1312
Joined: 10 Feb 2014, 20:00

Re: Help for getting owner properties from a file on a server

21 Feb 2019, 15:55

Hi Shawn,
I've used this code from TLM posted here:

Code: Select all

oOwner:=ComObjGet("winmgmts:").ExecQuery("Associators Of {" "Win32_LogicalFileSecuritySetting='" CurrentFile "'} Where As" "socClass= Win32_LogicalFileOwner ResultRole=Owner")
For itm in oOwner
  Owner:=itm.ReferencedDomainName . "\" . itm.AccountName
Regards, Joe
ShawnT
Posts: 11
Joined: 07 Mar 2017, 15:19

Re: Help for getting owner properties from a file on a server

26 Feb 2019, 14:30

I tried the code but it still isn't able to grab the owner from the server. I'll keep poking around and trying stuff, thanks for the help and Any additional incite is appreciated.
User avatar
JoeWinograd
Posts: 1312
Joined: 10 Feb 2014, 20:00

Re: Help for getting owner properties from a file on a server

26 Feb 2019, 15:59

Tested here with WS2012R2...works perfectly (with a full path in the CurrentFile variable). What server OS do you have?
ShawnT
Posts: 11
Joined: 07 Mar 2017, 15:19

Re: Help for getting owner properties from a file on a server

27 Feb 2019, 12:36

The server is windows 2012 r2. I am thinking maybe it is the directory isn't being put in right?

Code: Select all

Loop, \\192.168.168.1\plats\PDF DRAWINGS\*.PDF{
oOwner:=ComObjGet("winmgmts:").ExecQuery("Associators Of {" "Win32_LogicalFileSecuritySetting='" \\192.168.168.1\plats\PDF DRAWINGS\ A_LoopFileName "'} Where As" "socClass= Win32_LogicalFileOwner ResultRole=Owner")
For itm in oOwner
  Owner:=itm.ReferencedDomainName . "\" . itm.AccountName
  
msgbox % Owner
}
But with this i am getting an "illegal character error" when i try and make part of the file name static. Thank you so much for the help!!
ShawnT
Posts: 11
Joined: 07 Mar 2017, 15:19

Re: Help for getting owner properties from a file on a server

27 Feb 2019, 13:42

Ok with some testing it appears to use the directory wording that is put into the loop. So that can't be it, trying to also figure out this code and i can't for the life of me understand how you got what wrote down. I am lost right after "ComObjGet" =P
User avatar
JoeWinograd
Posts: 1312
Joined: 10 Feb 2014, 20:00

Re: Help for getting owner properties from a file on a server

27 Feb 2019, 15:10

Hi Shawn,

Try this:

Code: Select all

AllPDFs:="\\192.168.168.1\plats\PDF DRAWINGS\*.PDF"
Loop,%AllPDFs%
{
  CurrentFile:=A_LoopFilePath
  oOwner:=ComObjGet("winmgmts:").ExecQuery("Associators Of {" "Win32_LogicalFileSecuritySetting='" CurrentFile "'} Where As" "socClass= Win32_LogicalFileOwner ResultRole=Owner")
  For itm in oOwner
    Owner:=itm.ReferencedDomainName . "\" . itm.AccountName
  MsgBox,64,Owner Info,File=%CurrentFile%`nOwner=%Owner%
}
Regards, Joe
ShawnT
Posts: 11
Joined: 07 Mar 2017, 15:19

Re: Help for getting owner properties from a file on a server

27 Feb 2019, 15:38

JoeWinograd wrote:
27 Feb 2019, 15:10
Hi Shawn,

Try this:

Code: Select all

AllPDFs:="\\192.168.168.1\plats\PDF DRAWINGS\*.PDF"
Loop,%AllPDFs%
{
  CurrentFile:=A_LoopFilePath
  oOwner:=ComObjGet("winmgmts:").ExecQuery("Associators Of {" "Win32_LogicalFileSecuritySetting='" CurrentFile "'} Where As" "socClass= Win32_LogicalFileOwner ResultRole=Owner")
  For itm in oOwner
    Owner:=itm.ReferencedDomainName . "\" . itm.AccountName
  MsgBox,64,Owner Info,File=%CurrentFile%`nOwner=%Owner%
}
Regards, Joe
Thanks for your continued incite into this, I appreciate it! Ok for this one I had to modify it slightly to get the Current file var to show up. I switched A_LoopFilePath to A_LoopFileFullPath. running your script without modification both variables showed up blank in the msgbox. Still no owner information though =( Could it be something i have to talk to IT about? Could i be restricted in some way? Thank you so much.
User avatar
JoeWinograd
Posts: 1312
Joined: 10 Feb 2014, 20:00

Re: Help for getting owner properties from a file on a server

27 Feb 2019, 16:19

> I had to modify it slightly to get the Current file var to show up.

I don't understand that. The script works perfectly here. No reason to modify it that I can see. Don't know what you mean by "get the Current file var to show up". It shows up fine in the MsgBox dialog here. Anyway, what did you modify in the script?

> I switched A_LoopFilePath to A_LoopFileFullPath

Unnecessary. They mean the same thing. See doc here:
https://autohotkey.com/docs/commands/LoopFile.htm#LoopFileFullPath

Note this: "A_LoopFilePath is available in [v1.1.28+] as an alias of A_LoopFileFullPath, which is a misnomer."

> running your script without modification both variables showed up blank in the msgbox

Both variables show up fine here.

> Could i be restricted in some way?

Yes. It could be a permissions issue.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], bobkater, BreezeB, Google [Bot], Gully, miike, Sam_ and 199 guests