AutomoxAutomox

Creating a start-up item

AdamGourlay
January 27, 2020 at 3:58 pm UTC

I am still very new to Powershell and using Automox with Powershell and was wondering what would be needed to create a worklet that would create a start-up item.

This is for a Papercut printing client that is run from a network share.

I would mean avoiding a mass manual install so would be very useful!

Sorry if this is not the right place for this.

Thanks!

This discussion is archived and closed to replies. Continue it in the Automox Community Slack.

Discuss on Slack

Replies (5)

Nic-AutomoxJanuary 27, 2020
#1

I did that in this worklet:

It makes a startup shortcut that points to an executable, so you could take that portion of the code. Let me know if you need assistance getting your worklet running!

AdamGourlayJanuary 27, 2020
#2

Completely glanced over that! Maybe i need to get another eye test…

In my Environment it is a little different.

I have a .Lnk file on a network share that needs to be copied to the startup location on the local machine.

Do I follow the above and replace the bginfo.exe location to reference my .Lnk location?

If i run

5 lines
$source="\\server\Software\Papercut shortcut\PC-Client.lnk"

$destination="C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp"

Copy-item -path $source -destination $destination -force

on the local machine it copies the file without a problem, I am just struggling to get Automox to do this.

Thanks

MinnesotaJoeJanuary 27, 2020
#3

So the issue you have there is Automox is most likely running as SYSTEM.
That would mean it probably doesn’t have READ access to your SMB Share on \server.
You would either need to upload the PC-Client.lnk into the worklet or create it on the fly with more powershell. Like below.

powershell19 lines
# Create a Shortcut with Windows PowerShell

$SourceFileLocation = "$env:SystemRoot\System32\notepad.exe"

$ShortcutLocation = "C:\Users\thiyagu.a.selvaraj\Desktop\Notepad.lnk"

#New-Object : Creates an instance of a Microsoft .NET Framework or COM object.

#-ComObject WScript.Shell: This creates an instance of the COM object that represents the WScript.Shell for invoke CreateShortCut

$WScriptShell = New-Object -ComObject WScript.Shell

$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)

$Shortcut.TargetPath = $SourceFileLocation

#Save the Shortcut to the TargetPath

$Shortcut.Save()
AdamGourlayJanuary 28, 2020
#4

That worked a treat! I was looking at it from completely the wrong angle. Thanks @MinnesotaJoe and @Nic!

Nic-AutomoxJanuary 28, 2020
#5

@MinnesotaJoe is correct - worklets run as System so they don’t have any network shares, permissions or variables that you’d have logged in as you. It’s not advisable to put credentials into a worklet, so Joe’s approach is best in this situation.