Archive for the 'Windows' Category

Node: Fix line endings by platform

Tuesday, December 28th, 2021

Using a Node script to query a database to do corrections was working fine on my local Windows based system until we tried to automate the process. We moved it to a Jenkins server which happened to be on a Linux system and the script stopped working. After some debugging it turned out that the way we were attempting to differentiate data returns from the queries depended on the line ending.

On a Windows system, the line endings are ‘\r\n’ or carriage return, new line. This had worked well while we were running the script locally, but once it went to the Linux system the line endings were just a ‘\n’ or new line. The line ending was not being matched so this led us to figure out how to tell what platform was being used. The process.platform variable contains the platform name.

The process.platform returns ‘win32’ for Windows, ‘darwin’ for MacOS and ‘linux’ for linux systems. There are other platforms supported but these are all that mattered to us. Using this variable we were able to replace the line endings and the data started working as expected on all our platforms.

The following code snippet sets the lineendings for our sql code:

let platform = process.platform;
let lineendings = '\n';
if (platform == 'win32') {
    lineendings = '\r\n';
}

Tags: ,

Issue with f.lux and screenshots on Windows 10

Thursday, October 22nd, 2020

Recently I was helping my daughter with some homework and it was going well. That is until I tried to take a screen shot. The screen shot came out with a red tint to everything I captured. It took me a while as I worked through if it was a Snipping Tool issue or a general screen shot issue. It was any screen shot which was even more frustrating. I searched the internet for answers and saw some issues with Lenovo laptops but I am on a HP Laptop so that was no help. I tried updating the drivers for my video cards and that was no help.

Finally I thought of what could be adjusting colors on my computer and remembered I had installed f.lux to help with my sleep patterns as it helps to make the color levels of your monitor change as the night time arrives. It turns out that f.lux was messing with the screen capture and disabling f.lux made my screen captures look correct.

Tags:

Windows 10 Screen Rotation

Thursday, March 5th, 2020

I was recently trying to read a large log file and I needed to rotate my screen to portrait mode in order to read more text. Sadly, I learned that the CTRL+ALT+<LEFT ARROW> and CTRL+ALT+<RIGHT ARROW> key combinations are not implemented by the Windows OS but with each graphic card manufacturer. And sadly many of the more recent drivers no longer support this functionality.

In order to rotate the screen you need to use the display settings.

Either : Right-Click the desktop and choose “Display Settings”

or

Start > Settings > System > Display

Next: Select the display you want to rotate and scroll down to “Display Orientation”

Choose the orientation depending on the rotation of your mount. The options are:

  • Landscape
  • Portrait
  • Landscape (flipped)
  • Portrait (flipped)

Sadly the quick switching of displays may be gone but at least the ability still exists.

Tags:

Windows GodMode folder

Monday, January 12th, 2015

I just found a way to create a settings folder in Windows 7. This God Mode folder can be created by:

1) Create a new Folder
2) Rename the folder to : GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}

Then the folder will change its icon and give you access to the settings for your computer in one place.

Windows: Add Copy-to and Move-to folder to context menu

Tuesday, September 4th, 2012

I spend a lot of time copying and moving files between folders. More often than not, when I click on a file in Explorer, I want to copy or move it to another folder. That means I spend a good deal of time dragging files around or copying and pasting them.

But with a Registry entry, you can save yourself time: you can add Copy To Folder and Move To Folder options to the right-click context menu. When you choose one of the options from the menu, you get a dialog that will let you choose the location to copy or move the file to, and then send the file there.

To add the option, run the Registry Editor (regedit) and go to

HKEY_CLASSES_ROOTAllFilesystemObjectsshellexContextMenuHandlers.shellex

This tells you it’s a shell extension key that lets you customize the user shell or the interface. Create a new key called “Copy To”.

Set the value to

{C2FBB630-2971-11d1-A18C-00C04FD75D13}.

Create another new key called “Move To”. Set the value to

{C2FBB631-2971-11d1-A18C-00C04FD75D13}.

Exit the Registry.

The changes should take effect immediately. The Copy To Folder and Move To Folder options will appear. When you right-click on a file and choose one of the options, you’ll be able to move or copy the file using a dialog box like the

DOS: Capture return values from commands

Wednesday, February 8th, 2012

When I am writing build automation scripts, there are times that I have to insure that the previous command completed
with no errors. I have found that ERRORLEVEL gets filled in with the return value from a command.

dir %1

if (%ERRORLEVEL%) == (0) echo Found File: %1
if (%ERRORLEVEL%) == (1) echo Missing File: %1

So if you save the previous in a file and run the command with one (1) argument, it will display the output of the dir command
but also print either “Found file: ” or “Missing File: “.

Tags: ,

Dos: Adding commands to the PATH

Tuesday, December 20th, 2011

When you install a new piece of software that does not add itself to the Windows PATH variable, you may find your self
needing it to be run from a command prompt. You could type the full command path each time you run the executable, but
it may be easier to add the directory to the PATH variable so that it is always available.

To add it for the current command prompt:

set PATH=%PATH%;"C:Program FilesSometool"

This will add the variable to the current command prompt environment but will go away once you close the window and will not
be available to other prompts unless you type it in again.

To add it to the Windows Environment, you can use the My Computer->Properties menu to select the “Advanced System Settings”
in Windows 7 to then select the “Environment Variables…”. Now the choice you have is to add it to the System variables or
the User variables for.

If you choose the System varables you will be adding it to the system as a whole and any other user who logs in will have
the updated path. If you add it to the User variables, then it is only available to your user.

Whichever you choose, select the Path entry and click the “Edit…” button. This will pop up a dialog that will let
you add to the “Variable Value” entry. Now you will need to decide whether you want your new path at the beginning, end,
or somewhere in the middle. You might add it to the beginning if it is being used to override an existing command. You
may add to the end if there is no conflict with other installs. And finally, you may need to choose the middle if there
are some commands you need to override but others that need to be left alone.

Entries are separated by the semi-colon “;” character in DOS.

Tags: ,

DOS: Check for empty environment variable

Wednesday, November 16th, 2011

I was writing a batch file the other day and needed to change the argumets to a command based on if the user had specified his password on the command line.

SET PASS=somepassword
: or
:SET PASS=
if x%PASS%= X (
  SET PASSARG=--password somepassword
) else
(
  SET PASSARG=
)

commandtorun %PASSARG%

Now if the user comments out his password, the script will make the PASSARG environment variable be empty or if they set a password the passarg variable will be filled in.

Tags: ,

Viewing many different video formats on Windows

Monday, October 3rd, 2011

So I lost my hard drive and went to play some of the videos that I have saved on the system and could no longer play them in Windows Media Player. I needed to download a set of video codecs to play my .vob files. I am using the K-Lite Codec Pack.

Featured Software

VIDEO CODECS
FFDShow MPEG-4
DivX 8
Koepi’s XviD Codec
DScaler MPEG Filters
Ogg Codecs
Xvid Video Codec
Nic’s XviD Codec
Ligos Indeo Codec
AUDIO CODECS
MPEG Layer-3 Codec
AC3 Filter
AC-3 ACM Codec
CoreVorbis Decoder
LAME DirectShow Filter
LAME MP3 Encoder
Monkey’s Audio
Vorbis Ogg ACM Codec

This allows me to view the files in other video apps as well.

Tags: ,

Retrieve drive letter on Windows

Thursday, June 16th, 2011

The other day I had to write a script to change to a working directory and back to the original directory. The problem was they were on different drives on Windows. So I had to find a way to capture the drive letter
and switch back to that drive. When using the following command,

cd F:somedir

you are not moved to the “F:” drive without an explicit “F:” command.

The cd Command on windows will show the current directory location. Using some string manipulation on that and capturing it to a variable allows us to go back to that drive.

REM Capture the current drive letter
set ORIGDRIVE=%cd:~0,2%

F:
REM some other scripting things here

REM Return to the original drive letter
ORIGDRIVE

The first line captures the current drive letter by specifying the first character with 0 and the ,2 states to pick up the next 2 characters which would hold the “C:” or whatever drive you started on.

Tags: , , ,