All posts by admin

Helpful Windows Admin Tips


To launch Windows Update from the Windows Run dialog:

ms-settings:windowsupdate


Use Powershell to kill processes with a name filter:

Get-Process | Where-Object {$_.Path -like "*SOME-FILTER*"} | Stop-Process


See what time computer was booted up:

net statistics server


Restart or Shut Down a Remote Computer and Document the Reason (https://technet.microsoft.com/en-us/library/cc770416(v=ws.11).aspx)

shutdown /i


 

Debugging Angular2 apps in Visual Studio Code

I couldn’t debug TypeScript from my Angular 2 app files at first…

but then I got it working. Here’s how:

(Note: The environment used here was Windows 10 and a beginner Angular 2 app cloned from the Angular Quick Start repo from the Angular Github repo. If you’re on a Mac or Linux system, I can’t say whether the solution presented he will work for those environments.)

This post explains my trouble (and solution) of using the the Microsoft VS Code Debugger for Chrome extension to debug my first beginner Angular 2 app from within VS Code.  I let VS Code create the default launch.json  file that is required (details in this link: https://code.visualstudio.com/docs/editor/debugging) , but when I started the debugger from inside VS Code, and I put a breakpoint on a line of code in a TypeScript file (.ts), VS Code complained that it could not find the corresponding .js file (therefore it could debug from the .ts file), and it put a little gray circle beside the line of code, instead of the typical red dot, with a warning:

“Breakpoint ignored because generated code not found (source map problem).”

When searching the web about this issue, all of the suggested launch.json code examples from various posts I found all looked very similar in what they suggested was required to fix the issue, but I never could get any of them to work for my app / dev environment. But, I finally found one that did work for my beginner Angular 2 project, which I had begun by cloning the Angular 2 Quick Start repo.

I found the magic solution for me in one user’s example that he posted to an issue on the VSCode GitHub project: https://github.com/Microsoft/vscode-chrome-debug/issues/367 and again the issue of where the generated .js and .js.map files are located (in a Windows environment) is addressed in this issue: https://github.com/angular/angular-cli/issues/1223

Now it works!

Here’s the part from his included code that worked for me:

IMPORTANT: Kill all current VS Code and Chome instances to start fresh.

After making this change to my launch.json, I made sure to kill all existing VS Code instances and all Chrome instances. Then I used npm start  and then I started the debugger from inside VS Code. It then launched its own instance of Chrome to start my app, and finally, VS Code debugger was able to trace into the .ts code because it was finally able to find the generated .js code.

.gitignore changes

I also found that I needed to add two folders to my .gitignore  file:

 

Configure Windows Defender using PowerShell

References

I found these 2 links very helpful and informative which explain how to use PowerShell commands to observe the current setting of Windows Defender and make configuration changes such as disabling and enabling, and how to add exclusions on certain apps.

#1

http://www.thomasmaurer.ch/2016/07/how-to-disable-and-configure-windows-defender-on-windows-server-2016-using-powershell/

#2

and this one, which has a short but helpful video: http://www.netometer.com/blog/?p=1579

Add Windows Defender exclusion for iBackup exe

In my case, I wanted to add an exclusion for the iBackup exe which runs nightly to do a local disk backup to another drive on the same machine, and Windows Defender was watching every file write operation in real time, and this made the backup take a very long time. So, I added an exclusion for the iBackup processes exe using this command, and it sped up the backup tremendously:

 

Manually update Windows Defender to fix update failures KB2267602 (Definition 1.213.6196.0) – Error 0x80070643

On a few of my Windows 10 computers, Windows Defender was failing to update properly through Windows Update.  I found that you can manually update Windows Defender using this command from a terminal window:

I found this instruction in the comments of this post: https://answers.microsoft.com/en-us/protect/forum/protect_defender-protect_updating/definition-update-for-windows-defender-kb2267602/d0d06c7a-fd70-4f27-94a6-9320d8114768

Set Windows local user account passwords to never expire

I found this helpful instruction from @hansb1 to prevent Windows local user account passwords to never expire:

Open a Command Prompt as the administrator mode, then run the following command:


Your password will never expire.

Thanks @hansb1!

You can see his answer given in a comment to this Bleeping Computer post: https://www.bleepingcomputer.com/forums/t/565081/cannot-set-password-never-expires-server-2012/

Sql Server queries using PowerShell – Lesson 1

It’s actually pretty easy to throw a SQL query against Sql Server using PowerShell.   This would be very familiar to any C# or FoxPro developer, so don’t let the mystery of Power Shell scare you away from exploring this handy tool.

Here’s a tiny code snippet to show you how simple it is:

powershell_screenshot_1_getting_started

Note that the call to the DoSql() function is a wrapper function that I wrote which creates a few PowerShell objects to do all the low level work so that you don’t have to repeat all that connection and plumbing stuff in your scripts. Once you have that in place, executing Sql queries is a piece of cake.  After you get back the query results, PowerShell has all the standard language features you’d expect such as looping and counting, and even some cool sorting and filtering tricks that are pretty handy for working with the data rows.

Helper functions

 

From here, it becomes really easy to add system admin things shooting off an email, or calling a Stored Proc, or writing a Windows Event log entry, or call an external API, or blah-blah-blah.

Every modern version of Windows has PowerShell pre-installed, and it even has a simple IDE (Called PowerShell ISE ) to give you a coding environment with intellisense, code completion, and debugging tools.

Note: I found this article very helpful in learning how to do this: https://cmatskas.com/execute-sql-query-with-powershell/

Message Queue solution for Visual FoxPro applications

Download from git repo here: https://bitbucket.org/mattslay/foxpro_message_queue

Job Queues, Message Queues, Message Broker, Asynchronous Processing…  There are many names for this very helpful architecture where you take a process that holds up a user’s workstation for several seconds, or even minutes, and move the work to another machine (i.e. server or other workstation) to be processed offline, “in the background”, aka “asynchronously”,  either immediately or at some later time.

Using some helpful classes from the West Wind Web Connection framework (also available in the West Wind Client Tools package) we can implement a robust Message Queue solution in Visual FoxPro.  All it takes is two simple steps:

Step 1 – Submit a “Message”:  Create and submit a simple Message record to the QueueMessageItems database table which has the name of the Process or Action that you want to execute, along with any required parameters, values, settings, user selections, other other criteria required to complete the task.  Boom… in a blink the local user workflow is finished and they think your system is the fastest thing in the world, because now their computer is free in a few milliseconds and they can resume other tasks.

Step 2 – Process the “Message”: Down the hall, you are running a Message Queue Processor on a server or other workstation that can access the database, network drives, printers, internet, make API calls, etc needed to complete the task.  Once the Message (i.e. task) is picked up by the Processor it is marked as Started, and when all the processing is finished the record is marked as Complete. Along the way you can send other other messages, emails, SMS text messages, reject messages, etc.

Message Queue Monitor – UI Form

A simple UI form allows you to observer all the Message processing as it happens.

message_queue_monitor_form

Other great benefits of this pattern and architecture:

  • You wind up with a complete log of who submitted what, and when, how long it took, and if there were any errors processing the various messages.
  • You can direct certain types of Message to different “Queues” so that you can halt processing of certain Queues if you wanted to.
  • You can re-process any requests that failed, in case there were errors other reasons that the task could not be completed at that time.
  • You can launch multiple instance of the Queue Processor to handle Messages in one or more Queues if you have heavy workload or wanted to focus horsepower on a certain Message type.

“Multi-threaded” processing

Another thing this allows is that on the “server” (i.e. whatever machine is running the Message Processor app) , you can actually launch MULTIPLE instances of the Message Processor, and that lets it run essentially achieve the performance of a multi-threaded app because you are processing several Messages simultaneously.  FoxPro’s single-threaded architecture can be circumvented with this approach. No need to wait for sequential processing of each Message.  When running on Sql Server, it calls a Stored Proc on GetNextMessage() and it also flags the record as in-process so that other running instances will not pick up the Message.

Example uses

  • Generating and printing reports
  • Sending emails to clients or customers
  • Batch processing that run long queries, Insert, or Update statements
  • Calling external APIs that may have slow response times, or be totally offline that the time the task is initiated.

Specific case

I recently used Message Queue to solve this nagging problem… When printing a particular report from a form in our FoxPro app, the form (and user) is held up for about 3-4 seconds while the report renders and spools. That doesn’t sound like much, but I *hate* waiting that amount of time every time we print a new Shop Order to sent out to production. It happens dozens of times per day for several users.

So… Using the West Wind Message Queue, it now submits a Print Request Message to the Message Queue, which takes about 30-50 milliseconds, and the user form is never held up at all waiting for the report to print.  The Queue Message Manager (which is a VFP app running on the server), picks up the Message and prints the report.

Conveniently, it prints to the default printer defined on the server, which is the main printer central to all users, which is the same one that is the default printer on everyone’s desktop.  If you needed to send the report to a specific printer, you’d just have to add that printer name using loAsync.SetProperty(), then do Set Printer in the Queue Manager code to control where the report comes out.

You can do it too

Consider this asynchronous architecture if you any such hold-up, or long-running-processes that your users wastefully wait for each day on their job.

References

You can read Rick Strahl’s extensive whitepaper on his wwAsync class. (Note: the whitepaper is kind of old, and the focus there is on how his Web Connection framework uses the wwAsync class to handle back end processing in web apps, but using this on a LAN or desktop/Client Applicaiton works exactly the same way.) Documentation of each method and property can be found here.

.Net Version

There’s also a more robust .Net version of this same framework. It has even more features for managing multiple threads, multiple Queue, and much better live GUI that runs in in a web browser.  It’s an open source project on GitHub :  https://github.com/RickStrahl/Westwind.QueueMessageManager

FoxPro Code samples

Submitting a Message:

message_queue_code_sample

Message Processor – handling the Message request

message_queue_processor_sample

XML data to pass values

The required parameters, values, user choices, etc, are stored on the Message record in an XML field using the SetProperty() method when creating the Message, and can be retrieved using the GetProperty() method when processing a record.

XML example of data stored on a Queue Message:

message_xml_sample

Here’s what the message look like in the QueueMessageItems table:

messages

Message item data structure

Here is the data structure of the fields used on the QueueMessageItems table. Some of the fields are managed by the Message Manager class, several are available for your use in constructing and processing the message.

queue_message_item_data_structure