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

Tuesday, December 28, 2010

windows: setting environment variables from the command line

The standard route is rather slow and painful, even on Win7:
“MyComputer | Properties | Advanced System Settings | Environment Variables”… that’s a lot of clicks just to get to the point where you can add/edit an environment variable.

Thankfully, there’s a much easier alternative via the command line.

But first, did you know where the environment variables are stored on the file system? Until now I thought they were in some system config file, but it turns out they're actually stored in the registry itself (which technically is a system config file).
  • The logged-in user’s env variables go here:
    HKEY_CURRENT_USER\Environment
  • The machine-wide env variables go here:
    HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
The setx utility lets you change env variables for either the user or machine. The good old set command let’s you add/edit env variables too, but there are a few major differences from setx:
  • setx will permanently change the value of an env variable. The changes made by set last only for the current session.
  • Changes made by setx are not immediately visible – that is, they are not available to the current session. However, set’s changes are immediately visible.
  • You can’t delete env variables with setx, like you can with set. For example:
    set someVar=
    will delete the environment variable ‘someVar’ for the current session, but you can’t do something like this with setx.

    Instead, you have to use the “reg” utility to delete environment variables (that may or may not have been created with setx):
    REG delete HKCU\Environment /V someVar
Okay, so do you create a permanent environment variable via setx? It’s pretty straightforward:
  • To set an env variable for the current user:
    SETX <Variable> <Value>
  • To set an env variable for the machine (i.e. globally):
    SETX <Variable> <Value> -m
Example:
setx  CLASSPATH  C:\Users\ambars\.m2\repository\com\oracle\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;.

source: http://ss64.com/nt/setx.html

Saturday, October 16, 2010

windows: which processes have loaded xyz.dll?

Example: find all processes that have loaded msvcrt.dll:
C:\Users\ambars>tasklist /m /fi "modules eq msvcrt.dll"


Image Name                     PID Modules                                     
========================= ======== ============================================
csrss.exe                      748 ntdll.dll, CSRSRV.dll, basesrv.DLL,         
                                   USP10.dll, msvcrt.dll, sxssrv.DLL, sxs.dll, 
                                   RPCRT4.dll, CRYPTBASE.dll                   

wininit.exe                    800 ntdll.dll, kernel32.dll, KERNELBASE.dll,    
                                   USER32.dll, GDI32.dll, LPK.dll, USP10.dll,  
                                   msvcrt.dll, RPCRT4.dll, sechost.dll,        
                    
csrss.exe                      808 ntdll.dll, CSRSRV.dll, basesrv.DLL,              
                                   USP10.dll, msvcrt.dll, sxssrv.DLL, sxs.dll, 
                                   RPCRT4.dll, CRYPTBASE.dll  
[SNIP/]

Thursday, September 23, 2010

windows: powertools that replace the plain old netstat command

  • currports: powerful, easy-to-use and free! Can filter processes. A perfect replacement for port explorer.
  • tcpview (sysinternals)
  • procmon (sysinternals)
  • port explorer (Trialware, old favorite. Development has long stopped since the parent company seems to be dead. Also redundant now, thanks to the above free options)

Thursday, July 29, 2010

how much physical memory is supported by 64 bit editions of Windows 7?

While the maximum RAM limit for 32-bit Windows 7 editions is 4GB, when it comes to the 64-bit editions, the amount of memory that the OS can address depends on which edition you are running.

Here are the upper RAM limits for the different editions of Windows 7:

  • Starter: 8GB
  • Home Basic: 8GB
  • Home Premium: 16GB
  • Professional: 192GB
  • Enterprise: 192GB
  • Ultimate: 192GB

source

Thursday, October 29, 2009

windows: installing the recovery console on xp

To install the Recovery Console in Windows XP, follow these steps:


1.    Insert the Windows XP CD into the CD-ROM drive.
2.    Click Start, and then click Run.
3.    In the Open box, type d:\i386\winnt32.exe /cmdcons where d is the drive letter for the CD-ROM drive. In the case of 'Microsoft Windows XP Professional x64 Edition, type d:\amd64\winnt32.exe /cmdcons where d is the drive letter for the CD-ROM drive.
4.    A Windows Setup Dialog Box appears. The Windows Setup Dialog Box describes the Recovery Console option. To confirm the installation, click Yes.
5.    Restart the computer. The next time that you start your computer, "Microsoft Windows Recovery Console" appears on the startup menu.

Tuesday, October 20, 2009

windows: how to schedule a high-frequency task

Task Scheduler doesn't let you schedule tasks with fine-grained frequencies. For example, you can't schedule a task to execute every minute, or every few hours. The maximum frequency that can be given to a task is "daily" which sucks because you need to run some programs more often than that (linux's cron is still the king!)

Here's the solution. It involves using the rather powerful "schtasks" windows command:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true

Here's what I used:
schtasks /create /sc hourly /mo 2 /tn "autoupdatesourcecode" /tr c:\tools\autoupdatesourcecode.bat


And this is my super-simple autoupdatesourcecode.bat:
cd d:\Codebase\trunk\pi\
d:
svn up

Tuesday, October 6, 2009

batch file to fix WMI errors

There's a lot to learn about batch file scripting from this example!
source

net stop winmgmt

pause

c:

cd c:\windows\system32\wbem

rd /S /Q repository

regsvr32 /s %systemroot%\system32\scecli.dll

regsvr32 /s %systemroot%\system32\userenv.dll

mofcomp cimwin32.mof

mofcomp cimwin32.mfl

mofcomp rsop.mof

mofcomp rsop.mfl

for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s

for /f %%s in ('dir /b *.mof') do mofcomp %%s

for /f %%s in ('dir /b *.mfl') do mofcomp %%s

mofcomp exwmi.mof

mofcomp -n:root\cimv2\applications\exchange wbemcons.mof

mofcomp -n:root\cimv2\applications\exchange smtpcons.mof

mofcomp exmgmt.mof

Monday, September 14, 2009

vbscript: create system restore points with no fuss

Here's how to create a simple VBscript that will create a restore point when you double-click it:

1. Save the code below to, say, c:\system_restore.vbs:

Set SRP = GetObject( "winmgmts:\\.\root\default:Systemrestore" )
CSRP = SRP.CreateRestorePoint( "Before Changes", 0, 100 )

2. Double-click the script file you just created, any time you want to create a fresh System Restore Point.

It only takes a few seconds to do this. And no dialogues are shown to confirm that a Restore Point was created. If you want to double-check you can click "Start | All Programs | Accessories | System Tools | System Restore" and click "Restore My Computer To An Earlier Time."

You'll see the restore point you just created (called "Before Changes") right there. Now be sure to cancel out of System Restore.

source

Friday, October 31, 2008

windows: removing the welcome/login screen in xp for single user logon

To log in automatically, type this command (it's a shortcut to 'User Accounts'):

control userpasswords2


Click the desired user's logon name, then click OK and enter the password when prompted (which is probably a blank).


To set the password for the current user to a blank, get to a cmd prompt and run this command:
net user "%UserName%" ""{Enter}



source

Monday, March 10, 2008

windows: the TcpTimedWaitDelay registry setting

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

The TcpTimedWaitDelay key in the Windows registry determines the time that must elapse before TCP can release a closed connection and reuse its resources. This interval between closure and release is known as the TIME_WAIT state or 2MSL state. During this time, the connection can be reopened at much less cost to the client and server than establishing a new connection.

Reducing the value of this entry allows TCP to release closed connections faster, providing more resources for new connections. However, if the value is too low, TCP might release connection resources before the connection is complete, requiring the server to use additional resources to reestablish the connection.