1

Currently I've got my PowerShell script on the desktop named Chrome with a Chrome logo on it. They launch that, it opens chrome for them to use but if you tab out you'll see a PowerShell script idle counting until it reaches the terminate period.

Issue - Small business owner that has several computers employees use for web (chrome) based duties day to day. Employees often leave without logging out and closing their browser.

My Solution - Run chrome in incognito by default

While this works, they are now leaving their incognito tab open and not closing it to prevent logging out...

My Solution - deployed powershell script to close chrome after a set period of idle mouse and KB.

WHY I'M HERE - Is there any way to prevent them from closing out of my powershell script? Also is there a way to make it less obvious a giant powershell icon in the dock?

DevError404
  • 129
  • 2
  • 14
  • 1
    a somewhat more robust idea might be to simply log the user off at certain times.. if that is not do-able, then take a look at the `-WindowStyle Hidden` option of `Powershell.exe`. – Lee_Dailey Aug 02 '21 at 19:58
  • Just a point of terminology - In Windows it's called the "taskbar" (not "dock"). – Bill_Stewart Aug 02 '21 at 20:27

2 Answers2

1

This answer provides an overview of launching applications hidden.

A non-third-party solution that requires a helper VBScript, however, is described in this answer.

Assuming you have created such a script and named it runHidden.vbs and placed it in C:\path\to\HelperVBScript, you can create your shortcut file with a command line such as the following:

wscript.exe C:\path\to\HelperVBScript\runHidden.vbs powershell.exe -file c:\path\to\your\script.ps1

This will launch your PowerShell script (.ps1) invisibly, while allowing it to launch GUI applications such as Chrome visible - and only the latter will appear in the taskbar.

mklement0
  • 382,024
  • 64
  • 607
  • 775
0

My first thought would be to have it run as a job when the computer is logged in. Look into launching your script as a scheduled task with the command Start-Job.

Example:

Start-Job -ScriptBlock {### YOUR CODE HERE ###}

Then, you'd need to create a scheduled task to launch this script at login. Here's a guide on how to do that: https://blog.netwrix.com/2018/07/03/how-to-automate-powershell-scripts-with-task-scheduler/

  • I hear you. I messed around for 2-3 days and got frustrated trying to learn task scheduler. There is no way that I can find to tell my script to open when " chrome " or " edge " is opened. I only find schedule it by login, by time, date, and a bunch of other garbage. – macsrbetter Aug 02 '21 at 20:53
  • Are you trying to have it only close Chrome? Would you not like it to log the user off of the device? If you are okay with having it log the user off of the device, you can set a group policy to log user out after a set time of inactivity. – Bryan Mulvey Aug 02 '21 at 22:12
  • No, the computer is on 24/7, several people will use it a day. It's going to be on available on the desktop. It simply needs to close out of chrome incognito to reset browser usage. – macsrbetter Aug 03 '21 at 12:29