|
- Dim WshShell,ver,windir,val(500,3),reg,srv_dict,firewall_dict
- Set WshShell=WScript.CreateObject("WScript.Shell")
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objWMIService = GetObject("winmgmts:\\.")
- Set Shell=CreateObject("Shell.Application")
- Set srv_dict=CreateObject("Scripting.Dictionary") '需调整的服务
- Set firewall_dict=CreateObject("Scripting.Dictionary")'需禁止接连网络的程序
- Set objRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
- Const HKEY_CLASSES_ROOT = &H80000000
- Const HKEY_CURRENT_USER = &H80000001
- Const HKEY_LOCAL_MACHINE = &H80000002
- tmp1="用户名"
- tmp2="用户密码"
- tmp1=trim(tmp1):tmp2=trim(tmp2)
- if ver>5.5 then '如果是Win78则试写注册表以检查权限,如果没有权限则以管理身份重新运行
- If WScript.Arguments.length = 0 Then
- Shell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
- WScript.quit
- End If
- '如果是78则打开管理员使用应用.
- SetRegACL("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System")
- WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA",0,"REG_DWORD" '是否开启UAC
- WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\PromptOnSecureDesktop",0,"REG_DWORD" '桌面是否变黑
- WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\ConsentPromptBehaviorAdmin",0,"REG_DWORD" '通知强度级别
- end if
- msgbox tmp1
- user tmp1,tmp2'添加用户:
- '设置自动登陆
- 'WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName",tmp1,"REG_SZ"
- 'WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDefaultPassword",tmp2,"REG_SZ"
- 'WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon",1,"REG_DWORD"
- 'WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\ForceAutoLogon",1,"REG_DWORD"
- Wscript.Quit
- Function user(username,password) '没有用户就新建/设置密码,并永不过期/加到超级组
- dim mo,ObjServices
- Set objWMI = GetObject("Winmgmts:\\.\Root\Cimv2")
- Set ObjServices =objWMI.ExecQuery("Select * From Win32_Service")
- on error resume next
- For Each mo In ObjServices
- If mo.Name = "LanmanWorkstation" Then
- mo.ChangeStartMode("Automatic")
- user=mo.Start()
- exit for
- End if
- Next
- Set objWMI = nothing
- Set ObjServices = nothing
- debug("检查" & username & "权限和密码是否正确")
- Set wbemServices = Getobject("winmgmts:\\.")
- Set wbemObjectSet=wbemServices.execquery("select name from win32_userAccount")
- user=""
- For Each mo In wbemObjectSet
- if mo.name=username then
- user=mo.name
- exit for
- end if
- Next
- err.clear
- Set wbemServices=GetObject("WinNT://.") '得到adsi接口,绑定
- if err.number<>0 then
- debug("工作站服务未正常运行,无法对用户进行操作,本操作被跳过")
- err.clear
- user=username
- end if
- If user = "" Then '无此用户则建立,有则取得句柄
- Set wbemObjectSet=wbemServices.Create("user",username) '建立用户
- Else
- Set wbemObjectSet = GetObject("WinNT://./"&username)'得到用户
- End If
- wbemObjectSet.SetPassword password '设置密码
- wbemObjectSet.Put "UserFlags", &H10201'设置密码永不过期
- wbemObjectSet.accountdisabled=false '设置账号不禁用
- wbemObjectSet.SetInfo '保存
- user="失败."
- Set wbemServices = GetObject("WinNT://./Administrators")
- Set wbemObjectSet = GetObject("WinNT://"&username)'得到用户
- wbemServices.Add(wbemObjectSet.ADsPath)
- user="搞定"
- On error resume next
- Set wbemServices= nothing
- Set wbemObjectSet= nothing
- End Function
- Function SetRegACL(reg_path) '为当前用户设置注册表权限
- Set ini_file = Nothing
- dim tmp1,tmp2,tmp3
- tmp3=WshShell.ExpandEnvironmentStrings("%temp%") & "\setacl."
- tmp2="\if":tmp1=reg_path:if right(reg_path,1)<>"" then tmp1=reg_path & ""
- on error resume next
- objFSO.deletefile tmp3 & "ini",true
- tmp2=WshShell.RegRead(tmp1)
- on error goto 0
- if tmp2="\if" then SetRegACL="没找到注册表" & reg_path :Exit Function
- Set ini_file = objFSO.OpenTextFile(tmp3 & "ini",8,True,0)
- tmp2=tmp1
- tmp2=replace(tmp2,"HKEY_LOCAL_MACHINE","MACHINE",1,-1,1)
- tmp2=replace(tmp2,"HKEY_CLASSES_ROOT","CLASSES_ROOT",1,-1,1)
- tmp2=replace(tmp2,"HKEY_CURRENT_USER","CURRENT_USER",1,-1,1)
- tmp2=replace(tmp2,"HKEY_USERS","USERS",1,-1,1)
- tmp2=replace(tmp2,"HKEY_CURRENT_CONFIG","CURRENT_CONFIG",1,-1,1)
- ini_file.WriteLine "[Version]" & chr(13) & "Signature = ""$Chicago$""" & chr(13) & chr(13) & "[Registry Keys]"
- ini_file.WriteLine chr(34) & tmp2 & chr(34) & ", 0, "& chr(34) & "O:BA" & chr(34)
- Set ini_file = Nothing
- WshShell.Run "secedit /configure /db " & tmp3 & "sdb /cfg " & tmp3 & "ini /quiet",0,true '先获得所有权
- objFSO.deletefile tmp3 & "ini",true
- Set ini_file = objFSO.OpenTextFile(tmp3 & "ini",8,True,0)
- ini_file.WriteLine tmp1 & " [1 5 7 11 14 17 21]"
- Set ini_file = Nothing
- WshShell.Run "regini " & tmp3 & "ini",0,true '再设权限
- objFSO.deletefile tmp3 & "ini",true
- SetRegACL="正常完成"
- End Function
复制代码 |
|