Monday, November 10, 2008
Ultraedit files does not show in tabs even when set for it
Beware, it does not work to simply enable the "View -> Views/Lists -> Open File Tabs" from the menu, that is already enabled, and no file tabs are shown!
So it turns out that all you have to do is delete this section from uedit32.ini:
[ToolBarState1-v110-Bar17]
BarID=59423
Horz=1
Floating=1
XPos=4
YPos=992
Bars=3
Bar#0=0
Bar#1=143
Bar#2=0
You can remove more [ToolBarState1 sections if you want, you will have to fix your toolbars afterwards though.
Uedit32.ini location can be modified, which is a nice feature, enabling you to have your own private .ini file. Simply using the documents and settings location ("C:\Documents and Settings\USERNAME\Application Data\IDMComp\UltraEdit\uedit32.INI") is better than Windows system dir.
Friday, June 13, 2008
Commands from cmd does not set errorlevel as you might expect!
It might not be a surprise to you, but Windows commands inside cmd.exe does not change errorlevel as you might expect.
For example running a echo something > c:\somefile.txt, which will succeed actually creating the file, but not change errorlevel to 0. You can test it like this:
md 2>nul
echo %errorlevel%
1
echo this.works > c:\test.txt
echo %errorlevel%
1
type c:\test.txt
this.works
This echo can not really be solved by using cmd /c echo because that will just always succeed, for example:
md 2>nul
echo %errorlevel%
1
cmd /c echo this.works > c:\test.txt
echo %errorlevel%
0
type c:\test.txt
this.works
cmd /c echo this.fails > drivedoesnotexist:\test.txt
The filename, directory name, or volume label syntax is incorrect.
echo %errorlevel%
0
And now, testing if copy command file1 + file2 into file3 gives errorlevel 1 if one of the source files does not exists. Errorlevel 1 is what you might expect, but it is not the case here:
echo 1 > 1.txt
rm 2.txt
echo 3 > 3.txt
ls -la 2.txt
ls: File or directory "2.txt" is not found
copy /b 1.txt + 2.txt + 3.txt 123.txt
1.txt
3.txt
1 file(s) copied.
echo %errorlevel%0
This is not as I expected, I will want to find a way to get around this.
There are probably same problem with other cmd commands, I didnt try others.
Maybe I am doing something the wrong way, in my environment and installation ... need to investigate :-)
I have not been able to find anything in the cmd command line reference, and it does not seem to solvable if everything is put into a batch script, instead of running commands one by one. I did hope that, because of text on information about setlocal ENABLEEXTENSIONS which can be set in a script, but has no effect on the command prompt:
cmd does not set the ERRORLEVEL variable when command extensions are
disabled
But unfortunately it did not work, here is the run.cmd script i ran:
setlocal ENABLEEXTENSIONS
echo 1 > c:\1.txt
rm c:\2.txt
echo 3 > c:\3.txt
copy /b c:\1.txt + c:\2.txt + c:\3.txt c:\123.txt
echo %errorlevel%
endlocal
The above echo'd 0 and the errorlevel after the script is 0. So not a solution!
I still keep investigating :-)
Oh yeah - in case you ever wondered, you should never manually set the errorlevel to 0 or 1 or whatever you need. Instead you should always use a command for that. I am using "ver" to get errorlevel 0 and "md;2>nul" to get errorlevel set at 1, which I found on one of my favorite batch example webpages.
Tuesday, May 20, 2008
Dig into the Active Directory information store
A few days ago I needed to show the list of computers in an Organizational Unit (OU), so I searched for some ways to get that. And I bumped into the Microsoft dstools (dsget/dsquery/....) and they are just perfect for automating Directory service stuff.
The commands works from a Windows 2003 server, but not from XP.
Also, I need a intro for directory services, because I havnt used it much, and a then moved to a good simple dsquery tutorial.
Then I could make some quick oneliners, starting with a very comprehensive query that is highly educative of how the Directory of Level2OU is made:
dsquery * OU=Level2OU,OU=Level1OU,DC=domain,DC=domainext -limit 0 -attr *
Listing the members of a Windows group:
dsget group "CN=somegrp,OU=level2,OU=level1,DC=domain,DC=domainext" -members -expand
Show the computers of an OU:
dsquery computer OU=Level3OU,OU=Level2OU,OU=Level1OU,DC=domain,DC=domainext -limit 0
To automated the query, I have used psexec to run it on a remote server, with a user that has access to do queries:
psexec \\srv -u dom\usr -p pwd -e cmd /C "dsquery ou domainroot"
Other than that I just found the dstools to be very powerful and some googling shows many good examples of what people have done with it! Very impressive!
The article also mentions some need-to-have directory service binaries from joeware.net/freetools but I havnt tried them. They look good though, like lots of work has been wrappen into those exes:
AdFind [switches] [-b basedn] [-f filter] [attr list]
basedn RFC 2253 DN to base search from.
filter RFC 2254 LDAP filter.
attr list List of specific attributes to return, if nothing specified returns 'default' attributes, aka * set.
...
Monday, May 19, 2008
Dependency Walker commandline example
I wanted to script the dependency check for some .dll files, so i ran toward remote server:
psexec \\someserver /u someuser -e cmd /c "environment.cmd&depends.exe /c /pb /oc "d:\depends.temp" "some.dll""
Now parse the output file, first column is status, look for "E,":
findstr /bic:"E," \\someserver\d$\depends.temp
if errorlevel 1 echo all OK
I have not made a way to avoid enter password, but if I need I recall there are some runas and similar alternatives.
Thursday, May 8, 2008
Hello World and 99 Bottles of Beer collections
... the collection of the Song 99 Bottles of Beer programmed in different
programming languages. Actually the song is represented in 1200 different
programming languages and variations. For more detailed information refer to
historic information.
Checking the reg exp, it is a bit (but not much really) readable:
perl -MO=Deparse 99-bottles.pl
'' =~ /(?{eval"\$==pop99;--\$=;sub\n_\{(\$;=(\$=No).\" bottle\".\"s\"x!!--\$=.\" of beer\").\" on the wall\"\}print+
_,\", \$;!\nTake one down, pass it around,\n\",_,\"!\n\n\"while++\$="})/;
$: = 'P';
$~ = 'h';
$^ = 'r';
$/ = '`';
99-bottles.pl syntax OK
Wednesday, April 30, 2008
More good Windows command line tools
When I was playing around with Powershell I stumbled upon Windows Command Reference, a .chm file with reference for a lot of command line utils in Windows:
The Windows command-line tools are used to perform various tasks related to
Windows Vista, Windows Server 2003, and Windows Server 2008.You can use the
command reference to familiarize yourself with new and enhanced command-line
tools, to learn about the command shell, and to automate command-line tasks by
using batch files or scripting tools.
Many of the tools in the reference are also in Windows XP and 2003, but the resource kit tools are not listed, for example jt.exe or tail.exe is not in the list.
With all these nice utils, and more to come probably, I am thinking a lot of old selfmade scripts can be replaced or simplified. I prefer to use windows builtin tools if possible, most often wrapped somehow.Of course there will always come new needs, ideas for improvements, so script wrapping, script/batch control is just as much wanted as before!
Two of the utils I can use immediately, its tasklist.exe and taskkill.exe, which can query and kill processes depending on lots of different restrictions.
One of the good filter options is username, memusage and session number. Unfortunately only on one server at a time:
TASKLIST [/S system [/U username [/P [password]]]]
[/M [module] /SVC /V] [/FI filter] [/FO format] [/NH]
Description:
This command line tool displays a list of application(s) and
associated task(s)/process(es) currently running on either a local or
remote system.
Parameter List:
/S system Specifies the remote system to connect to.
/U [domain\]user Specifies the user context under which
the command should execute.
/P [password] Specifies the password for the given
user context. Prompts for input if omitted.
/M [module] Lists all tasks that have DLL modules loaded
in them that match the given pattern name.
If the module name is not specified,
displays all modules loaded by each task.
/SVC Displays services in each process.
/V Specifies that the verbose information
is to be displayed.
/FI filter Displays a set of tasks that match a
given criteria specified by the filter.
/FO format Specifies the output format.
Valid values: "TABLE", "LIST", "CSV".
/NH Specifies that the "Column Header" should
not be displayed in the output.
Valid only for "TABLE" and "CSV" formats.
/? Displays this help/usage.
Filters:
Filter Name Valid Operators Valid Value(s)
----------- --------------- --------------
STATUS eq, ne RUNNING NOT RESPONDING
IMAGENAME eq, ne Image name
PID eq, ne, gt, lt, ge, le PID value
SESSION eq, ne, gt, lt, ge, le Session number
SESSIONNAME eq, ne Session name
CPUTIME eq, ne, gt, lt, ge, le CPU time in the format
of hh:mm:ss.
hh - hours,
mm - minutes, ss - seconds
MEMUSAGE eq, ne, gt, lt, ge, le Memory usage in KB
USERNAME eq, ne User name in [domain\]user
format
SERVICES eq, ne Service name
WINDOWTITLE eq, ne Window title
MODULES eq, ne DLL name
Sunday, April 27, 2008
TclockEx is still a better Windows Clock
It serves a few important purposes for me:
- Display date and time in a better way
- Customizable format of "date and time copy to clipboard" when i doubleclick the systray. I use this format to get a quick datestring for usage in reports and documentation: yyyyMMdd-HHmm (eg. 20080427-0719)
- Display a simple calender with week numbers, shown by single click and week start can be modified to monday.
For the paranoid people, here is my md5 sum for the safe exe:
1238b1c59fd4987d538144aa915e85c2 *tclockex-1.4.2.exe
1238b1c59fd4987d538144aa915e85c2 *tclockex.exe