Tuesday, April 24, 2007

NT4 Timezone Fix

Only recently realised that the default time for the clocks to change on Windows NT is an hour later than it should be in the UK, meaning that if the clock change to GMT or DST at 2pm, the NT servers default to 3pm. To change this, here's the registry script to do so, plus a link below with some info regarding the variables in the script:

REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]

"Bias"=dword:00000000"
StandardName"="GMT Standard Time"
"StandardBias"=dword:00000000
"StandardStart"=hex:00,00,0a,00,05,00,02,00,00,00,00,00,00,00,00,00
"DaylightName"="GMT Daylight Time"
"DaylightBias"=dword:ffffffc4
"DaylightStart"=hex:00,00,03,00,05,00,01,00,00,00,00,00,00,00,00,00
"ActiveTimeBias"=dword:ffffffc4

Pretty sure you need to restart the server for the change to take effect! Bring on the next clock change!

Info: http://www.jsifaq.com/SF/Tips/Tip.aspx?id=0398

Possible Syware - No SystemRoot variable

Had a user the other day who suddenly wasn't getting and drives mapped when he logged onto his computer. When attempting to troubleshoot the problem and jumped onto the command line and typed the usual ping which came back with:

'ping' is not recognized as an internal or external command,operable program or batch file!

This was a bit of a shock as ping is certainly a well known windows app. After ensuring ping did still exist on the user's pc in the correct location, i then (after a bit of a think) tried this:

echo %path% - came back with the correct entries

echo %systemroot% - came back with nothing!

True enough, after navigating to the system environmental variables the systemroot variable was not there - after adding it again all was fixed.

This seemed to be due to spyware as, after a run of CounterSpy, many bits of spyware were removed and has been fine ever since.

Tuesday, March 20, 2007

Watch and Search Realtime Network Connections via Windows Command Line

I recently discovered a way of watching network connections in Windows in realtime without using a program like Active Ports. Simply run this command:

netstat -o 1

Check out netstat /? for more options, but this will show and update network connections from the local machine every second.

TO make this a bit more useful, use:

netstat -o 1 find "3389" - I use this example to show only connections using the Remote Desktop Protocol.

Useful to use with a server where 3rd party applications cannot be installed.

Friday, March 16, 2007

Restoring an MSSQL 2000 Database and Creating Correct Logons

If you want to migrate/copy an SQL Server database and login/secrutiy infromation then this script is for you...

I was passed on this script that creates a stored procedure on the source sql server and then after being run in Query Analyzer, creates an SQL script to run on the destination server creating appropriate logons and secrurity after restoring/migrating a database to a different server. Note - if moving/restoring a database to another sql server, restore the database first, then run this script. The script itself is as follows:

USE master
GO
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
@binvalue varbinary(256),
@hexvalue varchar(256) OUTPUT
AS
DECLARE @charvalue varchar(256)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length)
BEGIN
DECLARE @tempint int
DECLARE @firstint int
DECLARE @secondint int
SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
SELECT @firstint = FLOOR(@tempint/16)
SELECT @secondint = @tempint - (@firstint*16)
SELECT @charvalue = @charvalue +
SUBSTRING(@hexstring, @firstint+1, 1) +
SUBSTRING(@hexstring, @secondint+1, 1)
SELECT @i = @i + 1
END
SELECT @hexvalue = @charvalue
GO

IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL
DROP PROCEDURE sp_help_revlogin
GO
CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
DECLARE @name sysname
DECLARE @xstatus int
DECLARE @binpwd varbinary (256)
DECLARE @txtpwd sysname
DECLARE @tmpstr varchar (256)
DECLARE @SID_varbinary varbinary(85)
DECLARE @SID_string varchar(256)

IF (@login_name IS NULL)
DECLARE login_curs CURSOR FOR
SELECT sid, name, xstatus, password FROM master..sysxlogins
WHERE srvid IS NULL AND name <> 'sa'
ELSE
DECLARE login_curs CURSOR FOR
SELECT sid, name, xstatus, password FROM master..sysxlogins
WHERE srvid IS NULL AND name = @login_name
OPEN login_curs
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd
IF (@@fetch_status = -1)
BEGIN
PRINT 'No login(s) found.'
CLOSE login_curs
DEALLOCATE login_curs
RETURN -1
END
SET @tmpstr = '/* sp_help_revlogin script '
PRINT @tmpstr
SET @tmpstr = '** Generated '
+ CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
PRINT @tmpstr
PRINT ''
PRINT 'DECLARE @pwd sysname'
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT ''
SET @tmpstr = '-- Login: ' + @name
PRINT @tmpstr
IF (@xstatus & 4) = 4
BEGIN -- NT authenticated account/group
IF (@xstatus & 1) = 1
BEGIN -- NT login is denied access
SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''
PRINT @tmpstr
END
ELSE BEGIN -- NT login has access
SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + ''''
PRINT @tmpstr
END
END
ELSE BEGIN -- SQL Server authentication
IF (@binpwd IS NOT NULL)
BEGIN -- Non-null password
EXEC sp_hexadecimal @binpwd, @txtpwd OUT
IF (@xstatus & 2048) = 2048
SET @tmpstr = 'SET @pwd = CONVERT (varchar(256), ' + @txtpwd + ')'
ELSE
SET @tmpstr = 'SET @pwd = CONVERT (varbinary(256), ' + @txtpwd + ')'
PRINT @tmpstr
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name
+ ''', @pwd, @sid = ' + @SID_string + ', @encryptopt = '
END
ELSE BEGIN
-- Null password
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name
+ ''', NULL, @sid = ' + @SID_string + ', @encryptopt = '
END
IF (@xstatus & 2048) = 2048
-- login upgraded from 6.5
SET @tmpstr = @tmpstr + '''skip_encryption_old'''
ELSE
SET @tmpstr = @tmpstr + '''skip_encryption'''
PRINT @tmpstr
END
END
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd
END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
GO


Save as sp_help_revlogin.sql.

As said before, run this firstly on the source sql server in Query Analyzer. This won't show anything outputted to the screen, but will create a stored procedure which can be run by typing: sp_help_revlogin and hitting execute. This will output some sql. Copy and past this sql into the Query Analyzer on the destination server and execute. This will create all logins and appropriate permissions on the destination server.

Friday, February 23, 2007

Stop and Start Specific Websites

Ran into this really useful bit of VBS to stop or start specific websites in IIS:

To Stop (StopSite1.vbs):

Set IISObj=GetObject("IIS://LocalHost/W3SVC/1")
IISObj.Stop

To Start (StartSite1.vbs):

Set IISObj=GetObject("IIS://LocalHost/W3SVC/1")
IISObj.Start

Just copy the lines into a text file, rename to .vbs and run with: cscript StartSite1.vbs or cscript StopSite1.vbs.

Errorlevels and Windows XP

I was recently playing with a script to do some basica automated failover depending on whether a certain service was running or not and came accross an interesting fact that Windows XP and I think any newer Windows OS younger than Windows 98 doesn't see Errorlevel =0 as success, instead the successful errorlevel is 255.

For instance - to check the Messenger service on a remote computer (you obviously need the correct rights on the remote machine);

sc \\ query Messenger | FIND "STATE" > service_state.txt
type service_state.txt | find "4"

IF ERRORLEVEL 255 GOTO Running
IF ERRORLEVEL 1 GOTO Problem

:Running
echo Service is running
goto end

:Problem
echo Service Problem
goto End


:End
exit

Thought this may be worth posting if someone's having a hard time with errorlevels!

Monday, February 19, 2007

RPC over HTTPS Problems

I had a problem that I just couldn't solve - check out my google group post:

I'm absolutely stuck. I've been through almost every knowledgebase
article i've found and along the way fixed every error i've come
across (which has pretty much been all of them). I've got a single
exchange server enabled for RPC over HTTPS. I've got a self signed ssl
certificate created via the IIS resource kit using Self SSL which I
have trusted and is called the same as my external url to my owa
server.

I can navigate to owa without getting prompted with certificate
information, and I can go to http:///rpc where i get prompted for
username and password which fails after third attempt where i get an
error: HTTP Error 401.3 - Unauthorized: Access is denied due to an ACL
set on the requested resource.

I've read that even though this error isn't the standard error i
should get, it should not prove to be a problem. I've done an rpc ping
with the following commands:

rpcping -t ncacn_http -s exch_server_name -o RpcProxy=external_url -P
"user,domain,*" -I "user,domain,*" -H 1 -u 10 -a connect -F 3 -v 3 -E -
R none

rpcping -t ncacn_http -s exch_server_name -o RpcProxy=external_url -P
"user,domain,*" -I "user,domain,*" -H 1 -F 3 -a connect -u 10 -v 3 -e
6002

rpcping -t ncacn_http -s exch_server_name -o RpcProxy=external_url -P
"user,domain,*" -I "user,domain,*" -H 1 -F 3 -a connect -u 10 -v 3 -e
6001

rpcping -t ncacn_http -s exch_server_name -o RpcProxy=external_url -P
"user,domain,*" -I "user,domain,*" -H 1 -F 3 -a connect -u 10 -v 3 -e
6004

all come back fine. When connecting i can see Outlook trying to
connect via port 443 (using Active Ports) but nothing at all happens.
When i run outlook /rpcdiag all i see is it trying to connect, but
nothing else.

The server setup is:

1 x Windows 2003 SBS Server - does have exchange 2003 sp2, but is not
running any part of Rpc over HTTPS - we are slowly decomissioning it.
- DC and GC
1 x Windows 2003 R2 Server - Exchange 2003 SP2 - Rpc over HTTPs server
1 x Windows 2003 x64 Server - DC and GC

<

If you get this far and everything is fine, one thing I didn't check were the firewall rules on the client PC. The firewall was allowing connections out from Outlook, but not back in!!! Such a schoolboy thing to do, but didn't believe it. I was using Kerio firewall, but it just wasn't warning me about incoming connections!!!! Frustrating!!!

Also - if using SelfSSL as with the IIS6 Resource Kit, bear in mind teh default certificate is only for 7 days. You can increase this with the /V switch. Check ou tthis site for a great tutorial:

http://www.visualwin.com/SelfSSL/