Tag Archives: Windows

Change network profile name and type in Windows 8

The Network and Sharing Center in Windows 8 is kind of useless in many ways. There is for example no way to change the name, so you might be stuck with a dumb “Network 3″ identity. There’s also no way to change between the Public and Private types if you want to change what you selected when you initially connected to the network.

So, on your own responsibility, here’s where to find those profiles in the Registry Editor.

  • HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\Windows NT \CurrentVersion \NetworkList \Profiles

Of particular note is the ProfileName and the Category. The last one can have the following values:

0

Public
1

Private
2

Domain

BAT: Change working directory to directory of script

Sometimes you want a batch file to always run with the directory of the script as the working directory. Not whatever directory you ran it from.

@echo off
pushd %~dp0
do stuff
popd

Here pushd changes the directory to %~dp0, which is the directory of the running batch script. popd returns to whatever it was when the script started running. Not sure if the last step is necessary, but there you go anyways :)

What’s keeping my Windows computer awake

Just discovered a very simple way to find what’s keeping my Windows computer awake.

  1. Open up an elevated command prompt.
  2. Run the following command
    > powercfg -requests

While playing a video in Windows Media Player I get this output:

DISPLAY:
[PROCESS] \Device\HarddiskVolume2\Program Files (x86)\Windows Media Player\wmplayer.exe

SYSTEM:
[DRIVER] High Definition Audio Device (HDAUDIO\FUNC_01&VEN_10EC&DEV_0888&SUBSYS_1458A102&REV_1000\4&1454c4ac&0&0001)
An audio stream is currently in use.
[PROCESS] \Device\HarddiskVolume2\Program Files (x86)\Windows Media Player\wmplayer.exe

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
None.

Simple and clear!

Bat: Some simple things to make batch scripts more helpful

Tried to make a helpful batch script for something at work and learned some new things I thought I’d write down here so I know where to find it later.

Turn off echoing

Should be known by everyone really, but in case you don’t. Prevents the commands in the batch script and the command prompt to show up while the script is running. Beginning a line with @ does this for a single command.

@echo off

Comments

REM Some comment
REM Will still appear as a command if you haven't disabled echoing

Labels and goto

Trivial, but I keep forgetting about this since I never use it in other programming.

goto end
REM Will be skipped
:end

Set title of command prompt

title MyScript: Doing x now

Check command line arguments

if "%~1"=="" (echo Usage: test.bat path && goto end)
if not exist %~1 (echo %~1 does not exist && goto end)

Simpe choices

choice /c ny /n /d y /t 10 /m "Do you really want to do this? [y=10s,n]
if ERRORLEVEL 2 (
    echo Ok, I'll do it
)

Run other batch scripts

If you don’t use the call command, the other script will actually take over and your script will end.

call other.bat arg1 arg2 ...

Do the same thing with various subjects

for %%x in (
    a
    b
    c
) do (
    echo %%x
)

Quick’ish way to swap between Java versions on Windows

Here’s a sort of quick way to swap between Java versions on Windows without having to change any environment variables and restarting your console window and such. The short version is to create symlinks to your java versions and then a single symlink called for example ‘active’ which points to the one you want. In your environment variables java_home and path you’d then point to this ‘active’ symlink instead of the actual installation. You can then fairly quickly swap out the target of the ‘active’ symlink and, tadaa’ish, you have a different version.

Setup

  1. Open up an elevated command prompt.
  2. Go/Make somewhere you want this.
    > c:
    > mkdir \dev\java
    > cd \dev\java
  3. Set up the symlinks
    > mklink /d 1.5 "c:\Program Files\Java\jdk1.5.0_22"
    > mklink /d 1.7 "c:\Program Files\Java\jdk1.7.0"
    > mklink /d 1.6 "c:\Program Files\Java\jdk1.6.0_27"
    > mklink /d active 1.7
  4. Set your JAVA_HOME and PATH environment variables. *
    setx JAVA_HOME "C:\dev\java\active" /m
    setx PATH "%JAVA_HOME%\bin;%PATH%" /m
* The second command assumes you don’t have Java in your PATH already. If you do, you should edit it the usual way instead. Also note that if JAVA_HOME is already set, it will be expanded in the second command.

Now open up a new regular command prompt and run the following.

> java -version
> mvn --version

Both (skip mvn if you don’t have maven installed) should report Java version 1.7.

Swapping

So, let’s say we want to change to java 1.5, we just need to run the following in an elevated command prompt.

> cd \dev\java
> rmdir active && mklink /d active 1.5

If you now repeat the version checks we did in our regular command prompt they should both report version 1.5 instead of 1.7. And we didn’t even have to restart the command prompt.

Shortcut

To prevent us from having to do this manually we could also create a simple bat file. I made one I called swap.bat which I put in the same directory as the symlinks with the following contents.

@echo off
cd \dev\java && rmdir active && mklink /d active %~1

You could then create a short cut to for example c:\dev\java\swap.bat 1.5, set it to run as administrator, and you’d have a two click solution to change the Java version to 1.5. I created one shortcut for each version.

If you have a better way, please leave a comment though. Always on the lookout for things and techniques that can make my developer life simpler :)

Default location of pinned Windows Explorer icon on taskbar

On Windows 7 and Windows 8 there is by default a Windows Explorer icon pinned on the taskbar. By default, when you click this, it opens up an Explorer window showing you your Libraries.

I don’t care much about Libraries, and when I do I just access them in the sidebar anyways. I want Computer to be default and found a way to do that at leonmeijer.nl.

  1. Right-click the pinned Windows Explorer icon
  2. Right-click the Windows Explorer item
  3. Select the Properties item
  4. Select the Shortcut tab
  5. Replace the contents of Target with
    %windir%\explorer.exe ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
  6. Click OK

That GUID there is the Windows Class identifier (CLSID) for My Computer.