none
running a script with higher credentials. RRS feed

  • Question

  • Hi,

    I am running into some issues, i am trying to watch a folder waiting for a file to be created using this script but it pops up with a login dialogue box. If i run the start-process and credential part of the script without the filewatcher it opens powershell box using the required credentials. any ideas? (all credit to BigTeddy for the initial script)

    # based on the script by By BigTeddy 05 September 2011
    # simplified by Andy Myatt, to use one script block
    # https://gallery.technet.microsoft.com/scriptcenter/Powershell-FileSystemWatche-dfd7084b

    param(
        [string]$folderToWatch = "C:\test\logins"
      , [string]$filter        = "*.*"
      , [string]$logFile       = "C:\test\scripts\filewatcher.log"
    )

    #sets password to be used in Credentials
    $secpasswd = ConvertTo-SecureString "xxxxxxxx" -AsPlainText -Force

    #creates a credential object using username and a password
    $mycreds = New-Object System.Management.Automation.PSCredential("mydom\taska", $secpasswd)


    # In the following line, you can change 'IncludeSubdirectories to $true if required.
    $fsw = New-Object IO.FileSystemWatcher $folderToWatch, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}


    Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -MessageData $logFile -Action {
        $name = $Event.SourceEventArgs.Name
        $Arguments =  "C:\GPFolder\Scripts\monitor\dd.ps1 -filename " + $name
        #start-Process powershell.exe -Credential $mycreds    -RedirectStandardOutput "C:\GPFolder\scripts\logs\jmadmin.txt" -argumentList $Arguments
        write-host "Start-Process powershell.exe -ArgumentList $Arguments"
        Start-Process powershell.exe -Credential $mycreds -ArgumentList $Arguments
        #invoke-command -filepath C:\GPFolder\Scripts\monitor\dd.ps1 -ComputerName $env:COMPUTERNAME

        } #-windowstyle hidden



    # To stop the monitoring, run the following commands:
    #  Unregister-Event FileDeleted  ;  Unregister-Event FileCreated  ;  Unregister-Event FileChanged



    #The advantage of this method over using WMI eventing is that this can monitor sub-folders.
    #The -Action parameter can contain any valid Powershell commands.
    #The script can be set to a wildcard filter, and IncludeSubdirectories can be changed to $true.
    #You need not subscribe to all three types of event.  All three are shown for example.

    • Moved by Bill_Stewart Friday, August 4, 2017 9:45 PM No, you cannot bypass the UAC prompt
    Tuesday, July 4, 2017 10:15 AM

All replies

  • You need to format and post your code correctly as it is very broken as posted.  Posting text causes extra line breaks and is not very readable.  Use the code posting tool on the edit bar.


    \_(ツ)_/

    Tuesday, July 4, 2017 10:25 AM
  • You cannot elevate a process running as an event.


    \_(ツ)_/

    Tuesday, July 4, 2017 10:41 AM