1

I need a FileWatcher script to detect new files and execute another powershell script if the files are found. The destination directory of this 2nd PS script outputs file to a UNC mount that has the directory mounted as P: . That UNC mount is actually a SMB share from a Linux machine. That Linux machine hosts a SMB service with access granted to one linux user on the box. That linux user has the proper rights to create and modify the files within the SMB directory.

I can get the filewatcher script to perform the actions perfectly fine if I run the script in a live window while I am logged in.

I cannot get the filewatcher script to run as a windows service and properly execute a command after the System.IO.FileSystemWatcher detects a new file.

I used the winsw.exe format to create the Windows Service. When I run this as the SYSTEM user...nothing. When I run the service as myself, the same user that successfully runs it in a live window, nothing.

Here is the winsw.xml

<service>
<id>StartWatchingFiles</id>
<name>Start Watching Files</name>
<description>This is used to watch files.</description>
<executable>PowerShell.exe</executable>
<logmode>reset</logmode>
<arguments>-ExecutionPolicy Bypass -File "C:\scripts\StartWatching.ps1"</arguments>
</service>

After this runs, the files are generated and the watcher script will not fire off the PS script in response to that newly detected file.

  • Does the ACL on the path you're watching include access for the SYSTEM account? – Clayton May 25 '17 at 13:52
  • How does the P: drive get mapped? – Twisty Impersonator May 26 '17 at 21:22
  • Clayton - It does include SYSTEM. All access. – Justin Edmands Jun 1 '17 at 16:26
  • Clayton - It does include SYSTEM w/ all perms. Twisty - I have a script that maps it and it is already mapped as a fail safe during testing. Neither proved to work. When mapping through he powershell script, I used the NET USE w/ credentials baked in. the script works when firing it off manually as the user logged in – Justin Edmands Jun 1 '17 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.