Tuesday, March 24, 2020

Launching a playlist in VLC with one click

I should note I have a Windows 7 system. Not sure how this would work with Windows 10, I am sure it's harder and more restrictive.

Some time ago, the "play all" feature in file explorer stopped working correctly. I have all my media files associated with VLC and when I clicked on "Play all", it would open the songs in the folder with VLC.  Cool. Something happened and Windows started insisting on using Media Player instead, even though Media Player is not set as a default program on my system for anything. I could not find a solution to that issue (everyone said to set my default programs, but that's set!) so I got creative.

I created a sweet little batch program.

1) Open Notepad as administrator
2) In the Notepad document, type:

@echo off
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" --playlist-autostart --loop  --playlist-tree "D:\Fun\Music\favorites\"

The second path (D:\Fun\Music\favorites\) should be edited to be the path to where you keep your music.

3) Save the file on your Desktop

Whenever you feel like launching your favorite playlist, double click on the file. Voila.

If you want to edit the file and not launch VLC, then right click and select "edit". The file will open in Notepad.

Tuesday, March 19, 2019

Getting the linux sort command to work correctly on multiple columns of numbers

In my trade (Astrophysics), I often find myself having to do something on a daily basis that no-one else appears to need. Two examples: scatter plots and sorting files with multiple columns of pure numbers.

My life would change if Excel made scatter plots by default and if the Linux sort command sorted multiple columns of numbers by default (or at least with the simple addition of the -n flag). Neither is true.

At least let me address how to get the sort command to work correctly on files that contain columns of numbers.

Say you have a file called foo that looks like this:

22500.  1000.    200.   100.
22500.   450.    200.   100.
22500.   400.    220.    50.
22000.  1000.    220.   100.
22000.  1000.    200.    20.
22000.  1000.    220.    20.
22500.  1000.    200.    20.
22000.   450.    200.   100.
22000.   400.    220.    50.

You want to have it sorted numerically, by first column, then second, then third, then fourth.

We expect:
22000.   400.    220.    50.
22000.   450.    200.   100.
22000.  1000.    200.    20.
22000.  1000.    220.    20.
22000.  1000.    220.   100.
22500.   400.    220.    50.
22500.   450.    200.   100.
22500.  1000.    200.    20.
22500.  1000.    200.   100.

No biggie you say, use the -n flag (for numeric sort).

sort -n foo

This is what you get, for some inexplicable reason:

22000.   1000.   200.    20.
22000.   1000.   220.   100.
22000.   1000.   220.    20.
22000.    400.   220.    50.
22000.    450.   200.   100.
22500.   1000.   200.   100.
22500.   1000.   200.    20.
22500.    400.   220.    50.
22500.    450.   200.   100.

Here is what we get if we specifically sort the second column, using numerical sort

sort -k2,2n foo

22000.    400.   220.    50.
22500.    400.   220.    50.
22000.    450.   200.   100.
22500.    450.   200.   100.
22000.   1000.   200.    20.
22000.   1000.   220.   100.
22000.   1000.   220.    20.
22500.   1000.   200.   100.
22500.   1000.   200.    20.


When used on a single column, numerical sort works (numbers are recognized as numbers). Used on multiple columns, numerical sort fails (numbers are treated as text).

And so to get multiple columns of numbers to sort numerically for real with numerical sort, one has to use the n flag column by column. To get the desired result, use:

sort -k1,1n -k2,2n -k3,3n -k4,4n foo

Yep, a joy when the said file contains 15 columns of numbers... And why that is not the default behavior escapes me.


Friday, May 11, 2018

Blocking programs that run without your permission (Windows 7)

In pure Microsoft tradition, the latest version of Skype comes stripped of the ability to turn off automatic updates (which always launch when you are trying to make a Skype call).

For entertainment, you can see the conversation on the Microsoft help forum.

Summarized, it goes like this:

User1 - We used to have the ability to turn off automatic updates on Skype. I don't see the option in the new Skype. Where is it?
MS - Our updates are so grand and important, and the will of the user of so little significance that we have eliminated that option. However, you can go here to download the older Skype.
User1 - Ah, OK, thanks.
User2 - I'm not falling for this. How long until the older Skype goes away entirely?
User3 - The link is already dead. Can you not treat us like idiots, please?
User4 - There is a way, you just need to hack into the OS, here is how.

Below I expand on what User4 posted (it's missing a few pieces, which I fill in).

1) Search for the command prompt and right click on it to launch as an administrator
2) At the command prompt, type: gpedit.msc
3) Hit enter and wait for the Local Group Policy window to launch (it may take a few seconds)

Local Group Policy Editor
4) In the left pane, navigate to Administrative Templates --> System. Click on System to view the items in that folder in the right panel.

The Local Group Policy Editor, with the System folder opened
5) Double click on "Don't run specified Windows applications (yours will likely say "Not configu..." instead of "Enabled"
6) Wait for a new window to launch. First thing on that new window, select "Enabled"



7) When you do that, the Show... button should activate. Click on it. Yet another window launches.


8) Yours will likely be blank. Click on the empty box with the asterisk next to it and type "SkypeSetup.exe". Supposedly, that kills Skype's automatic updates. I am also attempting to kill some annoying popups launched by the program CCleaner so I added that executable as well. You can add any programs that launch at the wrong time without your explicit permission to the list.

9) Click OK, then Apply and you can exit out of all this.

Saturday, April 9, 2016

Forcing a factory reset on a Dell computer - Performing the factory reset

If you still have the recovery partition intact on your disk, this will allow you (if it works), to force restore it to your had drive. You do not need this hack if you have a working Windows with a factory reset option that shows up, or if when you hit F8, either upon first or second reboot, you get the option to do a factory reset.

I am going to assume that you are reading this because all the easy ways to do the factory reset have failed.

To be safe, first back up your recovery partition, and anything else you want to keep. Doing a factory reset will delete your files on the hard drive.

You will need a Windows PE bootable flash drive. Instructions on how to make one here.

Once you have a bootable flash drive, it's pretty easy, if things work correctly.

Plug your Windows PE flash drive into a USB port and restart the computer. When the Dell logo appears, press F12 repeatedly until a boot menu appears. If you do not have a LEGACY BOOT menu, try to enable legacy boot options (see "Boot from recovery USB - take 3" on this post). If your USB Storage Device is not listed on the LEGACY BOOT menu, it means there is a problem with your Windows PE bootable flash drive (it is not bootable).


Use the arrow keys to select USB storage Device then hit [Enter].

Windows PE will start. At first it looks just like a Windows 7 installation (with the Windows is loading files bar, then the Windows is starting screen), but eventually, it opens to a grey background and a big command prompt window. Wait until the initialization command finishes and you have a blinking cursor at the prompt.

We are going to use a single imagex command to start the factory reset. Dell made what is called an image of the system. The original OS, all the settings, drivers, programs etc... that came with the computer are all packaged into a file called factory.wim. For newer systems, the image is so large that it gets split up. You may have a factory.wim, factory2.wim, factory3.wim. The first file, factory.wim is the one we need to launch. That file resides in the recovery partition, in the folder \dell\image. The rest of the recovery partition contains supporting scripts and files. The picture below is just to show you what is in the \dell\image folder (if you really want to know).


You need to know two things: 1) where you want to restore the OS and 2) where the factory.wim file is.

In a previous post, I covered how to backup the partition to an external storage device. If you have destroyed all the data on your hard drive and no longer have the recovery partition (but do have the backup), then you will need to transfer these files back to the hard drive first. This will be covered in subsequent posts.

To check whether you have a recovery partition on your drive and to assign a letter to it (if needed), see this post.

Now I am assuming your hard drive is properly formatted and has a partition ready to receive the OS. If it does not, you will have to prepare your hard drive first (again to be covered in subsequent posts).

You can use DiskPart (see this post) to find out what letter was assigned to the partition where the OS goes. If you have not messed with your hard drive too much yet, the partition labeled "OS" and with "boot" under Info is the one you want to restore the image to. Usually, that will be the C partition. But do make sure before proceeding.

I am going to assume you have your recovery files in the volume labeled as R. Exit DiskPart before proceeding.

To summarize: recovery files in R, OS goes on C. Insert your own letters and edit the imaging command below accordingly.

You may have read elsewhere that imagex is in the tools folder and that it needs to be ran from there. With the flash drive we created, that is not true and not necessary.

Give it a shot. type:
imagex

That will bring up a list of instructions on how to use imagex (but won't actually perform any task).


Ready? run the command (Remember to substitute the proper letters):
imagex /apply r:\dell\image\factory.wim 1 c:\

The process should start. I have a bunch of crap on the screenshot below because I ran the command wrong at first. If you get a bunch of output telling you how to use imagex instead of an "Applying progress" status, it means you typed the command wrong. Double check it. In my case, I forgot to type the "1". After I fixed that mistake, the process ran. A tip from Linux: if you do type the command wrong at first, hit the up arrow. It will bring back the command you typed originally and you can edit it, instead of retyping the whole thing.


Aaaand in my case it failed. I hope you have better luck, or that this at least got you closer to where you needed to be.

Hmm and it failed with Office15, which I don't even want. Bummer.

Forcing a factory reset on a Dell computer - Backing up the recovery partition

I am assuming you have your Linux live USB flash drive and your Windows PE bootable thumb drive. You will also need a thumb drive large enough to accommodate your Dell Recovery Partition (see this post to check its size). You will need a thumb drive with twice that size. My 12 GB somehow turned into 20 GB on my thumb drive. I am not sure if that is by design and part of the problem I encountered when trying to hack my factory reset (remember that I was not successful and that you are only trying this because you yourself have reached the bitter bottom of despair).

The idea is to backup the recovery partition to the external drive, format the hard drive, put the files back on it, and use Windows PE to restore the Dell Recovery image.

The instructions, for expert Linux users are all here. They are for expert Linux users, so I will fill in the details.

We are going to do a lot of boot-up from usb drives and some from hard drive, so review how to do that (scroll down to Boot from recovery USB - take 2)

First, boot into the Linux environment. To do that, insert the Linux Live USB into a USB port, and only that one (otherwise, things can get complicated) and boot from USB.

You should see a friendly, green desktop appear, kind of Windowsy.

The first program you want to find and launch is the file explorer (called Nemo, if you must know).

You can launch the file explorer by clicking on its icon. It is the right-most green icon in the picture above, taken of the bottom left corner of the screen (the icon to the right of the black square icon). There is a way to make these icons bigger, but we are not going to use Mint for long so we'll live with it.

If you want more windows of the file explorer, just click on that icon again. Use the file explorer to navigate to your hard drive if you still have files on it that you want to save. Linux defines file systems a little differently, so it may take a bit of poking around before you see familiar files and folders.

Open a window for your back up media and drag anything you want to save over before proceeding. That takes place of step 00 in the instructions for experts.

Since you are in file explorer, navigate to the external storage device that is big enough to put the contents of the recovery partition and create a folder called "dellrecovery". Next navigate to the root of the hard drive and create a folder there called "recoverypartition".

The next step is to backup the contents of the recovery partition on your hard drive to the folder you just created. We have to be careful with this step and it involves some hacking. The reason you can't just drag files from the recovery partition to your dellrecovery folder using the file manager is because 1) the recovery partition, being unnamed (unless you mucked around with it) does not show up and 2) we want to ensure that we copy everything and preserve their nature. That includes hidden files. There are Linux copy command flags that will catch all the hidden files and that will ensure that files permissions are preserved.

You need to open a command prompt, called "terminal" in Linux. Because it is used a lot by Linux users, there is a clickable icon for it. It is the black square right to the left of the file explorer. You get a new window every time you click on it.

For now open one terminal window. First, we need to mount the recovery partition. In order to be able to copy the files over, Linux is going to kind of copy the files that are in the recovery partition ot the recoverypartition folder you just created. Linux does not really copy anything over, but it will look like that to you. The contents of the recovery partition will show up in the recoverypartition folder once you type the command we are going to put together next.

Before you can put together the command, you need some info. We are going to get it from the Linux equivalent of Disk Management. In Linux, we use the program called "GParted". Click on the menu button and search for gparted. That part of the OS works a lot like Windows 7. GParted will show up among the programs. Click to open it and let it do its scanning.


GParted looks like this

What we are particularly interested in is the left most column that has items that read like "/dev/sda1". "dev" stands for device. "sda" refers to a hard drive. "sdb" (if present) often refers to an external storage device (or it may be a second hard drive). If you have lots of stuff plugged in, you could also see an "sdc".

Compare this output to the outputs you had from Disk Manager in Windows. If you do not have that, the size of each drive is a clue. Your goal is to find the device number for the partition on your hard drive where you created the recoverypartiton folder (i.e. "sda1").

Next, you need to determine the path to the folder on your external storage where you created your dellrecovery folder. You can read off that path from the file manager. Using the file manager, navigate to the recoverypartition folder. Go as far as to open that folder. Here is an example:

Find the button on the right I have highlighted and click on it. An address bar magically appears with something like:
/media/axk55/52987BC4987BA55F/Recovery
in it (yours will be different and will end with /recoverypartition if you faithfully followed the instructions up 'till now).

This is what you will need for the next step.

Now go to your terminal window and type
sudo mount /dev/sda1 /media/axk55/52987BC4987BA55F/Recovery

Except you need to customize it. Instead of "sda1", put the device number you noted earlier. And instead of the /media/axk55/.... path, use the one from the file manager. You can copy and paste, using the right button of the mouse (ctrl V does not work in the terminal window).

Hit enter. It may prompt you for a password, if you set one up (sudo gives you administrator rights on the command). Look on your desktop, a new drive should appear, called "recoverypartition" (I named mine Recovery instead). You can click on it to view the contents (empty at the moment).

Now we are ready to copy the files from the recovery partition into the Dellrecovery folder on the external storage device. My preferred method is to navigate to the destination folder (Dellrecovery) and then copy things over.

Open a new file manager window and use it to navigate to your Dellrecovery folder. Again, click on the magic button to get the patch to that folder. For instance, say it is:
/media/axk55/myflashdrive/Dellrecovery

In the terminal window, type:
cd /media/axk55/myflashdrive/Dellrecovery

Now you are in the Dellrecovery folder. You can check that by typing
pwd
The output should be the path to your current folder (/media/axk55/myflashdrive/Dellrecovery).

Now we do the copying. You should still have that path to the recoverypartition folder, the one we used in the mounting process. Type the command
sudo cp -Rfpv /media/axk55/52987BC4987BA55F/Recovery/ .

Notice I added a / at the end of the path. It's safer to do that, though in most cases, not absolutely necessary. Make sure to type the "." at the end of the command (with a space between the / and the .). The dot tells Linux to copy the contents of /media/axk55/52987BC4987BA55F/Recovery to your current location (in other words, "." stands for "here").

If you must know: sudo puts you again in administrator mode, cp means "copy", and -Rfpv are flags that tell Linux to copy absolutely everything without messing with any file settings and also to let you know what is going on. Then you have the path to what you want to copy and with ".", you are telling where to put that (in your current folder).

There will be output to the terminal so you know that stuff is getting copied over. Large files will take longer so at times, it will appear to pause. Give it a few minutes to finish. When it is done, the command prompt will reappear with a blinking cursor. And we have backed up the recovery partition.

Friday, April 8, 2016

How to create a bootable Windows PE flash drive

I learned about Windows PE just today, after I fought so hard with my Windows 7 installation thumb drive. Windows PE is so sweet. It stands for "Windows Preinstallation Environment". It is essentially a short cut to the command window tool that one can open with the regular Windows 7 installation drive, but also comes packed with extra utilities not available on the regular installation disk, such as imagex. Imagex is what we will be using at the very end to force the factory reset.

In order to create a Windows PE bootable flash drive, first you need to install WAIK on your healthy Windows 7 computer. WAIK stands for "Windows Automated Installation Kit" and it packs tools that IT personnel use to install Windows quickly on multiple computers. We only need it because it contains imagex and because it will allow us to create our Windows PE thumb drive.

Get it here, and make sure to get the one for Windows 7.

This is another iso file. You can burn it to a DVD and install off the DVD drive, or use a USB drive to install it.

If you got the USB thumbdrive route, you will need to use the Windows USB/DVD Download tool. There are other options, but this one is from Microsoft and is best for their product. I have personally tried Rufus and that failed, when the Windows USB/DVD Download tool worked.

The tool is pretty simple to use. Essentially. download it, install it, launch it and follow the instructions on the screens.

Once you have prepared your USB flash drive, you are not done. Remember that we wanted to install WAIK. Well now you have an installation disk for WAIK. WAIK is not an OS and does not require a reboot, nor is the USB bootable. If nothing launches, try to eject it and put it back into the drive. Or look for the setup.exe file or equivalent on the thumbdrive. Unfortunately, I did not document that part of the process, but I remember it being standard Windows.

Now launch WAIK. WAIK is always ran as an administrator and it is just a special version of the command prompt window. In your programs, look for "Deployment Tools Command Prompt" and right-click on it. Select "Run as administrator".

I have introduced the command prompt window in previous posts, the first one here. We are going to be using diskpart again, so that post is a good primer.

To create the bootable Windows PE disk, follow the instructions on this page. The are nice and clear (for once). I am reproducing them below only in case the page gets taken down.

Essentially, you want to copy and paste the following lines (commands) in the command prompt window, hitting [Enter] after each. Use the right button of your mouse to copy and paste. Each of these commands must be entered exactly as shown (aside from font). Every little symbol, every space or lack thereof. Welcome to computer hacking.

CopyPE.cmd amd64 C:\WinPE_amd64

DISM /Mount-WIM /WimFile:c:\WinPE_amd64\WinPE.wim /Index:1 MountDir:c:\WinPE_amd64\Mount

Copy “C:\Program Files\Windows AIK\Tools\amd64\ImageX.exe” C:\WinPE_amd64\Mount\Windows\System32\

DISM /Unmount-WIM /MountDir:C:\WinPE_amd64\Mount /Commit

The last command in the post produced an error message for me, because Windows randomly added quotation marks when I pasted the command. Watch for that:

Copy C:\WinPE_amd64\WinPE.wim C:\WinPE_amd64\ISO\Sources\boot.wim

Next you want to prepare your USB flash drive. It must be formatted a certain way. In particular, it needs to be formatted as FAT32. You may be able to use file explorer to do that, I have not tried. I used diskpart, as recommended in the original instructions.

You can use the same command prompt to run diskpart.
Launch the program and look at your disks by running the two commands
diskpart
list disk

Carefully identify which disk is your thumb drive. The best way to do that is by size.

Now select your thumb drive, partition and format it

select disk 2 (if the thumb drive is disk 2)
clean
create partition primary
list partitition (to double check)
select partition 1
active
format quick fs=fat32
assign

For me, I got some error messages after clean. If you do, try to proceed with the commands. It may do what you want it to do in the end. If all goes well, when you hit [Enter] after "assign", a window should pop up asking you what you want to do with your thumb drive. Click on "View folders".

Use file explorer the way you are accustomed to to copy files from the folder c:\winpe_amd64\iso to the usb drive. You will not be needing the rest. Your Windows PE flash drive is ready to go.


Forcing a factory reset on a Dell computer - gathering the essentials

I should say as a disclaimer that this did not work for me. I suspect because I had a bigger problem (still unsolved): Windows 7 can't find my SSD drive.

But if your computer came with a regular hard drive and the Dell Recovery partition is on that drive, you may be in luck.

First of all, if you deleted the Dell Recovery partition without further ado, you may despair now. This will not help you. You are left with a fresh install of whatever OS will work.

This how-to applies if
1) You still have the Dell recovery partition on your drive and
2) You have tried absolutely every mean under the Sun to do a factory reset (except this one).

To hack a factory reset, you will need
1) The Dell recovery partition intact on your hard drive
2) A spare computer running Windows 7 if yours, like mine, has been hijacked and destroyed by Windows 10
3) A Linux Live USB drive
4) A Windows PE USB drive
5) A third USB thumbdrive

There is a way to do it with fewer thumb drives, but it will be even more complicated.

First, let's gather the pieces.

To verify whether you have the original Dell partition on your hard drive, see this post. Take a picture of the disk manager window, the same way I did in my post. You will need to know what is what. Also, because it shows more details, use diskpart to list your partitions and take a picture of the output (see this post). For good measure, in addition to list disk and list vol, do a list partition. Record everything.

If your OS is broken and you can't boot into it, we will see other ways that you can check whether you have your recovery partition. You will definitely want to create a Linux Live USB drive. It will allow you to access the files on your computer and create a friendly environment where you can easily back them up - covered here.

If you do not have anything on your computer that is worth saving and you are a maverick, you can skip the whole Linux thing, it's for backup purposes. But if you do have a recovery partition on your disk, I highly recommend you back it up. Even if like me, you end up not being able to do the factory reset, it's always good to have it. And to properly back up the recovery partition, Linux is good.

So let's create a Linux Live USB. Here you have a choice between Ubuntu and Mint. Mint is my favorite at the moment, so I will use that, but Ubuntu (more popular) would work just as well and would be very similar on how you create and use the USB.

Linux is an alternate operating system, preferred by a small niche of computer geeks and astronomers. It has its kinks, but overall it works. It allows full control over the computer and new editions are relatively easy to use. I would say Linux has surpassed Windows in terms of being user friendly, because of nice improvements in the desktop environments of Linux and because Windows went downhill in that category. It is a light weight OS that comes in many flavors. The underlying OS is all the same, it's just the desktop environments that get slapped on top that differ. Mac users will adapt to Ubuntu more easily, while Mint has a desktop that looks more familiar to PC users.

Enough history. Let's make our Mint USB.

You will need to download an image of the OS and install a USB creator. This can all be done on your spare Windows 7 computer (or any PC really). But I will assume a Windows environment.

Download Linux Mint here. Unless you have an old computer, you will want to download the 64 bit version. Like they recommend, download Cinnamon. MATE is for Mac users. Once you get to the download page, pick a download mirror near you and click on its name. This will initiate the download of an iso file.

iso files are image files that traditionally were burned to DVDs by software like Nero. As a matter of fact, if you have a blank DVD and a DVD drive in your sick laptop, you can use that as an alternative to USB. But Linux runs beautifully off USB (not as fussy as Windows) and I will discuss the USB route.

Once you have downloaded the iso file, use a program to create a bootable Live USB drive of Mint. There are options, but one I like to use is unetbootin. It's a simple, compact program.

When you use unetbootin, you will want to click on the radio button next to "Diskimage" then click on the ... button and navigate to where you downloaded your iso file. You also need to select the USB Drive where you put your flash drive and then you click OK and watch the magic unfold. You will need a USB with a capacity of at least 4 GB.

The last piece we need is a bootable Windows PE flash drive. That's a little complicated, so it is worthy of a new post.