2008年12月22日星期一

server 2008 安装 Microsoft Loopback Adapter(环回适配器)

为了更好地使用虚机来访问本的资源,所以安装了回路网卡,本来以为server 2008不带Microsoft Loopback Adapter的驱动程序,后来终于找到创建的方法(如下图)
Start -> Computer -> Right-click, Properties -> Device Manager -> Computer Name, Right-click, Add Legacy Hardware -> Next -> Install the hardware I manually select from a list -> Next -> Network Adapters -> Microsoft on the right, Loopback adapter on the left -> Next

2008年12月19日星期五

Dell E6400 成功安装windows server 2008(64bit) & hyper-v

这两天回公司新领了笔记本E6400,CPU P8600[2.4G]支持vt技术,终于可以装上一直心仪的hyper-v玩玩了,以后工作上开发的东西可以在vt虚机上跑了,呵呵。
主要是以太网的驱动不太适合,为了解决这个问题差不多花了一天的时间……
安装过程中其中主要遇到了三个问题:
1、首先是虚拟网卡驱动的安装,装上之后发现不能正常工作,后来发现Server 2008对于无线网卡要新增feature[功能]安装,在服务管理器添加功能选项安装对无线网卡的支持;
2、安装hyper-v角色后发现服务不能正常运行,想起忘了配置BIOS中对VT应用支持的选项,采用Intel的cpu的机器vt支持大部分需要在BIOS中开启;
3、最后遇到最辣手的问题就是以太网卡825XX的驱动安装了,最后去网上找了一个Inter公版的intel_pro1000_130_vista64,试了半天终于强制安装上了82567LM-2型号的驱动,装上后插上网线测试一切正常,强制安装网卡驱动的步骤如下:
右键computer(我的电脑)--properties(属性)--左边栏第一个devicemanager(硬件管理)--找到显卡右键选 updatedriver(升级驱动)--选第2项browse my computer.....----选第2项Let me pick....(选择计算机驱动列表)--have disk(查询)指向你的驱动文件包里的INF文件--找到你的硬件型号安装,出现红字提示选继续……
哈哈,现在继续开始装其他软件和hyper-v虚机了……

因为暂时没时间回公司申请license,临时安装的是msdn下载的server datacenter版本,所以要用命令演出一下激活前使用的有效期……
slmgr.vbs -dli [查看时间]
slmgr.vbs -rearm [增加有效使用时间最高可以180天]

2008年12月17日星期三

Microsoft SQL Server 2005 Service Pack 3 发布了

这次微软Launch Microsoft SQL Server 2005 Service Pack 3相当的低调,没有太多消息宣传!
简体中文x86和x64的下载地址如下:SQL Server 2005 sp3

2008年12月16日星期二

AD某OU目录下用户信息操作vbscript脚本

'CONST ForReading = 1
CONST ForWriting = 2
CONST ForAppending = 8
CONST CONST_ERROR = 0
CONST CONST_WSCRIPT = 1
CONST CONST_CSCRIPT = 2
CONST CONST_SHOW_USAGE = 3
CONST CONST_LIST = 4
Const ADS_SCOPE_SUBTREE = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = 65536
Const ADS_UF_PASSWORD_EXPIRED = 8388608
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ONE_HUNDRED_NANOSECOND = .000000100
Const SECONDS_IN_DAY = 86400

Dim lastLogin
'''''''''''''''''''''''''
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
& "TimeZoneInformation\ActiveTimeBias")
If (UCase(TypeName(lngBiasKey)) = "LONG") Then
lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = "VARIANT()") Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
Set objShell = Nothing

'''''''''''''''''''''''''
inputOU=inputbox("请输入查询的OU,该OU必须位于" & TARGET_OU & "的下一层,不输入为查询此OU下所有帐号","输入信息")

Outputfile= strDCName1 & "账号列表" & inputOU
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fLog = fso.OpenTextFile(Outputfile & ".csv", ForWriting,TRUE)
fLog.WriteLine "帐号,姓名,工号,公司,部门,最后登陆时间,是否有邮箱,是否停用"

Set rootDSE = GetObject("LDAP://rootDSE")
BaseDN = rootDSE.Get("defaultNamingContext")
DC= replace(BaseDN,"DC=",",")
DC= replace(DC,",,",".")
DC=right(DC,len(DC)-1)

TARGET_OU = "Employee"

if inputOU<>"" then
TARGET_OU=inputOU & ",OU=" & TARGET_OU
end if


Set objConnection = CreateObject("ADODB.Connection")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
Set objCommand1 = CreateObject("ADODB.Command")
Set objCommand1.ActiveConnection = objConnection
'on error resume next

objCommand.CommandText = ";(&(objectclass=organizationalUnit));cn,ADsPath;subtree"
Set objRecordSet = objCommand.Execute
if err.number<>0 then
msgbox "无法找到:" & TARGET_OU
end if
wscript.echo "Begin:"
If objRecordSet.RecordCount>0 Then
i = 0
Set OU = GetObject(objRecordSet.Fields("ADsPath").Value)
OUdistinguishedName=OU.distinguishedName
Wscript.Echo OUdistinguishedName
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

strBase = ""
' Filter on all user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,ADsPath,lastLogonTimeStamp" & ";subtree"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes
' Run the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 10000
adoCommand.Properties("Timeout") = 60
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute

' Enumerate resulting recordset.
adoRecordset.movefirst
Do Until adoRecordset.EOF
On Error Resume Next
adspath=adoRecordset.Fields("adspath")
ShowMSG adspath
Set objMailbox = GetObject(adspath)
lastName=objMailbox.sn
If(objMailbox.legacyExchangeDN="") Then
mailaddress="无邮箱"
Else
mailaddress=objMailbox.mail
End If
statusflag=objMailbox.AccountDisabled
firstName=objmailbox.givenname
mailNickname=objMailbox.samaccountname
company=objMailbox.company
department=objMailbox.department
Set objDate = adoRecordset.Fields("lastLogonTimeStamp").Value
If (Err.Number <> 0) Then
On Error GoTo 0
dtmDate = #1/1/1601#
Else
On Error GoTo 0
lngHigh = objDate.HighPart
lngLow = objDate.LowPart
If (lngLow < 0) Then
lngHigh = lngHigh + 1
End If
If (lngHigh = 0) And (lngLow = 0 ) Then
dtmDate = #1/1/1601#
Else
dtmDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
+ lngLow)/600000000 - lngBias)/1440
End If
End If
lastLogin=dtmDate

fLog.WriteLine mailNickname & "," & lastName & "," & firstName & "," & company & "," & department & "," & lastLogin & "," & mailaddress & "," & statusflag

adoRecordset.MoveNext
i=i+1
Loop

End If

wscript.echo "总计输出账号为:" & i

Sub ShowMSG(strSubMSG)
Wscript.Echo Time & vbTab & strSubMSG
end sub

set adoRecordset=nothing
set adoCommand=nothing
adoConnection.close
set adoConnection=nothing

2008年11月13日星期四

2008年9月25日星期四

AD用户删除脚本

最近在客户那做一个AD相关的项目,要实现一个批量删除AD用户的需求,可以通过以下的AD脚本+txt文件实现批量功能:(vbs脚本如下)
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("D:\Test\Book.txt", ForReading)

Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
'--------------Start--------------
TARGET_OU = "JT" '删除帐号所在的OU
samAccountName=strNextLine '删除帐号的samAccountName


Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

Dim rootDSE
Set rootDSE = GetObject("LDAP://rootDSE")
BaseDN = rootDSE.Get("defaultNamingContext")

DC= replace(BaseDN,"DC=",",")
DC= replace(DC,",,",".")
DC=right(DC,len(DC)-1)

objCommand.CommandText = ";(&(objectcategory=person)(objectclass=user)(samAccountName="&samAccountName&"));cn,ADsPath,distinguishedName;subtree"
'MsgBox objCommand.CommandText
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount>0 Then
cn=objRecordSet.Fields("cn") '查找要删除帐号的CN名.因为删除的时候要指定CN名,我不知道这里查出来的,带不带“cn“,如果不带,手工加一下
ComDNPath = objRecordSet.Fields("distinguishedName")'得到distinguishedName,并在如下的代码中重新组合成OU的LDAP
End If
'MsgBox ComDNPath
arrDirectoryLocation = Split(ComDNPath,",")
'MsgBox Ubound(arrDirectoryLocation)
For i = 1 to Ubound(arrDirectoryLocation)
If i = 1 Then
strComOU = arrDirectoryLocation(i)
Else
strComOU = strComOU & "," & arrDirectoryLocation(i)
End If
Next
Set objOU = GetObject("LDAP://" & strComOU)
If objRecordSet.RecordCount>0 Then
'MsgBox arrDirectoryLocation(0)
objOU.Delete "user", arrDirectoryLocation(0)
End If
'--------------End----------------
Loop

objTextFile.Close
set objTextFile = Nothing

另外附上两个参考vbs脚本库的地址:http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/usersgroups/users/
http://www.microsoft.com/china/technet/community/scriptcenter/scripts/ad/default.mspx
微软脚本中心:http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx

2008年8月21日星期四

SQL Server 日期函数使用大全

--转换日期不同的输出格式
print convert(varchar(10),getdate(),100)--默认格式 mon dd yyyy hh:miAM(或 PM)
print convert(varchar(10),getdate(),101)--美国标准 mm/dd/yyyy
print convert(varchar(10),getdate(),102)--ANSI yy.mm.dd
print convert(varchar(10),getdate(),103)--英国/法国 dd/mm/yy
print convert(varchar(10),getdate(),104)--德国 dd.mm.yy
print convert(varchar(10),getdate(),105)--意大利 dd-mm-yy
print convert(varchar(10),getdate(),110)--美国 mm-dd-yy
print convert(varchar(10),getdate(),111)--日本 yy/mm/dd
print convert(varchar(10),getdate(),112)--ISO yymmdd
print convert(varchar(10),getdate(),121)-- yyyy-mm-dd

--一周的第一天 美国英语中默认 7 对应星期日。
select @@DATEFIRST

--一个月的第一天 DATEDIFF 返回两个指定日期之间所跨的日期和时间边界的数目
select dateadd(mm,datediff(mm,0,getdate()),0)

--本周的星期一
select dateadd(wk,datediff(wk,0,getdate()),0)

--一年的第一天
SELECT DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
select cast((cast(year(getdate()) as varchar)+'-01-01') as datetime)

--季度的第一天
SELECT DATEADD(qq, DATEDIFF(qq,0,getdate()), 0)

--当天的零时
SELECT DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)
select cast(convert(varchar(10),getdate(),121) as datetime)

--上个月的最后一天 :本月第一天减10ms.
SELECT dateadd(ms,-10,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))

--本月的最后一天
select dateadd(dd,-1,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))

--显示星期几
select datename(weekday,getdate())

--如何取得某个月的天数
SELECT Day(dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0)))

--判断是否闰年
SELECT case day(dateadd(mm, 2, dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0))))
when 28 then '平年' else '闰年' end

--当前季度有多少天
declare @m tinyint,@time smalldatetime
select @m=month(getdate())
select @m=case when @m between 1 and 3 then 1
when @m between 4 and 6 then 4
when @m between 7 and 9 then 7
else 10 end
select @time=datename(year,getdate())+'-'+convert(varchar(10),@m)+'-01'
select datediff(day,@time,dateadd(mm,3,@time))

2008年8月13日星期三

如何打开.csproj项目文件


不知道为什么Visual Studio 2005的sp1要创建出.csproj格式的项目文件,难道就是为了让每个人都打上sp1的补丁,最讨厌的是Microsoft Visual Studio 2008竟然也不认这种格式的项目文件,难道是vs.net 2005的sp1比vs.net 2008产品开发的时间较晚,还是两个产品不是同一个产品组开发出来的。摸索了半天找到了解决方法,其实很简单,就是用vs2008去强制打开.csproj的文件。
点击.csproj项目文件,右键选择打开方式,点击浏览,找到vs2008的默认安装目录的运行程序:E:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe,点击确定后会弹出转换选择对话框(如下图),选择下一步或者完成,转换后就可以打开了……

2008年8月11日星期一

.Net实现Post方式数据传输

这两天帮一个朋友实现一个短信交互的网站,要跟sp进行接口数据交换,接口实现方式是Post,我们提供数据接收,实现功能后自己也写了一段POST程序进行了一下测试,代码如下:
首先是发送数据

string strParm = "传输的XML字符串";
Encoding encode = System.Text.Encoding.Default;

byte[] arrB = encode.GetBytes(strParm);

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://localhost:34738/MOPage.aspx");
myReq.Method = "POST";
myReq.ContentType = "application/x-www-form-urlencoded";
myReq.ContentLength = arrB.Length;
Stream outStream = myReq.GetRequestStream();
outStream.Write(arrB, 0, arrB.Length);
outStream.Close();
WebResponse myResp = null;
try
{
//接收HTTP做出的响应
myResp = myReq.GetResponse();
}
catch (Exception ex)
{
throw ex;
}
Stream ReceiveStream = myResp.GetResponseStream();
StreamReader readStream = new StreamReader(ReceiveStream, encode);
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
string str = null;
while (count > 0)
{
str += new String(read, 0, count);
count = readStream.Read(read, 0, 256);
}
readStream.Close();
myResp.Close();
Response.Write(str);


下边代码实现接收数据功能


由于数据编码格式采用的GBK,接口使用asp.net技术实现,所以接收端采用GB2312格式转换数据流,接收数据并转换为xml实体对象存储
string ReqToWrite = string.Empty;
try
{
byte[] ReqData = Request.BinaryRead(Request.ContentLength);//得到请求的数据
//string ReqQuery = System.Text.UnicodeEncoding.UTF8.GetString(ReqData, 0, ReqData.Length);
string ReqQuery = System.Text.Encoding.GetEncoding("GB2312").GetString(ReqData, 0, ReqData.Length);
ReqQuery = ReqQuery.Replace("\r\n", "");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(ReqQuery);
XmlElement root = xmlDoc.DocumentElement;
XmlNodeList nodeList = root.SelectNodes("/message");
int i=0;
foreach (XmlNode node in nodeList)
{
string linkid, spid, spcode, feecode, feeprice, toicp, product, feecategory, channel, mobile, content, isprovision, issubscribe, createDate;
linkid = node.SelectSingleNode("linkid").InnerText.Trim();
spid = node.SelectSingleNode("spid").InnerText.Trim();
spcode = node.SelectSingleNode("spcode").InnerText.Trim();
feecode = node.SelectSingleNode("feecode").InnerText.Trim();
feeprice = node.SelectSingleNode("feeprice").InnerText.Trim();
toicp = node.SelectSingleNode("toicp").InnerText.Trim();
product = node.SelectSingleNode("product").InnerText.Trim();
feecategory = node.SelectSingleNode("feecategory").InnerText.Trim();
channel = node.SelectSingleNode("channel").InnerText.Trim();
mobile = node.SelectSingleNode("mobile").InnerText.Trim();
content = node.SelectSingleNode("content").InnerText.Trim();
isprovision = node.SelectSingleNode("isprovision").InnerText.Trim();
issubscribe = node.SelectSingleNode("issubscribe").InnerText.Trim();
createDate = node.SelectSingleNode("createDate").InnerText.Trim();
i=InterfaceAccess.InsertMOInfo(linkid, spid, spcode, feecode, Convert.ToInt32(feeprice), toicp, product, feecategory,
channel, mobile, content, isprovision, issubscribe, Convert.ToDateTime(createDate), ReqQuery);
}
ReqToWrite = i.ToString();
}
catch (Exception ex)
{
// ....
}
finally
{
Response.Write(ReqToWrite);
Response.End();
}

以上程序分别需要的命名空间引用如下:
using System.Net;
using System.IO;
using System.Text;
using System.Xml;
有一点需要要注意ASP.NET中为了防止注入攻击,对"<"等字符进行了限制,所以要在被请求的ASPX页面中,将 Page指令中的ValidateRequest 设置"false"

2008年8月1日星期五

vmware server 2.0 RC1 安装过程中的问题

今天我的机器上那个vmware 6.5过期了,下载了一个vmware server 2.0尝试安装,我的机器是windows 2003 sp2 ,安装时遇到了很大问题,出现下边的错误:

Product: VMware Server -- Error 2755. Server returned unexpected error 1625 attempting to install package C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\{AF08C71F-F822-4416-87A9-2BBF5A8A5F12}~setup\VMware Server.msi.
折腾了半天终于终于找到了解决的方法:
1.直接打开控制面板的管理工具。(或者单击“开始”,单击“运行”,键入 control admintools,然后单击“确定”。)
2.双击“本地安全策略”。
3.单击“软件限制策略”。注意:如果未列出软件限制,请右击“软件限制策略”,然后单击“新建策略”。
4.在“对象类型”下,双击“强制”。
5.单击“除本地管理员以外的所有用户”,然后单击“确定”。
6.重新启动计算机。
wmware server 2.0采用基于apache的web方式进行管理操作,集成了证书认证模式的信任机制,感觉功能较server1的版本有很大改进和提高,但对于我来说安装了太多我不需要的东西,感受几十分钟后毫不犹豫的卸载了^_^

2008年6月28日星期六

xp_cmdshell安全使用

xp_cmdshell可以让系统管理员以操作系统命令行解释器的方式执行给定的命令字符串,
并以文本行方式返回任何输出,是一个功能非常强大的扩展存贮过程。
一般情况下,xp_cmdshell对管理员来说也是不必要的,xp_cmdshell的消除不会对Server造成
任何影响。
可以将xp_cmdshell消除:
Use Master
Exec sp_dropextendedproc N'xp_cmdshell'
Go

如果需要的话,可以把xp_cmdshell恢复回来:
Use Master
Exec sp_addextendedproc N'xp_cmdshell', N'xplog70.dll'
Go

xp_cmdshell 操作系统命令外壳
这个过程是一个扩展存储过程,用于执行指定命令串,并作为文本行返回任何输出。
语法:
xp_cmdshell command_string[,no_output]
command_string 要执行的命令串
no_output 不返回命令执行的输出
说明:
在把xp_cmdshell的执行许可权授予用户时,用户将能够在Windows NT命令
外壳执行运行SQL Server(通常是本地系统)的帐号有执行特权的任何
操作系统命令。
例:
1、EXEC master..xp_cmdshell "dir *.exe"
返回可执行文件的列表
2、EXEC master..xp_cmdshell "copy d:\test1.jpg e:\" no_output
不返回输出
3、特别是执行
EXEC master..xp_cmdshell "net start awhost32"
EXEC master..xp_cmdshell "net stop awhost32"
可以启动和停止远程的PCAnywhere服务。对远程服务器操作很有帮助。

SQL Server2005可以通过界面配置屏蔽xp_cmdshell功能

表中删除重复行的SQL语句

--查询重复语句

select * from SearchLogHistory where searchkey in (select searchkey FROM SearchLogHistory GROUP BY searchkey HAVING count(*) > 1)

--删除重复语句

delete SearchLogHistory where searchkey in (select searchkey FROM SearchLogHistory GROUP BY searchkey HAVING count(*) > 1) --获取重复的字段
and logid not in(select max(logid) from SearchLogHistory group by searchkey having count(*)>1 )--排除唯一重复的ID

2008年6月27日星期五

SID 介绍

            

SID是什么,Active Directory活动目录域中每一个对象也有一个唯一标识,成为GUID。GUID=SID + RID 。活动目录中专门有一个操作主机角色叫RID,就是为域中的每个对象分配一个RID号。最终GUID在所有域,乃至全世界都是唯一的。计算机使用 SID 来跟踪每个帐户: 如果重命名管理员帐户,计算机仍然知道哪个帐户是管理员帐户。 这是因为 SID 不同于名称,它永远不会更改。

            现实应用中很多使用磁盘映像克隆技术来大规模部署 Windows。此方法要求将完全安装和配置的 Windows 计算机的磁盘复制到其他计算机的磁盘驱动器。其他这些计算机似乎已经有效地完成了相同的安装过程,并且可以立即使用。虽然此方法节省了数小时的工作量并且比其他部署方法有效,但是它存在一个严重问题,即每个克隆的系统都具有一个完全相同的计算机安全标识符 (SID)。例如Ghost程序制作系统、使用VMware、Virtual虚拟操作系统拷贝时,这一因素会损害工作组环境的安全性,并且在具有多个相同计算机 SID 的网络中,还可能损害可移动媒体安全性。来自 Windows 社区的要求已经促使多家公司开发可以在克隆系统后更改计算机的SID 的程序。

            NewSID 是可更改计算机的 SID 的程序。它是一个免费的 Win32 程序,这意味着它可以容易地在以前克隆的系统上运行。NewSID 可在 Windows NT 4、Windows 2000、Windows XP 和 Windows .NET Server 上运行。NewSID 首先为计算机生成一个随机的 SID,然后更新它在注册表和文件安全描述符中找到的现有计算机 SID 的实例,并用新 SID 替换旧 SID。NewSID 要求使用管理权限运行。它有两个功能:更改 SID 和更改计算机名称。NewSID 的 SID 同步功能使您可以指定从另一台计算机获取新 SID 而不是随机生成 SID。使用此功能,可以将备份域控制器 (BDC) 移动到一个新域,因为根据 BDC 与其他域控制器 (DC) 具有相同的计算机 SID,可以确定该 BDC 与某个域的关系。只需选择“Synchronize SID”按钮并输入目标计算机的名称。您必须具有更改目标计算机的注册表项的安全设置的权限,这通常意味着您必须以域管理员身份登录才能使用此功能。

            请注意当您运行 NewSID 时,注册表的大小将会增长,因此请确保注册表最大大小能够适应这一增长。我们已发现这一增长对系统性能没有明显影响。注册表增长的原因是:当 NewSID 应用临时安全设置时,注册表变零碎了。删除这些设置后,注册表不受影响。
NewSID绿色软件下载地址:http://download.sysinternals.com/Files/NewSid.zip
更多关于AD技术的参考:http://gnaw0725.blogbus.com/