Developer OneNote

Emma's OneNote for Microsoft Windows, Office and Programming

Tag: Command line

Install PowerShell From Command Line

22 July, 2010 | Category: Script, Windows

To install PowerShell on Windows Server 2008 R2 or Hyper-V Server 2008 R2, following features needs to be installed.

  1. NetFx2-ServerCore
  2. NetFx3-ServerCore
  3. MicrosoftWindowsPowerShell

Because Powershell is built on DotNet framework, DotNet 2.0 and 3.5  has to be installed prior to PowerShell installation.

To install PowerShell from command line, run following from elevated command prompt

DISM.exe /online /enable-feature /featurename:NetFx2-ServerCore DISM.exe /online /enable-feature /featurename:NetFx3-ServerCore DISM.exe /online /enable-feature /featurename:MicrosoftWindowsPowerShell

Or run following command if it’s an 64bit machine

DISM.exe /online /enable-feature /featurename:NetFx2-ServerCore-WOW64 
DISM.exe /online /enable-feature /featurename:NetFx3-ServerCore-WOW64 
DISM.exe /online /enable-feature /featurename:MicrosoftWindowsPowerShell-WOW64 

Enable DotNet 3.5 from command line

4 July, 2010 | Category: Script, Windows

To enable DotNet 3.5 from command line, run following from elevated command prompt

dism.exe /online /enable-feature /featurename:NetFx3

Access denied when creating a folder just deleted

24 April, 2010 | Category: Development

I have a batch script which remove a folder and re-create it. The command that remove a folder is rd /s/q and the command create folder is mkdir. Recently I see something weird happening, everytime when the folder is deleted and re-created, there is error message Access is denied displayed. However, if I rerun the create folder command laer, it always pass successfully.

The explanation on http://support.microsoft.com/?id=159199 seems make sense,

This file is in a state known as pending deletion. This file has been deleted, but there are still handles open to it. NTFS will wait until all handles to this file are closed before updating the index. If an attempt is made to access the file, however, NTFS will deny the attempt. Because the file is listed in the index, but is effectively deleted, you can see the file but you cannot access it.

The workaround here is add a 60 seconds sleep between the folder deletion and folder creation operation.

Batch Script Tips

1 March, 2010 | Category: Development, Tips and Tricks

Getting the current working directory
cd /d %~dp0
Comment: %0 is the name of the batch file. ~dp gives you the drive and path.

Control panel applets

17 February, 2010 | Category: Tips and Tricks

Control panel applets (.CPL) is a shortcut to launch administrator tools quickly.

These are some that used frequently after new OS is setup.

  • intl.cpl – Regional and Language Options
  • timedate.cpl – Date and Time Properties
  • inetcpl.cpl – Internet Properties
  • ncpa.cpl – Network Connections
  • powercfg.cpl – Power Options Properties

Disable standby/sleep

10 January, 2010 | Category: Script, Tips and Tricks

powercfg.exe is a windows built in tool to config power management. powercfg.exe is a command line utility, it’s easy to integrate powercfg.exe into scripts.

Turn hibernation off

powercfg -hibernate OFF

Set the power configuration to High Performance

powercfg -setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c

Set the absentia power scheme (the scheme used when no one is logged in)

powercfg.exe -setabsentia 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c

Enable/disable the built-in administrator account

9 January, 2010 | Category: Script, Tips and Tricks

Enabling the built-in administrator account:

net user administrator /active:yes

Disabling the built-in administrator account:

net user administrator /active:no

Note: Must use an elevated command prompt for this command to work.

Shutdown or reboot the computer

5 January, 2010 | Category: Script, Tips and Tricks

Shut down

shutdown /s /t 0

Reboot

shutdown /r /t 0

Changing the computername

5 January, 2010 | Category: Tips and Tricks

Domain joined

netdom.exe renamecomputer %computername% /NewName:<new name> /userd:domain\user /passwordd:*

Non-Domain joined

wmic.exe computersystem where name="%computername%" rename name="<new name>"

Launch Regional and Language Settings

5 January, 2010 | Category: Script, Tips and Tricks

Bring up the Regional and Language Settings dialog box

control intl.cpl