Sign in to follow this  
Followers 0
jerrychen

VBScript to AutoIt Converter Not Work

1 post in this topic

#1 ·  Posted (edited)

VBScript to AutoIt Converter

Hi All:

I've try this tool , but it's not work in my computer

can some body help me to convert ?

On Error Resume Next
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set objEmail = CreateObject("CDO.Message")
Set objFSO = CreateObject("Scripting.FileSystemObject")

objStart = now()
mailfrom = "<admin@any.com>"
mailto = "admin@any.com"
smtp_srv = "smtp.any.com"
smtp_port = "25"

DCname = GetObject("LDAP://RootDSE").Get("defaultNamingContext")
DesOU = "OU=DisableAccount,OU=Adusers"
StopOU = "OU=StopAccount,OU=Adusers"
strDate = "20000101"
endDate = "20070131"
mv_array=Array(DesOU,StopOU)

html_array=Array("","","","","","","","")
csv_array = "異動類別,工號,廠別,顯示名稱,帳戶停用日,職級"
csv_tmp = "C:\異動清單.csv"

Set objAdConnection = CreateObject("ADODB.Connection")
Set objAdCommand = CreateObject("ADODB.Command")
objAdConnection.Provider = "ADsDSOObject"
objAdConnection.Open "Active Directory Provider"
Set objAdCommand.ActiveConnection = objAdConnection
objAdCommand.Properties("Page Size") = 5000
objAdCommand.Properties("Searchscope") = 2

objAdCommand.CommandText = "SELECT Name,distinguishedName FROM 'LDAP://OU=Adusers," & DCname & "' " & "WHERE objectCategory='user' " &_
    " and pager<>'99999999,9999' and pager<>'88888888,8888' and pager<>'77777777,7777' and pager<>'66666666,6666' order by pager"

Set objOraConnection = CreateObject("ADODB.Connection")
Set objOraRecordSet = CreateObject("ADODB.Recordset")
objOraConnection.Open "Driver={Microsoft ODBC For Oracle};Server=SOME.SERVER.COM;Uid=USER;Pwd=PASS;"

H_6 = "0"
H_7 = "0"
Set objAdRecordSet = objAdCommand.Execute
objAdRecordSet.First
Do Until objAdRecordSet.EOF
    Set objUser = GetObject("LDAP://" & objAdRecordSet.Fields("distinguishedName"))
    objUser.GetInfo
    strpager = objUser.Get("pager")
    strUserdn = objUser.Get("distinguishedName")
    Ucn = mid((split(strUserdn,"="))(1),1,(Len((split(strUserdn,"="))(1))-3))
    If (InStr(strUserdn,"DisableAccount")=0 and InStr(strUserdn,"StopAccount")=0 and InStr(Ucn,"$")=0) then
        Uou = mid(strUserdn,len(Ucn)+5 ,len(strUserdn) - len(DCname) - len(Ucn) - 5)
        if objUser.AccountDisabled <> 0 then
            H_7 = H_7 + 1
            html_array(7) = html_array(7) & "<tr><td rowspan=""2"">" & H_7 & "</td><td>顯示名稱</td><td>" & Ucn &"</td>" & chr(10) &_
                                            "</tr><tr><td>組織單位</td><td>" & Uou & "</td></tr>" & chr(10)
            mov_user strUserdn, "4201", "02"
        else
            If objUser.Get("pager") = "" Then
                Ustat = des_user(objUser, Ora_posi, 0)
                H_6 = H_6 + 1
                html_array(6) = html_array(6) & "<tr><td rowspan=""2"">" & H_6 & "</td><td>顯示名稱</td><td>" & Ucn & "</td>" & chr(10) &_
                                                "</tr><tr><td>組織單位</td><td>" & Uou & "</td></tr>" & chr(10)
            else
                pnl_no = (split(strpager,","))(0)
                fact_no2 = (split(strpager,","))(1)
                objOraRecordSet.Open s_sql & "SELECT * FROM TABLE where pnl_no = '" & pnl_no & "' and fact_no2 = '" &_
                                                fact_no2 & "' and up_type <> '00'" &_
                                                " and (upd_d between " & strDate & "0000 and " & endDate & "2359) ", objOraConnection, 3, 3
                objOraRecordset.First
                Do Until objOraRecordset.EOF
                    Ora_Uptype = objOraRecordSet("UP_TYPE")
                    Ora_pnl_no = objOraRecordSet("PNL_NO")
                    Ora_fact_no2 = objOraRecordSet("FACT_NO2")
                    Ora_pnl_noN = objOraRecordSet("PNL_NO_N")
                    Ora_fact_noN = objOraRecordSet("FACT_NO_N")
                    Ora_posi = objOraRecordSet("POSI_NO")
                    Ora_stop = objOraRecordSet("STOP_D")

                    i = 0
                    if Ora_posi > 4200 then
                        i = i + 3
                        posi_tmp = "副理以下"
                    else posi_tmp = "副理以上"
                    end if
                    if Ora_Uptype = "02" then
                        i = i + 1
                    elseif Ora_Uptype = "01" then
                        i = i + 2
                    end if
                    if Ora_Uptype <> "01" then
                        Ustat = des_user(objUser, Ora_posi, Ora_Uptype, Ora_stop)
                        NUou = mov_user(strUserdn, Ora_posi, Ora_Uptype)
                        h_ro = 5
                        if i < 2 then h_ro = 4
                        html_tmp = "<tr><td colspan=""3"" bgcolor=""#C0C0C0"">工號:" & Ora_pnl_no & " 廠別:" & Ora_fact_no2 & "</td></tr>" & chr(10) &_
                                    "<tr><td rowspan=""" & h_ro & """>&nbsp;</td><td>顯示名稱</td><td>" & Ucn & "</td></tr>" & chr(10) &_
                                    "<tr><td>帳戶狀態</td>" & Ustat  & "</td></tr>" & chr(10) &_
                                    "<tr><td>原始組織單位</td><td>" & Uou & "</td></tr>" & chr(10)
                        if Ora_posi > 4200 then html_tmp = html_tmp & "<tr><td>新組織單位</td><td>" & NUou & "</td></tr>" & chr(10)
                        html_tmp = html_tmp & "<tr><td>帳戶停用日</td><td>" & Ora_stop & "</td></tr>" & chr(10)
                    else
                        Ustat = des_user(objUser, Ora_posi, Ora_Uptype)
                        objUser.Put "pager", Ora_pnl_noN & "," & Ora_fact_noN
                        objUser.SetInfo
                        html_tmp = "<tr><td rowspan=""4"">&nbsp;</td><td>顯示名稱</td><td>" & Ucn & "</td></tr>" & chr(10) &_
                                    "<tr><td>原始資料</td><td>工號:" & Ora_pnl_no & " 廠別:" & Ora_fact_no2 & "</td></tr>" & chr(10) &_
                                    "<tr><td>異動資料</td><td>工號:" & Ora_pnl_noN & " 廠別:" & Ora_fact_noN & "</td></tr>" & chr(10) &_
                                    "<tr><td>異動日</td><td>" & Ora_stop & "</td></tr>" & chr(10)
                    end if
                    html_array(i) = html_array(i) & html_tmp
                    if i = 0 or i = 1 or i = 3 or i = 4 then
                        csv_array = csv_array & chr(10) & Ora_Uptype & "," & Ora_pnl_no & "," & Ora_fact_no2 & "," & Ucn & "," & Ora_stop & "," & posi_tmp
                    end if
                    objOraRecordset.MoveNext
                Loop
                objOraRecordSet.Close
            end if
        end if
    end if
    strpager = ""
    objAdRecordSet.MoveNext
Loop
objOraConnection.Close
objAdConnection.Close
for i = 0 to Ubound(html_array)
    if html_array(i) = "" then html_array(i) = "<tr><td colspan=""3"" bgcolor=""#C0C0C0"">沒有資料</td></tr>" & chr(10)
next

AD_ck = "<tr><td colspan=""3"" bgcolor=""#6699CC"">異動前已停用</td></tr>" & html_array(7) & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#6699CC"">副理以上同仁</td></tr>" & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#FFFF66"">異動類別:留職停薪</td></tr>" & html_array(0) & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#FFFF66"">異動類別:離職</td></tr>" & html_array(1) & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#FFFF66"">異動類別:異動</td></tr>" & html_array(2) & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#6699CC"">副理以下同仁</td></tr>" & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#FFFF66"">異動類別:留職停薪</td></tr>" & html_array(3) & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#FFFF66"">異動類別:離職</td></tr>" & html_array(4) & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#FFFF66"">異動類別:異動</td></tr>" & html_array(5) & chr(10) &_
        "<tr><td colspan=""3"" bgcolor=""#6699CC"">AD 未設定工號</td></tr>" & html_array(6) & chr(10)

Set objTextFile = objFSO.OpenTextFile(csv_tmp, 2, True)
objTextFile.WriteLine(csv_array)
objTextFile.Close

objFSO.DeleteFile(csv_tmp)

Public Function des_user(des_id,des_u_posi,des_up_ty,des_stop_d)
    user_stat = des_id.AccountDisabled
    if des_u_posi > 4200 and des_up_ty = "02" then
        des_id.AccountDisabled = TRUE
        objUser.AccountExpirationDate = left(des_stop_d,4)&"/"&mid(des_stop_d,5,2)&"/"&right(des_stop_d,2)
        des_id.SetInfo
        if des_id.AccountDisabled = 0 then
            des_user = "<td><font color=""red"">停用失敗</font>"
        else
            des_user = "<td><font color=""blue"">停用成功</font>"
        end if
    else
        if user_stat = 0 then
        des_user = "<td><font color=""red"">原始狀態啟用中</font>"
        else
        des_user = "<td><font color=""blue"">原始狀態已停用</font>"
        end if
    end if
End Function
Public Function mov_user(mov_dn,mov_u_posi,mov_up_ty)
    if mov_u_posi > 4200 and (mov_up_ty = "02" or mov_up_ty = "03") then
        mov_dn = replace(replace(mov_dn,"=","="""),",",""",")&""""
        if mov_up_ty = "02" then
            mvou = mv_array(0)
        else
            mvou = mv_array(1)
        end if
        CommandString = "%comspec% /c dsmove " & mov_dn & " -newparent " & mvou & "," & DCname
        WshShell.Run CommandString, 0, True
    end if
    mov_user = mvou
End Function
Function get_date(date_num)
    objYear = year(date_num)
    objMonth = month(date_num)
    if objMonth < 10 then objMonth = "0" & objMonth
    objDay = day(date_num)
    if objDay < 10 then objDay = "0" & objDay
    get_date = objYear & objMonth & objDay
End Function
Edited by jerrychen

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0