Everything you always wanted to know about Scense but were afraid to ask

Menu

Expanding your Scense building bricks collection

Even as Scense has a large feature set out of the box, that help you as an IT admin to manage the systems in your IT infra, you still might find some actions that you can’t do or require quite some (configuration) work.

Just as an example:
If you have to change a handfull of registry settings, you could use the built-in registry functionality. This allows you to set a single value at a time. Great for a few, but not practical if there are a lot of changes to apply. For example to load a default configuration for some Adobe application with 200+ registry settings, just to apply defaults.
There are alternative options available, like saving a textfile (.reg) and importing this with a reg.exe or regedit.exe import function. This however splits the configuration and the apply-action, and wouldn’t it be neat if it would be just a single setting option. Most likely you are familiar with the extensions hosted on the AppiXoft forum, and there is an extension that covers the registry import (phew). So download it, import in Scense (double-click the SPK) and you are covered. It even has a nice GUI that allows you to paste the contents of the exported registry, so it will be imported.

But what if there is no extension that does what you want to accomplish?
Sure: you could call AppiXoft and file a feature request, or post on the forum that you are looking for a specific feature (and hope someone has it).

Now comes the best part: Scense has the ability to give you the tools, so you can do it yourselves!
To show you how this can be done, and prove it is no rocket science, we will pick an extension that is good already, but make it more versatile to fit a slightly different purpose. To be honest: you need to have some scripting skills. However, if you know VBscript or powershell, this should be easy to accomplish.

My goal (in this blog):
I want to be able to change (network)drive features. This could be several actions, but for now we just focus on (un)hiding them.
There is an existing extension that allows drive hiding, but it requires to set the hiding options for all 26 driveletters (A-Z) at once. Changing a single one is not an option, and that is what we will create. The final result will be placed in the extensions on the AppiXoft forum of course 🙂

If you just want to have this ready-made extension, visit the Appixoft forum, check extensions and get the (updated) Show/hide drives extension.

Cool… you want to know more…

There are some handy things to know when starting scripting in Scense:

In Scense Explorer enable editing scripts:
In the menu, select File > Options
Tick the option for “Allow Action template editing”, as it allows editing scripts that have a GUI for editing settings. While editing, you can hit F6 to toggle the script editor mode…

Check the Embedded Scripting Guide
This is a PDF copied to your system whenever the Scense Explorer is installed. You can find this document also on the install ISO.

Some scripting experience helps

If you have imported one of the existing scripts into your Scense environment (download from the forum, doubleclick the SPK) you can open these scripts. In most cases you will be presented with a user interface asking you for some settings. Now hit F6, and you will see the raw code…

If you don’t know what to do with all the text, ask someone with scripting knowledge to help you. The language used by Scense is based on VbScripting, with some extensions (additional commands). Additionally scripts can be extended with a header, which allows to create the ‘Simple’ GUI, which allows non-scripting aware IT admins to change settings for the script.

The original script used for this mini-tutorial does have some flaws. First it has some configuration issues, as you need to specify the visibility of all driveletters. Most of the time however you want to (un)hide a specific driveletter for some users.
Next it was created in the good old Windows XP era, back then the IT guy was nothing less of a god once logged on to the system. Since then Microsoft has created some improved OS versions, in which security has been bumped a bit. Writing to the Policies registry branche has been denied for the user (but this script still expects to be able to do that). More about this later on…

So I actually almost completely rewrote the existing script, as a lot had to be replaced.

Original script flow:

Get the selection from the user, on which drive(s) to hide

Calculate the bitmask
Hiding driveletters depends on a bitmask in which each driveletter has a bit. If the bit is a ‘1’, that drive will be hidden.

Write the new value to the registry key:
HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Assign the calculated value to NoDrives (DWord)

New script flow:

Get the driveletter to (un)hide from the user selection

Get the current bitmask with the drives that are hidden

Depending on the option, re-calculate the new bitmask
It is possible to select hide or unhide the drive. The bit in the bitmask is enabled/disabled, depending on the choice.

Write back the updated value to the registry

There was an issue with writing the value to the registry. As described before, Microsoft no longer allows updating settings in the Policies part of the registry. This allows admins to enforce settings, and users can not change this.
Luckily Scense is able to run commands as the ODS (admin) user. This way it is possible to alter the value. However, in that case the ‘HKCU’ (Current User) is not correct, as it would address the ODS user, and we want to change it for the actual user.

Luckily the registry for all users is published in the HKEY_USERS-branche. We just need the SID for the user… Arg…
But not really an issue, as Scense offers this SID as a Scense variable. So we just apply this variable (%USERSID%) and the ODS user is able to change the setting for our user.

‘ Depending on the action: set or reset the bitmask value If (vAction = “HIDE”) Then newval = curval Or DriveValue WriteScenseLog “NewVal = ” & newval If Not Registry.WriteKeyValue (,HKEY_USERS, RegPath, “NoDrives”, newval, REG_DWORD) Then WriteScenseLog Registry.Result End If End If If (vAction = “SHOW”) Then newval = curval And (67108864 – DriveValue – 1) WriteScenseLog “NewVal = ” & newval If Not Registry.WriteKeyValue (,HKEY_USERS, RegPath, “NoDrives”, newval, REG_DWORD) Then WriteScenseLog Registry.Result End If End If

End Sub

The gray text is the header, which shows the GUI. This one is a bit long, as all 26 driveletters have to be defined. The result of this header is:
This is a lot simpler for a Scense admin to change, than editing (and potentially breaking) the script code…

Next we determine the bitmask. The CINT function to convert the string from the selection can only handle 2^16 bits, but we have 26 letters in the alphabet, requiring up to 2^26. I used a trick that I do the calculation in code, as the variables allow 2^31 (signed DWord).

Next we determine the registry location for the actual user, which is done by replacing the SID in the path in the registry using the ReplaceVariables-Scense-function. We use this key to read the current value of the bitmask. If the value can’t be read (policy not defined) the default of 0 (no drives hidden) is used.

Then depending on the action (Show/hide) the resulting bitmask is calculated and saved to the registry.

Simple, isn’t it…?
Now you can alter existing extensions or create your own with new functionalities!