Discussion:
Powershell script runs OK on the desktop but not when it's running under machine startup
(too old to reply)
fortran_guy
2011-04-01 18:42:50 UTC
Permalink
Windows 7 32 bit but the intended target is a Windows Server 2008 R2
as an inbound and outbound FTP server. I've run Set-ExecutionPolicy
unrestricted, set it to run with gpedit.msc, and both RSOP.MSC and
sysinternals AUTORUNS show it running through local group
policy. .ps1 is associated with PowerShell, the script is in c:
\windows\system32\grouppolicy\machine\scripts\startup (which I believe
is the default location) and the file even shows under the PowerShell
"Show Files" button. So what tweaks/changes/etc. am I missing.

The script is:

# Check for changes every 60 seconds
$currentFiles = Get-ChildItem D:\inetpub\ftproot\localuser\username
\UNEDITEDIMAGES
while(-1){
$newFiles = Get-ChildItem D:\inetpub\ftproot\localuser\username
\UNEDITEDIMAGES
if($newFiles.count -ne $currentFiles.count){
$currentFiles = $newFiles
(new-object Media.SoundPlayer "C:\WINDOWS\Media\notify.wav").play()
}
Start-Sleep(60)
}
David H. Lipman
2011-04-01 20:05:20 UTC
Permalink
From: "fortran_guy" <***@gmail.com>

| Windows 7 32 bit but the intended target is a Windows Server 2008 R2
| as an inbound and outbound FTP server. I've run Set-ExecutionPolicy
| unrestricted, set it to run with gpedit.msc, and both RSOP.MSC and
| sysinternals AUTORUNS show it running through local group
| policy. .ps1 is associated with PowerShell, the script is in c:
| \windows\system32\grouppolicy\machine\scripts\startup (which I believe
| is the default location) and the file even shows under the PowerShell
| "Show Files" button. So what tweaks/changes/etc. am I missing.

| The script is:

| # Check for changes every 60 seconds
| $currentFiles = Get-ChildItem D:\inetpub\ftproot\localuser\username
| \UNEDITEDIMAGES
| while(-1){
| $newFiles = Get-ChildItem D:\inetpub\ftproot\localuser\username
| \UNEDITEDIMAGES
| if($newFiles.count -ne $currentFiles.count){
| $currentFiles = $newFiles
| (new-object Media.SoundPlayer "C:\WINDOWS\Media\notify.wav").play()
| }
| Start-Sleep(60)
| }

Look at the POV the script is running under and the privileges provided.

When you run it it uses your credentials.
If it is failing it may be because of the credentials of the environment it is running
under.
--
Dave
Multi-AV Scanning Tool - http://www.pctipp.ch/downloads/dl/35905.asp
fortran_guy
2011-04-11 19:07:04 UTC
Permalink
Post by David H. Lipman
| Windows 7 32 bit but the intended target is a Windows Server 2008 R2
| as an inbound and outbound FTP server.  I've run Set-ExecutionPolicy
| unrestricted, set it to run with gpedit.msc, and both RSOP.MSC and
| sysinternals AUTORUNS show it running through local group
| \windows\system32\grouppolicy\machine\scripts\startup (which I believe
| is the default location) and the file even shows under the PowerShell
| "Show Files" button.  So what tweaks/changes/etc. am I missing.
| # Check for changes every 60 seconds
| $currentFiles = Get-ChildItem D:\inetpub\ftproot\localuser\username
| \UNEDITEDIMAGES
| while(-1){
| $newFiles = Get-ChildItem D:\inetpub\ftproot\localuser\username
| \UNEDITEDIMAGES
| if($newFiles.count -ne $currentFiles.count){
| $currentFiles = $newFiles
| (new-object Media.SoundPlayer "C:\WINDOWS\Media\notify.wav").play()
| }
| Start-Sleep(60)
| }
Look at the POV the script is running under and the privileges provided.
When you run it it uses your credentials.
If it is failing it may be because of the credentials of the environment it is running
under.
--
Dave
Multi-AV Scanning Tool -http://www.pctipp.ch/downloads/dl/35905.asp
Can't really be credentials of mine since the problem is at machine
startup with no one logged in.
Other suggestions?

Loading...