Score:0

Parse Service Pathnames

in flag

(get-ciminstance cim_service).pathname outputs something like:

C:\WINDOWS\system32\msiexec.exe /V

Does anyone know of a solution to remove all arguments and options from the output? Or a method of outputting all service executable file path locations?

Edit: My initial statement was a bit misleading I'm only looking for non system32 services. so my full script looks like:

$pathnames=(get-ciminstance cim_service).pathnames foreach ($pathname in $pathnames){if ($null -ne $pathname){if ($pathname -like "*system32*"){}else{get-acl $pathname -ErrorAction SilentlyContinue}}}

cn flag
That approach will not be very useful. A lot of services are launched in a generic hosting executable, C:\WINDOWS\system32\svchost.exe. To get the actual path name, you need to get it from the registry.
RevoCaine avatar
in flag
@GregAskew your correct. I edited my response to better explain my intentions I hope this helps with clarification. Thank you
cn flag
I would say if it begins with a double quote, get the string up to and including the second double quote. Else the first space.
Score:0
in flag

took some time but I just parsed it bit by bit

foreach ($pathname in $pathnames){
if ($null -ne $pathname){
    if ($pathname -like "*system32*"){
    }else{
        if($pathname -like '"*" *'){
            foreach ($path in $pathname.split('" ')){
                if ($path -like '"C:*'){
                    $path+'"'
                }
            }
        }elseif($pathname -like '"*'){
                $pathname.replace('"',"'")
            }elseif($pathname -like "\??\*"){
                $pathname
            }else{
                foreach ($path in $pathname.split(' ')){
                    if (!($path -like 'C:\*')){
                    }else{$path}
                }
            }
        }
    }
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.