Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Friday, 7 October 2016

Web request with HTTP authentication from Powershell

Web requests can be made from Powershell with HTTP authentication in the following 2 ways:

1. Using credential objects
$username = "foo"
$password = "bar" | ConvertTo-SecureString -asPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($username,$password)
$res = Invoke-WebRequest http://localhost:3000 -Credential $cred
$res.Content


2. Adding appropriate header
$acctname = "foo"
$password = "bar"
$params = @{uri = 'http://localhost:3000';
                   Method = 'Get'; #(or POST, or whatever)
                   Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($acctname):$($password)"));
           } #end headers hash table
   } #end $params hash table
$var = curl @params


Curl above is same as Invoke-WebRequest because on Windows, by default curl is just an alias to Invoke-WebRequest.


A JSON request with a body can be made as follows:

$res = Invoke-WebRequest http://localhost:3000/stores -Credential $cred -Method POST -Headers @{"Content-Type"="application/json"} -Body (ConvertTo-Json @{"Key"="Value"})

Wednesday, 22 June 2016

Robocopy

Robocopy is remarkably different from other copy commands. It is often used in msbuild projects but there are a bunch of caveats which would appear non-intuitive to a first time user. The reason people consider using it is because it allows retries and after parameterised wait intervals.

The default syntax of robocopy takes folders as parameters and copies source folder to destination. To copy a file, the syntax is the following:

robocopy C:\source C:\destination filename.ext

Notice that filename is not part of the source here. Also, because of this limitation a file can not be copied to another location with a different name. Due to this, in msbuild projects, you need to copy the file using robocopy (assuming you use robocopy) and then rename it.

Thursday, 19 May 2016

Last Shutdown time on Windows


Checking the last shut down time on Linux is as simple as reading through logs. On Windows, it is not as straight forward though. Recently, I needed to find the last shutdown time of my Windows desktop. I knew System events is what I should be looking at but searching through the logs is not as easy as a regular expression. After some reading, I found that I can filter the log with the following parameters to search for the shutdown events.

Event source: USER32
Event Id: 1074

Thursday, 28 April 2016

Pull from a shared Windows machine

As a distributed version control system, one of the benefits of using git is that you can pull from anyone's repo just as you would do from a server. With Git's support for SSH, it is very easy to do it on Linux. Two Windows machines don't talk SSH to each other though. So, I was not sure  how to pull from my repo on one Windows machine to another. It turned out equally easy though (may be easier).

git pull file:////<machine_name>E$/path/to/repo/root

Drives like E: and C: get replaced by E$ and C$ respectively. As both of my machines were on the same domain, it was easy. Sharing might come into picture for machines on different domains.

Monday, 27 July 2015

WDFME.exe using up resources

Recently, I found CPU usage stagnating at 100%. Task manager showed that aggregated CPU usage of all my processes consumed was much less than that. Check processes owned by all users, I found WDFME.exe consuming CPU heavily. It seemed quite unnecessary as my hard disk is of Seagate and the "WD" in the name suggested "Western Digital". So, I killed it. It is essentially the software that comes along with Western digital external hard drives. As it turns out, it is not necessary and it a known resource hog.

Monday, 29 June 2015

Idle windows isn't really idle

My laptop running Windows 7 using using 50% CPU when it is idle. I don't know why but this allows me very less resources to run other programs.
No programs running.
Any suggestions are welcome.

Wednesday, 14 May 2014

Do not save VBS file in UTF8 encoding

Recently, I had to run a VB script as suggested here. I do not have much experience on Windows; but I often keep my source code in utf8. I also have my IDE set to it. So, when I saved the script I opted for utf8. However, when I ran the script, I got a strange error. Since, I had opted specifically for utf8 overriding the default, I tried saving in the default character encoding, i.e. ASCII and the script ran fine. Reading about it, I can see that ASCII and utf-16 are supported. So, lesson learned: do not use utf8 on windows.

Thursday, 9 May 2013

Operating on each file in a directory in Windows Powershell

Recently, when I had to do some tasks on a Windows machine, I thought of trying out the Powershell. I had to process every file in a directory. In linux, I could easily do it on the command line so I tried to find out similar way for Windows. It turned out to be fairly simple actually.

$files=get-childitem .
foreach ($file in $files) { echo $file.fullname  }

Sunday, 30 October 2011

Funny Windows

I am using Windows 7 Service Pack 1. Windows might have got a bit more secure and flashy than Windows XP; but it continues to be funny. Today morning only, I encountered the following queer incidents.

1. In the (My)Computer window, I wanted to see Properties for each drive. So, I directly right clicked on them. However, each time it took me to System Properties. To get to Properties of a drive, I had to first select the drive and then right click on it again and select Properties.

2. While cleaning up my C: it showed 730mb will be cleared. Before cleaning, my C: had 6.77gb free and after cleaning it had 8.33gb free. Strange calculation indeed.

3. Last night, I had just put the lid of my system down and slept. According to my Settings, the system should have gone to Sleep mode too and most likely it did. In the morning, I was unable to connect to my wireless network. After banging my head for being forced to use such a system that does not offer any clue as to what the error was, I decided to try a restart. During restart, I found some disk corruption was causing the trouble. [Using Linux on the same machine for years, never gave me a disk corruption.] Also interestingly after recovering from corruption, I found that my wireless card was set to configure to IP address 192.168.190.1 with subnet mask 255.255.255.0 though I had set it to obtain the IP address automatically.

Friday, 24 June 2011

Mouse vs keyboard


Over the years, we have had a conflict between two groups of users: GUI-friendly and CLI-friendly. Mostly the CLI-friendly people think that the keyboard is faster than mouse while the GUI-friendly people think that the mouse is faster. A research by Apple shows that actually it is the mouse that is faster in most cases although people think the keyboard to be. However, it is not the metrics that matter; but the mentality that is developed.

A programmer typing in full flow is very unlikely to break his flow and hold the mouse. He probably would prefer the whole window to be controllable from the keyboard. That way the interface is letting the programmer do his job without being distracted towards using a mouse. Emacs is a classic example of this.

However, people who work primarily with the mouse like desktop users who are copying files or playing music can use the mouse with ease letting the other hand rest.

Apple and Microsoft provide a nice GUI interface and are doing good business because most of their users are GUI-friendly. However, linux allows choice. There are great GUI windows managers like Enlightenment and there are also tiling window managers like awesome.

Tuesday, 7 June 2011

Reading extended file system partitions in Windows

Ext2 and Ext3 partitions can be read in Windows using the open source driver available at sourceforge. However, windows does not treat files in a case sensitive manner as does linux. So if you have two files "data.txt" and "DATA.txt" on your linux partition, Windows will only be able to show you the contents of "data.txt".