Archive for the ‘Scripting’ Category
Posted by jpluimers on 2013/01/22
I normally don’t do much VBScript stuff, but sometimes I have to, and these tips helped me big time:
–jeroen
This was the script in question (mimicked a bit after Prnmngr.vbs): Read the rest of this entry »
Posted in Development, Scripting, Software Development, VBScript, Visual Studio 11, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »
Posted by jpluimers on 2013/01/02
On development machines it can be comfortable to add the local Administrators group to SQL Server, and make them equivalent to SA (SQL Server Administrator).
This especially as SA is disabled by default when you install using Windows Authentication mode (which is the default). You can Change Server Authentication Mode to include SQL Server mode, but then you still have to enable SA (you can even rename SA)
This is basically what you want to do:
CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=[master];
EXEC master..sp_addsrvrolemember @loginame = N'BUILTIN\Administrators', @rolename = N'sysadmin';
GRANT CONTROL SERVER TO [BUILTIN\Administrators];
There are a few gotchas here:
- The name of the group BUILTIN\Administrators depends on the localization of your system.
This is one of the reasons I usually advise clients to have server systems run on the most common ENU (English USA) localization of Windows.
Another reason is that it is far easier to find information ENU English Messages back on the internet.
- You need to be SQL Server Administrator to begin with.
There is a little trick to get this done: you can stop the SQL Server service, then restart SQL Server it in single-user mode.
In single-user mode, members from the BUILTIN\Administrators group can connect as a member of the sysadmin fixed server role.
- If you want to access SQL Server as member from BUILTIN\Administrators, you need to run your SQL client tools with the UAC elevated permission (otherwise the Administrative bit is not set, and the BUILTIN\Administrators is not recognized).
That’s what the batch file below solves.
You need to start it as member of BUILTIN\Administrators with elevated privilege (the easiest way is to run it from an elevated command prompt).
It will: Read the rest of this entry »
Posted in Batch-Files, Database Development, Development, Scripting, Software Development, SQL Server, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | Leave a Comment »
Posted by jpluimers on 2012/12/31
A lot of scripts you find on the internet have hardcoded Windows account names or groups, for instance BUILTIN\Administrators
Those don’t work on many localized Windows versions, as part of the account names have been translated as well. Not only Administrators is translated, but BUILTIN can be translated too. Basically, expect everything in Windows to be translated as part of the localization process.
Some people keep translations lists, but that is not the real solution.
The real solution is that each such group, account or other identifier stems from a SID or Security ID.
Many of those SIDs are the same on any machine, or structured the same within a domain.
Microsoft has a list of these called Well-known security identifiers in Windows operating systems.
That list isn’t in a format most Windows tools use it, so I generated the list below that is more suitable.
The list below is based on a Windows 7 machine. Other versions or editions give slightly different results, but it is a good start.
At the bottom is the batch file that I used to generate this table. That file is adapted from the Microsoft list above.
The batch file depends on a few tools and tricks: Read the rest of this entry »
Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows, Windows 7, Windows 8, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP | 1 Comment »
Posted by jpluimers on 2012/12/19
I knew that 2>&1 was needed to redirect both stderr and stdout, but for piping, it cannot be at the end of the line. This works in the categories shown at the bottom of the post.
Rob van der Woude again to the rescue in redirection:
(4) Redirecting both standard output and standard error to the same file or device is done by adding 2>&1 to the command line. This will only work in OS/2 and NT, not in MS-DOS.
Where you put 2>&1 is rather critical. It will only do what it is supposed to do when placed at the end of the command line (as Jennie Walker pointed out to me) or right before the next pipe ( | ).
Example: batch file that checks if a few NarrowCast machines are indeed on-line and logged on with the right user.
It uses PsLoggedOn to verify who is logged on, and Explorer to show a hidden share.
The pipe is needed to verify there is indeed a domain user logged on.
@echo off
for %%m in (Machine1 Machine2 Machine3) do call :show %%m
goto :pause
:show
echo %1
%~dp0PsLoggedOn -L \\%1 2>&1 | find /I "MYDOMAIN\"
start explorer /e,\\%1\NarrowCast$
goto :end
:pause
pause
:end
–jeroen
Posted in Batch-Files, Development, Power User, Scripting, Software Development, Windows, Windows 7, Windows Server 2003, Windows Server 2008, Windows Vista, Windows XP | 4 Comments »
Posted by jpluimers on 2012/12/18
Wow, Perl turned 25 today, it seems my first use was like yesterday!
–jeroen
via: The First Twenty-Five Years – The Perl Foundation.
Posted in Development, Perl, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2012/12/06
Thanks Nick Craver for answering this on StackOverflow.
Array initializers can be specified in field declarations (§17.4), local variable declarations (§15.5.1), and
array creation expressions (§14.5.10.2).
The array initializer can end in a comma, which makes some things way easier (boy, I wish I had this in other programming languages).
From Nick’s answer:
It has no special meaning, just the way the compiler works, it’s mainly for this reason:
[FlagsAttribute]
public enum DependencyPropertyOptions : byte
{
Default = 1,
ReadOnly = 2,
Optional = 4,
DelegateProperty = 32,
Metadata = 8,
NonSerialized = 16,
//EnumPropertyIWantToCommentOutEasily = 32
}
[/language]By comment request: This info comes straight out of the ECMA C# Specification (Page 363/Section 19.7)
“Like Standard C++, C# allows a trailing comma at the end of an array-initializer. This syntax provides flexibility in adding or deleting members from such a list, and simplifies machine generation of such lists.”
–jeroen
via c# – .NET Enumeration allows comma in the last field – Stack Overflow.
Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C++, Delphi, Development, Java, JavaScript/ECMAScript, PHP, Software Development, VB.NET | 5 Comments »
Posted by jpluimers on 2012/10/23
Interesting SharePoint CAML XML trouble shooting tool:
this script is NOT meant to help you *build* your queries. There are other tools for that. This is purely a testing tool to help you during those “doh” moments.
-jeroen
via: Simple CAML Query Tester using jQuery & SPServices –.
Posted in .NET, Development, JavaScript/ECMAScript, jQuery, Scripting, SharePoint, Software Development, Web Development | Leave a Comment »
Posted by jpluimers on 2012/10/08
Most console applications return 0 (zero) as success.
But sometimes there are multiple success result codes, and the success depends on what you want to do with them.
One example is RoboCopy.
The zero result code means that nothing happened: no error occurred and nothing was copied, because there was no need to.
But for most RoboCopy scenario’s result code 1 (one) is also success. It means that no error occurred and that one ore more files were copied.
In fact the RoboCopy result codes form a bitmap explained on ss64.com.
Most RoboCopy use cases will have [0,1] as the set off success result codes.
–jeroen
via: Robocopy Exit Codes.
Posted in Batch-Files, Development, Power User, RoboCopy, Scripting, Software Development, Windows, Windows 7, Windows 8, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Vista, Windows XP | 3 Comments »
Posted by jpluimers on 2012/09/13
It was a long time ago that I ever did something with the Elf proef.
It is the algorithm that is used to calculate the check digit for Dutch bank account numbers (bankrekeningnummers) and a variation for BSNs (Social Security Numbers).
I needed it (or more exactly: a variation of it) in order to support anonymization of customer data for the DTA/OTA portions of a DTAP/OTAP environment.
So, I started reading on the Elf proef, and getting some sample data to setup some unit tests.
Wrong and wrong:
To start with the latter, they get it wrong because the check digit is modulo 11 (like the ISBN 10 check digit), but only numeric digits are valid. Their bank.js algorithm module tries to accommodate for that in the wrong way.
In addition they copy-pasted code between their other number generation algorithms which you can see form the variable SofiNr which is an abbreviation for SofiNummer, the old name for the Dutch Social Security Number (now called Burgerservicenummer aka BSN).
Their generated sample 290594880 is wrong because the check digit should be 10, and 10 is not a digit. Their generated number 936977590 is OK as the check digit should be zero (0) which it is.
More on their fault a bit further on. First lets concentrate on getting proper test data, and the right algorithm.
I will cover code for the bankrekeningnummer here. The complete code including BSN is at BeSharp.CodePlex.com. Read the rest of this entry »
Posted in .NET, C#, C# 3.0, C# 4.0, C# 5.0, Development, JavaScript/ECMAScript, Scripting, Software Development | 4 Comments »