Tahir Hassan's Blog

My Technical Notes

Work Blog

Monday, 15 August 2016

Executing a PowerShell Script via a BAT file and Capturing Output

Friday, 5 August 2016

Pasting an Image into Org Mode on Windows

The following is the answer I posted on StackOverflow.

My solution is for the Windows platform. Many thanks to Assem for giving his solution on which I based mine.

I wrote a C# console app `CbImage2File` that writes the image on the clipboard (if there is one) to a path given as the command line argument. You will need a reference to System.Windows.Forms assembly.

I use Greenshot to take the screenshot, which (via its configuration) automatically copies the screenshot to the clipboard.

I then use a shortcut `C-S-v` to paste the image in the org mode buffer using the function `org-insert-image-from-clipboard`:

This function will work out a file path, then invoke the C# app to create `png` file, then it will add the image tag and then call `org-display-inline-images` to show the image. If there is no image on the clipboard, it will paste in the response from the C# app.

Tuesday, 2 August 2016

Zip a Code Directory using 7zip command line

This solution using the command line application of 7z.

If you have a folder called `myproject`, then we can create a zip file containing this folder using a bat file in the same folder at `myproject`:

If you wish the contents of `myproject` to be the contents of the zip, then you use `.\myproject\*` instead of `.\myproject\`.

Monday, 11 July 2016

Getting rid of Woolly Aphid

  • Use a hose and blast them
  • scrub them with a brush dipped in soapy water
  • Wipe with methylated spirits

Thursday, 7 July 2016

Adding User to Local Administrators Group using Powershell

The following script, which needs to be run as administrator, adds a user to the administrators group using Powershell:

Replace `<domain>` with the domain and `<username>` with the username.

The following script will add the user to the administrators group, if they are not already a member, and then logoff:

To run this script as a desktop shortcut, we set the target to:

It will automatically resolve the `powershell.exe` to the full path of the Powershell executable.

Lastly, we can set the icon of the shortcut to an icon found in:

Task Scheduler

This script can be run using the Task Scheduler. Use `Action` -> `Create Task`.

The following simplified script can be used:

Follow the referenced guide. Make sure the following is true:

  • On the General tab, make sure "Run with highest privileges" is ticked.
  • On the General tab, Select "Run whether user is logged on or not"
  • On the General tab, on the Security Options bit, click on the "Change User or Group..." button and select the administator user.
  • Add a trigger, whereon the "Begin the task:" says "At startup".
  • Use the following batch file to run it

Friday, 1 July 2016

TheSage - Dictionary and Thesaurus App for Windows

Check out TheSage, which is more than a dictionary and thesaurus combined.