CJSmith dot me

Just another blog

Category: Windows

Updating a network location in Windows 2012

Published / by Chris Smith / Leave a Comment

I had an issue where a server which was joined to a domain had incorrectly set its network as Public.
A TechNet article and TenForum article provided the answer (As it states Windows 10 it also applies to Server 2012) so I have placed credits above the steps I followed.
Following a re-occurrence I have found my steps below didn’t work for me a second time, so this post now has a second way of performing this with PowerShell thanks to a blog post from Clint Boessen.

Credits:
MS Technet
TenForums

Press [Windows Key] + [R] together at the same time, the Windows Run prompt should appear. If it hasn’t appeared press Windows Key and type Run, a Run desktop program should appear in the list
Type “gpedit.msc” and press enter
If this also fails try and launch it via the Microsoft Management Console
Local Group Policy Editor should appear
Expand Computer Configuration –> Windows Settings –> Security Setting –> Network List Manager Policies
Right click “Network List Manager Policies” and click Show All Networks
Choose your affected Network name from the right pane (If you are unsure check its name in Control Panel –> Network and Sharing Centre)
Go to Network Location tab and change the Location type from Public to Private
Close Local Group Policy Editor
Restart the computer or server for it to take effect.

Clint Boessen’s method actually worked much better for me and also didn’t need a machine reboot.

Open up Command Prompt as Administrator
Type “PowerShell” and press enter
Get a list of interfaces by using the command:
“Get-NetConnectionProfile”
You will want the InterfaceIndex as I prefer to specify exactly the interface to be modified (Required when you have more than one network cable attached)
To modify the interface you require use the command in Powershell, however swap out and choose whether you want Private or Public set:
“Get-NetConnectionProfile ¦ Set-NetConnectionProfile -InterfaceIndex -NetworkCategory

Filtering in Event Viewer Windows Server 2008 onwards

Published / by Chris Smith / Leave a Comment

The Event Viewer from Server 2008 onwards is XML based.
Filters based on XML syntax can be used such as:

You can search for anything which appears in the data section such as service names, error messages etc..

Notes:
MS Technet

Simple error checking when running batch files from T-SQL in SQL Server

Published / by Chris Smith / Leave a Comment

A while ago we added error trapping to the batch file called by a SQL script, this was to ensure if a program failed the rest of the process would not run:

After ensuring the program would return an error level if something went wrong we then I then used the ErrorLevel and an if statement. If the error level is equal to or greater than 1, I make it go to the end of the file and exit with code 1 (By default its zero which normally means the batch or program executed as expected)

We then modified our existing code in SQL to ensure the batch program is run and the exit code is captured in a variable. It can then be dealt with and the example below can easily be changed to suit whatever is required.
 

Credits:
SS64
Microsoft MSDN (Example Set C)

Microsoft Access 2010 loader

Published / by Chris Smith / Leave a Comment

Credits (As what I consider the hard stuff was actually done by other people):
TheSmileyCoder for the solid awesome little VBS File, this basically gets around the limitation of not actually getting Access to load another Access Database. At the time I only ever needed one modification (A rarely issue affected two P4 machines with a 5400RPM drive and bloated AV software). More than likely WScript.Sleep(200) won’t be required and the original file can be used.
UtterAccess for the AddTrustedLocation code.
AccessMVP as for this loader I tend to use the DSNLESS code to remove the need to deploy yet another ODBC link to user machines.
VBA Tips and Tricks for the FileExists module.

About:
The following contains what I call the Microsoft Access 2010 Loader. It was put together to try and stop heavily used Microsoft Access database front ends from corrupting (We had a point where one particular Access front end would be corrupted up to 3 or 4 times a day as around 40 to 50 people would be in a 40MB Access front end at any time). The included version will require the table to be linked to a database, we use a central SQL database.
This access file will treat its own filename as the file it will launch, so be aware the loader and your actual access front ends needs to be located in different places.

What does it do:
It checks if a copy of the Access front end and VBS file exists locally (I use the %appdata% folder, you may want to use another location or %localappdata% instead)
If it exists it checks if the version in registry (HKEY_LOCAL_USER\Software\VB and VBA Program Settings\\Version\Version) matches what is in the database table “dbo_access_version_master”
If it doesn’t exist locally or the version does not match it then downloads from a location such as “\\myserver\access$\”
If downloaded the registry is updated with the new version number
It then passes parameters to a VBS file created by TheSmileyCoder and launches it

Limitations:
The first form of the called Access file MUST have VBA code of some sort or else the Access file simply closes.
I haven’t found a way to detect if a local copy of an Access ACCDR file has corrupt VBA.
I have found users copy and rename the loaders file breaking it, try and ensure shortcuts are used.
I haven’t been able to trap where Windows AD accounts have expired or locked, as the error occurs when Access connects to our central SQL database.
If the locations aren’t added to the Trusted Locations the user will be prompted twice to allow the Access files to open. The loader uses code to add this on first launch.
I sometimes find the repaints don’t always work.
Looking at the code used its a bit horrible looking, more than likely it can be optimized much better.

What do I need to change in VBA (Alt + F11):
Replaced in the VBA code “MyCompany” with your own on the main form and module SwitchFrontEnd.
Replace \\myserver\access$\ with where you will store your files (I used access$ as this is hidden if someone views the server)
If you don’t use .accdr files replace .accdr on the forms code

The actual files:
Microsoft Access Loader Files

Why use ACCDE and then ACCDR Access Front Ends

Published / by Chris Smith / Leave a Comment

Nearly every single Microsoft Access “database” I use has a proper database attached instead of using the internal Jet Engine, this means data is not actually stored in the Access “database” and I therefore call them Access Frontends.
Compiling your Access front ends to ACCDE provides a compiled copy of your Access Front End.
I find it is much harder for users to corrupt the Access front ends when compiled.
Making a compiled Access ACCDE file a runtime file is as simple as renaming the extension from ACCDE to ACCDR, all this does is make sure full installs of Microsoft Access launch in the runtime mode. It also means you can use the Access Runtime which is free from Microsoft (However always ensure you read through the EULA).
As runtime mode is used, its easier for development as I don’t have to hide menus.

To create an ACCDE from a Microsoft Access file, open the file in question, ensure your “Visual Basic for Applications” Code compiles otherwise the next step will fail.
Go to File –> Save & Publish –> Make ACCDE
Save the file in the location you want.
You can now rename the extension from ACCDE to ACCDR.
Now test the file launches.

Within a batch file run a program for a certain length of time before killing it

Published / by Chris Smith / Leave a Comment

I needed to run a scheduled batch job and kill it off after a certain amount of time, this was because the program would run what it needed and then run as normal (If it exists then there is no reason to use start or timeout). As it actually ran as a service I didn’t want to leave it running in this way.
As I use Taskkill on the programs exe name, obviously don’t use it if it will be run on a server where it is running other executables with the same program name.
I replaced timeout with ping as the process launched fully utilises the CPU cores.

Credits: I replaced my use of timeout based on a suggestion on SS64.com

Windows 10 Remove Unwanted Bloat from Windows 10

Published / by Chris Smith / Leave a Comment

A number of the default “apps” that Microsoft provide tend to get on my nerves, as I have Skype and Office already installed I was annoyed to see the “Get Skype” and “Get Office” were listed.
I tweak the below on all new machines as some members of my family do have a Windows Phone (So in some instances I leave windowsphone and people).

Credit: MS Technet

Outlook 2010: VBA delay sending of emails until the next working day if outside of reasonable hours

Published / by Chris Smith / Leave a Comment

This Outlook 2010 VBA code was used to impose a time when emails could not be sent and were instead delayed until the next work day.
This was put together (Credits go to key parts of this VBA are in the actual code) because the Managing Director where I work realised he was making people work outside of their core hours.
The script however will send emails if the email is set to high priority or if a user is in the email group “Send_at_all_times”.
Restrictions include having to sign the code (Otherwise Outlook VBA security has to be lowered), the other is since the code doesnt do anything fancy it will always send if someone it sends to is in the group “Send_at_all_times”.

    This has only been tested in Microsoft Outlook 2010 on Windows 7.

Compress and move existing Windows 2012 and Microsoft SQL Server 2008 Express backups

Published / by Chris Smith / Leave a Comment

The following has been used to backup a server with Cisco Cubac on. The software runs on Windows 2012 machine and uses SQL Server 2008 Express.
As its not on a managed server I had to find a way to backup the server and the database, plus keep the backup as small as possible.
I get the Windows backup tool to backup once a day and save it to D:\WindowsImageBackup\, I then get the script below to run which then backs up SQL Server 2008 Express separately. I then get the backups compressed with 7zip and move them to a network storage device.
The destination NAS required a username and password, I had to put in a username and password (Not recommended although I believe SAMBA may not have been configured correctly).
If the server was on the same domain as the backup destination then get rid of “/user:username Password” from the net use line, normally having an account with the same username and password should work.

This batch requires RoboCopy (I believe is installed with the OS), 7Zip, a destination device and lots of disc space to fit the backups.

This has been used on a server with Windows 2012 and Microsoft SQL Server 2008 Express to backup a Cisco Cubac install.
The script will call SqlBackup.sql to tell SQL to backup the databases (As it installed with SQL Server 2008 Express).
Everything surrounded by <> needs to be changed, anything calling a directory needs to be checked.
%hostname% is not used for ServerHostName variable, its used for the SQL instance name (Which normally is the hostname).

This second file (SQL Backup File for Microsoft SQL Server 2008 Express) is called separately, above I have called it SqlBackup.sql in the folder specified in variable BackupScript.

Synctoy 2.1 setup batch script

Published / by Chris Smith / Leave a Comment

This code was used to speed up the setup of SyncToy 2.1 (I see no reason to backup the entire user profile folder, but I hate having to setup multiple sync jobs). As Microsoft has not updated SyncToy it may not work on anything other than Windows 7.
The script expects SyncToy 2.1 is installed and that the destination is always the H drive (For whatever reason I am not using a variable for the main location, I may update this at some point as code to select another path is already in).