Getting the current working directory
cd /d %~dp0
Comment: %0 is the name of the batch file. ~dp gives you the drive and path.
Tag: Batch Scripts
-
Batch Script Tips
-
Symbolic Links
Vista and WIN7 now supports symbolic links, a feature that has been enjoyed in UNIX for a long time.
D:>mklink
Creates a symbolic link. MKLINK [[/D] | [/H] | [/J]] Link Target /D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to. -
Synchronizing two batch files
This useful command lets you wait for signals from other command windows or even across the network.
waitfor.exe is in windowssystem32 directory.
The simple case for the tool is in one command window you do a “waitfor foobar” and it’ll block until in another window you do a “waitfor /SI foobar”.
-
Disable standby/sleep
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
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
Shut down
shutdown /s /t 0
Reboot
shutdown /r /t 0
-
Changing the computername
Domain joined
netdom.exe renamecomputer %computername% /NewName:<new name> /userd:domainuser /passwordd:*
Non-Domain joined
wmic.exe computersystem where name="%computername%" rename name="<new name>"
-
Launch Regional and Language Settings
Bring up the Regional and Language Settings dialog box
control intl.cpl