0

I'm running PowerShell scripts at logon by:

Run: gpedit.msc ->
  Local Group Policy Editor ->
  User Configuration ->
  Windows Settings ->
  Scripts (Logon/Logoff) ->
  Logon ->
  PowerShell Scripts ->
  Add ->
  Browse

In the script, I'm executing programs using Start-Process:

if (!(Get-Process "outlook" -ea SilentlyContinue)) {
  Start-Process "outlook.exe"
} else { Log("Outlook already running.") }

But it seems to start these processes as administrator, which I don't want to happen.

How can I avoid this?

Paljas
  • 353
  • 3
  • 10

1 Answers1

1

Are you wanting to start the program as the currently logged in user? If you're wanting to use just another account in general, the Start-Process command can take in credentials. See here. If you're just trying to have programs start when the user logs on, you'd be better off adding them to the startup programs. This can be done by either adding it to HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run or C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

Chris S
  • 9
  • 2
  • To answer your question: as the currently logged in user, so not another account. The strange thing is that Microsoft claims that the logon scripts are executed as user, not admin, so I do not understand why the Start-Process still executes Outlook in administrator mode. I'll try your Startup directory suggestion and let you know. Thanks in advance. – Paljas Aug 17 '12 at 14:02
  • Putting the scripts in `C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup` seems to do the trick, thanks. Only trouble I had is that the default association for PowerShell scripts is to open in notepad rather than executing in PowerShell. I had to download the default registry setting for ps1 type, copy the execute in powershell command to the open action, and run. It works ok. Only downside now is that it opens a terminal. Through the logon procedure I used to do, it was done in background. An answer to the original question would still be appreciated. – Paljas Aug 17 '12 at 14:36
  • Sorry, I meant you should put a shortcut to the Outlook executable in the Startup folder. That will just launch the application. I'm not sure what else your startup script is doing or if it's only designed to launch Outlook on boot. – Chris S Aug 17 '12 at 14:58
  • I see what you mean now. I'll spare you the full script, but it determines the domain I'm in before it launches the necessary applications. So I need the script. – Paljas Aug 20 '12 at 06:46
  • It looks like what you want to do can be found here: http://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window – Chris S Aug 27 '12 at 20:07