Quantcast
Channel: OS|DC
Viewing all articles
Browse latest Browse all 64

SCCM\MDT: How to set up taskbar, wallpaper and pin items to taskbar programmatically in Windows 10 - 2016 refresh (a.k.a the super easy way!!)

$
0
0

as_it_burns_by_nedxfullmoon-d32v8s6

Ok, this a “the old new things” kind of post, as everything here is fundamentally not new. This post as one goal: leaving us away from a bunch of boring and limited technics everybody seems to be fond of lately!

After reading this blog you’ll be able to change your users wallpaper without overwriting Windows default one!

You you’ll be able to pin or unpin anything again to your users taskbar with ease. (Yes bros,  it’s  definitely back !!)

Finally you’ll be able to add or remove Edge or the Windows Store apps to your users taskbar  without capturing some part of the registry.

everything done in a dynamic and easy to maintain fashion ! Hold your breath… read on !!!

… and yes, long titles mode is also enable !

 

Wallpaper

Technology: For this one, we will be using the user’s capability to set his own wallpaper, The right click option “Set as desktop background”

2016-05-18_06h01_27

If you know about the scripting technic used to pin items to taskbar back in the day, this is exactly the same: We will execute the menu’s command to set the wallpaper… yes, it’s as simple as that.

“Scriptly” speaking, the code looks like this:

Const CSIDL_WINDOWS = &H24
Subpath = "\web\wallpaper"
Set objShell = CreateObject("Shell.Application")
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_WINDOWS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
Set objFolder = objShell.Namespace(strAllUsersProgramsPath & Subpath)
Set objFolderItem = objFolder.ParseName("LFWallpaper.jpg")
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
If Replace(objVerb.name, "&", "") = "Set as desktop background" Then objVerb.DoIt
Next
oFso.DeleteFile oShell.ExpandEnvironmentStrings( "%UserProfile%" ) & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup\"& WScript.ScriptName, true

Note that small adjustments are required to make it works in your context:

  • The image should be copied in the folder  C:\Windows\web\wallpaper (described at the second line, yes you can change it!) prior to execution.
  • at line Set objFolderItem = objFolder.ParseName("LFWallpaper.jpg"), replace LFWallpaper.jpg with your own wallpaper.
  • at line If Replace(objVerb.name, "&", "") = "Set as desktop background" Then objVerb.DoIt you should localize the menu’s command to make it work in your language. Example: for French, it must  be changed to  "Choisir comme arrière-plan du Bureau".

The Were and the When: setting up user environment require a bit of trickery as Microsoft is at rage forbidding any attempt to do so… Our path to salvation is called default Profil, but not this one, and not this one either! Our wonder is located in C:\Users\Default and has the ability to launch script in user context, right after explorer.exe has launch. The folder that make this append is located at C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup. Create the startup folder as it does not exist by default, put the script in, and you’re done !

Note: as you should have guessed, putting something in the default profil won’t do anything in your current session. to quick test what is happening:

  • create a new user: net user Gallaxhar Password /add
  • Login with this new account
  • See the magic happen after explorer.exe has launched !

 

Pin to taskbar

Technology: Actually, pinning with the above technic doesn’t works anymore on Windows 10. Fortunately a Turkish engineer has developed a tool called Syspin which pin/unpin any classic win32 application to the taskbar or start menu.

so, to pin an app to the taskbar just execute syspin "C:\Windows\notepad.exe" c:5386

other options are described in the capture :

2016-05-19_07h01_33

Were and When: As we did for the wallpaper, the default profile (C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup) is the preferred place. The command can be run from a batch file or a VBS/Powershell script, but one thing should not be forgotten:  the script should delete itself once his job is done, otherwise, a new icon will appears in your taskbar every next logon. That deletion process has some little magic as it will not delete itself in the default profile, but in the logged on user’s one. This way, the script continue to be copied from default to every new user profile and is deleted once executed.

Here is a full example in VBS that you can easily customize:

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
oShell.Run "syspin.exe ""C:\Windows\notepad.exe"" c:5386",0, True
oFso.DeleteFile oShell.ExpandEnvironmentStrings( "%UserProfile%" ) & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup\"& WScript.ScriptName, true

To make it works perfectly, don’t forget to copy syspin.exe to C:\Windows\System32 before launching !

 

Managing Universal Apps in the taskbar

Technology: The most common requests i face from my customers are “ Can you remove Edge & Windows Store form the taskbar ?  Of course I can, even if this in not possible out of the box !

As you may perhaps know, both apps are not native win32 application but universal apps, and apart from being launched and being killed, there is not really much that can be done to control them with a script or a tool. So we can’t use the pin/unpin item technic nor syspin to remove them from the task bar, but we can overcome those problems with a different approach:

Universal Apps can have shortcut, and shortcut can be pinned by syspin, so all in all, we can easily trick Universal Apps by using their shortcut. Not forgetting to mention that Icon that cast Universal Apps looks awful in the taskbar, they need to be replaced by better one found in the internet (Windows Store & Egde are include in the script package).

One last thing should be done before managing Universal Apps in the task bar is to clean the full bar as Universal Apps can’t be unpinned.

The cleaning is done by removing the value from the registry key HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband. Yes this will also remove the Explorer Icon but since we have syspin this not really a problem.

Were and When: For this last one, our winner will still be the default profile (C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup) with the auto delete at the last line. the full script looks like this:

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

'Functions
Function Create_FullShortcut (oSourceFile, oArguments, oShortCutName, oIconPath, oDestination)
    Dim olnk
    Set olnk = oShell.CreateShortcut(oDestination & "\"& oShortCutName & ".lnk")
           olnk.TargetPath = chr(34) & oSourceFile & chr(34)
        olnk.Arguments = chr(34) & oArguments & chr(34)
        olnk.IconLocation = oIconPath & ",0"
        olnk.WindowStyle = "1"
        olnk.WorkingDirectory = oFso.GetParentFolderName(oSourceFile)
    olnk.Save
End Function

'Clean TaskBar
oShell.regDelete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband\"
oShell.regwrite "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband\", ""

'Create Shortcut
Create_FullShortcut "C:\Windows\explorer.exe", "shell:appsFolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge", "Edge", "C:\Windows\Edge.ico", "C:\Windows"
Create_FullShortcut "C:\Windows\explorer.exe", "shell:appsFolder\Microsoft.WindowsStore_8wekyb3d8bbwe!App", "Store", "C:\Windows\Store.ico", "c:\Windows"

'Pin Icons
oShell.Run "syspin.exe ""C:\Windows\explorer.exe"" c:5386",0, True
oShell.Run "syspin.exe ""c:\Windows\Edge.lnk"" c:5386",0, True
oShell.Run "syspin.exe ""c:\Windows\Store.lnk"" c:5386",0, True
oShell.Run "syspin.exe ""C:\Program Files\Internet Explorer\iexplore.exe"" c:5386",0, True
oFSO.DeleteFile oShell.ExpandEnvironmentStrings( "%UserProfile%" ) & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\startup\"& WScript.ScriptName, true

Before using, copy Edge.ico and store.ico to C:\Windows and syspin.exe to C:\Windows\System32. The script will recreate a full task bar plus Internet Explorer. Comment the lines in the Pin Icons section to add or suppress IE, Edge, The Windows Store or Windows Explorer… That’s as simple as that!

Gallaxhar out !!!


Viewing all articles
Browse latest Browse all 64

Trending Articles