I have a script which opens a VBS script when an USB is connected. When I run it normally, it works fine. But, if I run it with -WindowStyle Hidden or I compile it with PowerGUI to run as a service, it will simply don't work.
So, you're not "compiling" anything, it's simply being packaged. It's still a PowerShell script, and it still has to run PowerShell. PowerShell scripts rarely make good services – it's simply not what PowerShell was designed to do. In this case, I'm guessing that the script either needs privileges it isn't getting, or that it needs access to a full user session, which services don't have.
If the goal is to run an antivirus scan every time a USB drive is inserted, this isn't a great (or reliable) approach to achieving that goal.
The topic ‘Why does my script compiled as a service is not running properly?’ is closed to new replies.