Archive

Archive for the ‘DOS Command Line’ Category

XP: kill a Windows process from the command line with taskkill | a Tech-Recipes Tutorial

XP: kill a Windows process from the command line with taskkill | a Tech-Recipes Tutorial

XP: kill a Windows process from the command line with taskkill

The ability to perform tasks from a system’s command line allows those tasks to be used in batch files. This recipe describes several uses of taskkill to terminate Windows processes.


If you know the name of a process to kill, for example notepad.exe, use the following command from a command prompt to end it:

taskkill /IM notepad.exe

This will cause the program to terminate gracefully, asking for confirmation if there are unsaved changes. To forcefully kill the same process, add the /F option to the command line. Be careful with the /F option as it will terminate all matching processes without confirmation.

To kill a single instance of a process, specify its process id (PID). For example, if the desired process has a PID of 827, use the following command to kill it: … (Read more here)

Advertisements

Elangovv\’s Blog – [Batch Files and Such]

[object HTMLTextAreaElement]

via Elangovv\'s Blog.

The Agony of Looping and Doing Foreach In XP DOS

07/07/12

It has been a primary goal of mine for several years to write a Windows program, in either DOS or Perl, to automate changing the folder icon in a batch of subdirectories.  It is quite tedious to do this process manually, and when I am trying to customize folder icons this process can eat up hours at a time!

Thus this post is simply to get my frustration down about all the time and effort I put into trying to figure this out and the dearth of knowledge on DOS commands and looping, and the alternative difficulty of doing this in other Windows-friendly languages…. Nature calls … Please let me know if you’ve ever had similar problems?!?

07/08/12

Here are some attempts I made last night to list all subdirectories (folders) in a given folder using the fully-qualified path name. Notice that in batchfoldericon.bat and batchfoldericon2.bat there is a lot of extra code … This is because after 3 hours of research and troubleshooting, I was finally able to get the code to do the variable expansion. But, for some reason it would never write the fully-qualified path to the text file … That or it would be reading the subdirs from one level up … huh? And to top it off, sometimes I’m getting the correct results with the for loop code I have, and other times it is giving me incorrect results as stated earlier!

NOTE: WordPress.com hosted code syntax highlighting doesn’t support “dos”, “batch”, “bat”, “command line”, “cmd”, or anything of that nature. Therefore, the closest logical relative is “powershell”, so that is the sourcecode language I am using to display the code below … It leaves much to be desired, but as stated, it’s not designed for DOS code. However, this problem is easily remedied when using a self-hosted WordPress site … There are nice plugins that a Google search will show that can do DOS code syntax highlighting just fine, but they are unavailable when you let Automatic host your site.

batchfoldericon.bat

@echo off
REM -- File:    batchfoldericon.bat
REM -- Created: 07/07/12
REM -- Author:  Eric Hepperle

REM -- Notes:   %1 refers to the first argument passed to the file.

rem @echo off
REM -- THIS WORKS FOR LISTING LEV1 SUBDIRS! 🙂 -->
REM     for /d %%X in (%~dp1*) do echo %%X >> c:\listjpg.txt

REM for /r %1 %%X in (*.jpg) do (echo %%X >> c:\listjpg.txt)
rem SETLOCAL EnableDelayedExpansion

if "%~1" == "." goto :defaultdircond
if "%~1" == "" goto :defaultdircond

goto :dirpassed
:dirpassed
set %startdir% = %~f1
goto: processdirs

:defaultdircond
echo CONDITION cond was gone-to.
set %startdir% = %cmd%

:processdirs
REM for /d %%X in (%startdir%\*) do (
 REM echo %%X >> c:\listjpg.txt
 REM attrib -r "%startdir%\*.*" /S /D
REM )
for /d %%X in (%~f1\*) do echo %%X >> c:\listjpg.txt

REM -- THIS WORKS FOR GRABBING ALL LEV1 SUBDIRS AND LISTING
REM --  THEIR FULLY QUALIFIED PATHS:
REM -- for /d %%X in (%~f1\*) do echo %%X >> c:\listjpg.txt

batchfoldericon2.bat

@echo off
REM -- File:    batchfoldericon2.bat
REM -- Created: 07/07/12
REM -- Author:  Eric Hepperle

REM -- Notes:   %1 refers to the first argument passed to the file.

if "%~1" == "." goto :defaultdircond
if "%~1" == "" goto :defaultdircond

goto :dirpassed
:dirpassed
set %startdir% = %~f1
goto: processdirs

:defaultdircond
echo CONDITION cond was gone-to.
set %startdir% = %cmd%

:processdirs
for /d %%X in (%startdir%\*) do (
 echo %%X > c:\listjpg.txt
 rem @attrib -r "%%X"
)

REM -- THIS WORKS FOR GRABBING ALL LEV1 SUBDIRS AND LISTING
REM --  THEIR FULLY QUALIFIED PATHS:
REM -- for /d %%X in (%~f1\*) do echo %%X >> c:\listjpg.txt
REM
REM -- Get all lev1 subdirs can also be done by:
REM --   dir /ad /b

batchfoldericon3.bat

NOTE: This one works!!! — It writes fully-qualified pathnames to the output file correctly! 🙂 Now I just have to get it to process each folder!

@echo off

for /d %%X in (%~f1\*) do echo %%X >> c:\listjpg.txt

Powershell – Executing commands which require quotes and variables is practically impossible!

March 30, 2012 4 comments


Executing commands which require quotes and variables is practically impossible: Microsoft Connect

This is an interesting forum thread about what I’ve spent the last 2 hours researching:  How to properly quote commands with parameters and interpolated paths so that they will execute as a command.  Doesn’t seem like it should be so hard.  Here is an example of the code I’m working with:

The command I’m trying to run:

C:\Program Files\Mozilla Firefox\firefox.exe -createprofile myTest

# Here is what works in MS-Dos / Windows XP command prompt:

"C:\Program Files\Mozilla Firefox\firefox.exe" -CreateProfile myTest

However, run the same thing in powershell and this is what you get:


PS C:\Documents and Settings\nunya> “C:\Program Files\Mozilla Firefox\firefox.exe” -CreatProfile myTest
You must provide a value expression on the right-hand side of the ‘-‘ operator.
At line:1 char:48Unexpected token ‘CreatProfile’ in expression or statement.
At line:1 char:49Unexpected token ‘myTest’ in expression or statement.
At line:1 char:62