protected void btnApprove_Click(Object Sender, EventArgs e)
        {
            oResourceRequest.UpdateWorkflowHours(intResourceWorkflow);
            DataSet ds             = oAccountRequest.GetMaintenance(intRequest, intItem, intNumber);
            int     intUser        = oRequest.GetUser(intRequest);
            DataSet dsParameters   = oAccountRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
            string  strMaintenance = ds.Tables[0].Rows[0]["maintenance"].ToString();
            string  strUser        = ds.Tables[0].Rows[0]["username"].ToString();
            int     intDomain      = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
            Domains oDomain        = new Domains(intProfile, dsn);

            intDomain = Int32.Parse(oDomain.Get(intDomain, "environment"));
            AD             oAD       = new AD(intProfile, dsn, intDomain);
            Variables      oVariable = new Variables(intDomain);
            DirectoryEntry oEntry    = oAD.UserSearch(strUser);

            if (oEntry != null)
            {
                switch (strMaintenance)
                {
                case "DISABLE":
                    // Account Disable
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Disable", oAD.Enable(oEntry, false), "Account " + strUser + " was successfully disabled", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "UNLOCK":
                    // Account Unlock
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Unlock", oAD.Unlock(oEntry), "Account " + strUser + " was successfully unlocked", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "ENABLE":
                    // Account Enable
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Enable", oAD.Enable(oEntry, true), "Account " + strUser + " was successfully enabled", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "EMAIL":
                    // Account Email
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Email", oAD.CreateMailbox(oEntry), "Account " + strUser + " was successfully created a mailbox", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "MOVE":
                    // Account Move
                    string strPath = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Move", oAD.MoveAccount(oEntry, strPath), "Account " + strUser + " was successfully moved", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "PASSWORD":
                    // Account Password Change
                    Encryption oEncrypt    = new Encryption();
                    string     strPassword = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Password Change", oAD.SetPassword(oEntry, oEncrypt.Decrypt(strPassword, "adpass")), "The password for account " + strUser + " was successfully changed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "COPY":
                    // Account Copy
                    string strID    = txtID.Text;
                    string strFirst = txtFirst.Text;
                    string strLast  = txtLast.Text;
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Copy", oAD.CreateUser(strID, strFirst, strLast, txtPassword.Text, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.UserOU()), "Account " + strUser + " was successfully copied", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    foreach (ListItem oList in chkGroups.Items)
                    {
                        if (oList.Selected == true)
                        {
                            oRequest.AddResult(intRequest, intItem, intNumber, "Group Membership", oAD.JoinGroup(strID, oList.Value, 0), "Account " + strUser + " was successfully added to the group " + oList.Value, intEnvironment, (oService.Get(intService, "notify_client") == "1"), "");
                        }
                    }
                    break;

                case "DELETE":
                    // Account Deletion
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Deletion", oAD.Delete(oEntry), "Account " + strUser + " was successfully deleted", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "RENAME":
                    // Account Rename
                    string strI = txtID.Text;
                    string strF = txtFirst.Text;
                    string strL = txtLast.Text;
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Rename", oAD.Rename(oEntry, strI, strF, strL), "Account " + strUser + " was successfully renamed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;
                }
            }
            oAccountRequest.UpdateMaintenance(intRequest, intItem, intNumber, 1, txtComments.Text);
            Complete();
        }
Esempio n. 2
0
        public void Process(int _requestid, int _itemid, int _number, int _id, string _server, string _password, int _environment)
        {
            Requests  oRequest  = new Requests(user, dsn);
            Variables oVariable = new Variables(_environment);
            Users     oUser     = new Users(user, dsn);
            DataSet   ds        = Get(_id);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DateTime _now      = DateTime.Now;
                string   strUnique = _now.Day.ToString() + _now.Month.ToString() + _now.Year.ToString() + _now.Hour.ToString() + _now.Minute.ToString() + _now.Second.ToString() + _now.Millisecond.ToString();
                string   strXID    = ds.Tables[0].Rows[0]["xid"].ToString().ToUpper();
                int      intUser   = oUser.GetId(strXID);
                int      intDomain = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
                Domains  oDomain   = new Domains(user, dsn);
                if (oDomain.Get(intDomain, "account_setup") == "1" || oDomain.Get(intDomain, "account_maintenance") == "1")
                {
                    intDomain = Int32.Parse(oDomain.Get(intDomain, "environment"));
                    Variables oVar      = new Variables(intDomain);
                    AD        oAD       = new AD(user, dsn, intDomain);
                    string    strFName  = oUser.Get(intUser, "fname");
                    string    strLName  = oUser.Get(intUser, "lname");
                    string    strResult = "";
                    string    strID     = strXID;
                    string    strAction = "";
                    //string strNotify = "<p><a href=\"javascript:void(0);\" class=\"bold\" onclick=\"ShowAccountDetail('divAccount_" + strUnique + "');\">Account " + strXID.ToUpper() + " in " + oVar.Name() + "</a><br/>";
                    //strNotify += "<div id=\"divAccount_" + strUnique + "\" style=\"display:none\"><table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" style=\"" + oVariable.DefaultFontStyle() + "\">";
                    string strNotify = "<p><table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" style=\"" + oVariable.DefaultFontStyle() + "\">";
                    strNotify += "<tr><td><b><u>Account &quot;" + strXID.ToUpper() + "&quot; in " + oVar.Name() + "</u></b></td></tr>";
                    // Add User
                    if (intDomain != (int)CurrentEnvironment.CORPDMN && intDomain != (int)CurrentEnvironment.PNCNT_PROD)
                    {
                        strID = "E" + strID.Substring(1);
                        if (oAD.Search(strID, false) != null)
                        {
                            strAction = " already existed";
                        }
                        else
                        {
                            strID = "T" + strID.Substring(1);
                            if (oAD.Search(strID, false) != null)
                            {
                                strAction = " already existed";
                            }
                            else if (oDomain.Get(intDomain, "account_maintenance") == "1")
                            {
                                strResult = oAD.CreateUser(strID, strFName, strLName, _password, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), "");
                                strAction = " was created";
                            }
                            else
                            {
                                strResult = "Cannot create accounts in this domain";
                            }
                        }
                    }
                    else
                    {
                        if (oAD.Search(strID, false) != null)
                        {
                            strAction = " already existed";
                        }
                        else if (oDomain.Get(intDomain, "account_maintenance") == "1")
                        {
                            strResult = oAD.CreateUser(strID, strFName, strLName, _password, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), "");
                            strAction = " was created";
                        }
                        else
                        {
                            strResult = "Cannot create accounts in this domain";
                        }
                    }
                    if (strResult == "")
                    {
                        strNotify += "<tr><td>The account " + strID + strAction + " for " + strFName + " " + strLName + " in " + oVar.Name() + "</td></tr>";
                        // Local Groups
                        string strLocal = ds.Tables[0].Rows[0]["localgroups"].ToString();
                        if (strLocal != "")
                        {
                            string[] strGroups;
                            char[]   strSplit = { ';' };
                            strGroups = strLocal.Split(strSplit);
                            DirectoryEntry oAccount = new DirectoryEntry("WinNT://" + oVar.Domain() + "/" + strID + ",user", oVar.Domain() + "\\" + oVar.ADUser(), oVar.ADPassword());
                            DirectoryEntry oServer  = new DirectoryEntry("WinNT://" + oVar.Domain() + "/" + _server + ",computer", oVar.Domain() + "\\" + oVar.ADUser(), oVar.ADPassword());
                            for (int ii = 0; ii < strGroups.Length; ii++)
                            {
                                if (strGroups[ii].Trim() != "")
                                {
                                    try
                                    {
                                        DirectoryEntry oGroup = oServer.Children.Find(strGroups[ii]);
                                        oGroup.Invoke("Add", new object[] { oAccount.Path });
                                        strNotify += "<tr><td>The account " + strID + " was successfully added to the local group " + strGroups[ii] + "</td></tr>";
                                    }
                                    catch
                                    {
                                        strNotify += "<tr><td>There was a problem adding the account " + strID + " to the local group " + strGroups[ii] + "</td></tr>";
                                    }
                                }
                            }
                        }
                        // Global Groups
                        string strGlobal = ds.Tables[0].Rows[0]["adgroups"].ToString();
                        if (strGlobal != "")
                        {
                            string[] strGroups;
                            char[]   strSplit = { ';' };
                            strGroups = strGlobal.Split(strSplit);
                            for (int ii = 0; ii < strGroups.Length; ii++)
                            {
                                if (strGroups[ii].Trim() != "")
                                {
                                    if (oAD.Search(strGroups[ii], false) == null)
                                    {
                                        strResult = oAD.CreateGroup(strGroups[ii], "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), "", "GG", "S");
                                        if (strResult == "")
                                        {
                                            strNotify += "<tr><td>The group " + strGroups[ii] + " was successfully created in " + oVar.Name() + "</td></tr>";
                                        }
                                        else
                                        {
                                            strNotify += "<tr><td>There was a problem creating the group " + strGroups[ii] + " in " + oVar.Name() + "</td></tr>";
                                        }
                                    }
                                    else
                                    {
                                        strResult  = "";
                                        strNotify += "<tr><td>The group " + strGroups[ii] + " already exists in " + oVar.Name() + "</td></tr>";
                                    }
                                    if (strResult == "")
                                    {
                                        strResult = oAD.JoinGroup(strID, strGroups[ii], 0);
                                        if (strResult == "")
                                        {
                                            strNotify += "<tr><td>The account " + strID + " was successfully added to the domain group " + strGroups[ii] + "</td></tr>";
                                        }
                                        else
                                        {
                                            strNotify += "<tr><td>There was a problem adding the account " + strID + " to the domain group " + strGroups[ii] + "</td></tr>";
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        strNotify += "<tr><td>There was a problem creating an account for " + strFName + " " + strLName + " in " + oVar.Name() + " - ERROR: " + strResult + "</td></tr>";
                    }
                    strNotify += "</table></p>";
                    //strNotify += "</table></div></p>";
                    Complete(_id);
                    oRequest.AddResult(_requestid, _itemid, _number, strNotify);
                }
            }
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);
            int             intRequest      = Int32.Parse(Request.QueryString["rid"]);
            string          strStatus       = oServiceRequest.Get(intRequest, "checkout");
            DataSet         dsItems         = oRequestItem.GetForms(intRequest);
            int             intItem         = 0;
            int             intService      = 0;
            int             intNumber       = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool   boolSuccess = true;
                        string strResult   = oService.GetName(intService) + " Completed";
                        string strError    = oService.GetName(intService) + " Error";
                        // ********* BEGIN PROCESSING **************
                        AccountRequest oAccountRequest = new AccountRequest(intProfile, dsn);
                        Requests       oRequest        = new Requests(intProfile, dsn);
                        Users          oUser           = new Users(intProfile, dsn);
                        DataSet        ds      = oAccountRequest.GetMaintenance(intRequest, intItem, intNumber);
                        Domains        oDomain = new Domains(intProfile, dsn);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            string         strUser      = ds.Tables[0].Rows[0]["username"].ToString();
                            int            intDomain    = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
                            int            intEnv       = Int32.Parse(oDomain.Get(intDomain, "environment"));
                            int            intUser      = oRequest.GetUser(intRequest);
                            DataSet        dsParameters = oAccountRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
                            AD             oAD          = new AD(intProfile, dsn, intEnv);
                            Variables      oVariable    = new Variables(intEnv);
                            DirectoryEntry oEntry       = oAD.UserSearch(strUser);
                            if (oEntry != null)
                            {
                                strResult = "<p>The account " + strUser + " already exists in " + oDomain.Get(intDomain, "name") + "</p>";
                            }
                            else
                            {
                                strError = "";
                                Encryption oEncrypt     = new Encryption();
                                string     strFirst     = dsParameters.Tables[0].Rows[0]["value"].ToString();
                                string     strLast      = dsParameters.Tables[0].Rows[1]["value"].ToString();
                                string     strEmail     = dsParameters.Tables[0].Rows[2]["value"].ToString();
                                string     strTechnical = dsParameters.Tables[0].Rows[3]["value"].ToString();
                                string     strPassword  = oEncrypt.Decrypt(dsParameters.Tables[0].Rows[4]["value"].ToString(), "adpass");
                                if (strTechnical == "1")
                                {
                                    strResult = oAD.CreateUser(strUser, strFirst, strLast, strPassword, "", "Created By ClearView on " + DateTime.Today.ToShortDateString() + Environment.NewLine + "Requested by " + oUser.GetFullName(intProfile) + " (" + oUser.GetName(intProfile) + ")", oVariable.UserOUTechnical());
                                    if (strResult == "")
                                    {
                                        strResult = "<p>The account " + strUser + " was successfully created in " + oDomain.Get(intDomain, "name") + " with registry access (Password: "******")</p>";
                                    }
                                }
                                else
                                {
                                    strResult = oAD.CreateUser(strUser, strFirst, strLast, strPassword, "", "Created By ClearView on " + DateTime.Today.ToShortDateString() + Environment.NewLine + "Requested by " + oUser.GetFullName(intProfile) + " (" + oUser.GetName(intProfile) + ")", oVariable.UserOU());
                                    if (strResult == "")
                                    {
                                        strResult = "<p>The account " + strUser + " was successfully created in " + oDomain.Get(intDomain, "name") + " (Password: "******")</p>";
                                    }
                                }
                                string   strGroupsRequested = dsParameters.Tables[0].Rows[5]["value"].ToString();
                                string[] strGroupRequested;
                                char[]   strSplit = { ';' };
                                strGroupRequested = strGroupsRequested.Split(strSplit);
                                // Add Groups
                                for (int ii = 0; ii < strGroupRequested.Length; ii++)
                                {
                                    if (strGroupRequested[ii].Trim() != "")
                                    {
                                        // Add the group
                                        string strJoin = oAD.JoinGroup(strUser, strGroupRequested[ii].Trim(), 0);
                                        if (strJoin == "")
                                        {
                                            strResult += "<p>The user " + strUser + " was successfully joined to the group " + strGroupRequested[ii].Trim() + "</p>";
                                        }
                                        else
                                        {
                                            strError += "<p>The user " + strUser + " was NOT successfully joined to the group " + strGroupRequested[ii].Trim() + " : " + strJoin + "</p>";
                                        }
                                    }
                                }
                                oRequest.AddResult(intRequest, intItem, intNumber, "Account Modification", strError, strResult, intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                            }
                        }
                        if (strResult == "")
                        {
                            boolSuccess = false;
                        }
                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strResult + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_error.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strError + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1);
                    }
                }
            }
        }
Esempio n. 4
0
        protected void btnSave_Click(Object Sender, EventArgs e)
        {
            string       strGroupRemote = "GSGu_WKS" + lblName.Text + "RemoteA";
            string       strGroupAdmin  = "GSGu_WKS" + lblName.Text + "Adm";
            bool         bool2000       = (lblName.Text.ToUpper().StartsWith("T2K") == true || lblName.Text.ToUpper().StartsWith("W2K") == true);
            Workstations oWorkstation   = new Workstations(intProfile, dsn);
            Users        oUser          = new Users(intProfile, dsn);
            Domains      oDomain        = new Domains(intProfile, dsn);
            int          intDomain      = Int32.Parse(oWorkstation.GetVirtual(intID, "domainid"));

            intDomain = Int32.Parse(oDomain.Get(intDomain, "environment"));
            AD     oAD       = new AD(intProfile, dsn, intDomain);
            string strHidden = Request.Form[hdnApprove.UniqueID];

            while (strHidden != "")
            {
                string strField = strHidden.Substring(0, strHidden.IndexOf("&"));
                strHidden = strHidden.Substring(strHidden.IndexOf("&") + 1);
                string strFlag = strField.Substring(strField.IndexOf("_") + 1);
                strField = strField.Substring(0, strField.IndexOf("_"));
                if (strFlag == "1")
                {
                    int     intAccount = Int32.Parse(strField);
                    DataSet ds         = oWorkstation.GetAccount(intAccount);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        int    intUser = Int32.Parse(ds.Tables[0].Rows[0]["userid"].ToString());
                        string strID   = oUser.GetName(intUser);
                        if (intDomain != (int)CurrentEnvironment.CORPDMN && intDomain != (int)CurrentEnvironment.PNCNT_PROD)
                        {
                            strID = "E" + strID.Substring(1);
                            if (oAD.Search(strID, false) == null)
                            {
                                strID = "T" + strID.Substring(1);
                                if (oAD.Search(strID, false) == null)
                                {
                                    oAD.CreateUser(strID, strID, strID, "Abcd1234", "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), "");
                                }
                            }
                            if (ds.Tables[0].Rows[0]["admin"].ToString() == "1")
                            {
                                oAD.JoinGroup(strID, strGroupAdmin, 0);
                            }
                        }
                        if (ds.Tables[0].Rows[0]["remote"].ToString() == "1" && bool2000 == false)
                        {
                            oAD.JoinGroup(strID, strGroupRemote, 0);
                        }
                    }
                    oWorkstation.UpdateAccount(intAccount);
                }
            }
            strHidden = Request.Form[hdnDeny.UniqueID];
            while (strHidden != "")
            {
                string strField = strHidden.Substring(0, strHidden.IndexOf("&"));
                strHidden = strHidden.Substring(strHidden.IndexOf("&") + 1);
                string strFlag = strField.Substring(strField.IndexOf("_") + 1);
                strField = strField.Substring(0, strField.IndexOf("_"));
                if (strFlag == "1")
                {
                    int intAccount = Int32.Parse(strField);
                    oWorkstation.UpdateAccount(intAccount);
                }
            }
        }
Esempio n. 5
0
        private void ServiceTick()
        {
            try
            {
                string  strServer = Environment.MachineName;
                DataSet ds        = oWorkstation.GetRemoteVirtuals(strServer);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    intID          = Int32.Parse(dr["id"].ToString());
                    int    intEnvironment = Int32.Parse(dr["environment"].ToString());
                    string strINI         = @"\\citrixfile.ntl-city.com\flexcfg$\vwcfg\VW.INI";
                    if (intEnvironment != 4)
                    {
                        strINI = @"\\citrixfiletest.tstctr.ntl-city.net\flexcfg$\vwcfg\VW.INI";
                    }
                    string strImageScan = @"\\citrixfile.ntl-city.com\flexcfg$\vwcfg\BuildScripts\VWH_IMAGESCAN_SECURITY.vbs";
                    if (intEnvironment != 4)
                    {
                        strImageScan = @"\\citrixfiletest.tstctr.ntl-city.net\flexcfg$\vwcfg\BuildScripts\VWH_IMAGESCAN_SECURITY.vbs";
                    }
                    AD     oAD              = new AD(0, "", intEnvironment);
                    int    intAnswer        = Int32.Parse(dr["answerid"].ToString());
                    string strHost          = dr["hostname"].ToString();
                    string strVirtualDir    = dr["virtualdir"].ToString();
                    string strZipPath       = dr["gzippath"].ToString();
                    string strImage         = dr["image"].ToString();
                    string strName          = dr["name"].ToString();
                    string strSerial        = dr["serial"].ToString();
                    int    intStep          = Int32.Parse(dr["step"].ToString());
                    int    intRam           = Int32.Parse(dr["ram"].ToString());
                    string strManager       = dr["manager"].ToString();
                    string strGroupRemote   = "GSGu_WKS" + strName + "RemoteA";
                    string strGroupRemote2K = "GSGu_WKS" + strName + "Remote2K";
                    string strGroupAdmin    = "GSGu_WKS" + strName + "Adm";
                    string strGroupW        = "GSGw_" + strName;
                    string strResult        = "";
                    string strVBS           = strScripts + "scripts\\" + intID + ".vbs";
                    string strVBSImageScan  = strScripts + "scripts\\" + intID + "_imagescan.vbs";
                    bool   bool2000         = (strName.ToUpper().StartsWith("T2K") == true || strName.ToUpper().StartsWith("W2K") == true);
                    if (intStep > 0)
                    {
                        Type   typeVSClass           = typeof(VMVirtualServerClass);
                        Type   typeDCOM              = Type.GetTypeFromCLSID(typeVSClass.GUID, strHost, true);
                        object objDCOM               = Activator.CreateInstance(typeDCOM);
                        VMVirtualServerClass oServer = (VMVirtualServerClass)System.Runtime.InteropServices.Marshal.CreateWrapperOfType(objDCOM, typeVSClass);
                        switch (intStep)
                        {
                        case -1:
                            // Rebuild Workstation
                            if (intLogging > 0)
                            {
                                oLog.WriteEntry(String.Format("Starting rebuild of workstation " + strName), EventLogEntryType.Information);
                            }
                            VMVirtualMachine oMachineDown = oServer.FindVirtualMachine(strName);
                            if (oMachineDown.State != VMVMState.vmVMState_TurningOff && oMachineDown.State != VMVMState.vmVMState_TurnedOff)
                            {
                                oMachineDown.TurnOff();
                            }
                            if (oMachineDown.State == VMVMState.vmVMState_TurnedOff)
                            {
                                string strDirectory = strVirtualDir + "\\" + strName;
                                Directory.Delete(strDirectory);
                                oWorkstation.NextRemoteVirtual(intID);
                                oWorkstation.NextRemoteVirtual(intID);
                                oWorkstation.NextRemoteVirtual(intID);
                                oWorkstation.NextRemoteVirtual(intID);
                            }
                            break;

                        case 1:         // Step 1 - Selecting Host
                            // Should be taken care of when adding remote workstation
                            break;

                        case 2:         // Step 2 - Configuring Accounts
                            // User intervention required
                            break;

                        case 3:         // Step 3 - Initiating Build
                            if (Directory.Exists(strVirtualDir + "\\" + strName) == false)
                            {
                                Directory.CreateDirectory(strVirtualDir + "\\" + strName);
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 4:         // Step 4 - Building VHD
                            if (strZipPath == "")
                            {
                                Zip oZip = new Zip();
                                oZip.ExtractZipFile(strImage, strVirtualDir + "\\" + strName);
                                oWorkstation.NextRemoteVirtual(intID);
                            }
                            else
                            {
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format("Starting step to create VHD for " + strName), EventLogEntryType.Information);
                                }
                                string strDirectory = strVirtualDir + "\\" + strName + "\\";
                                string strFile      = strDirectory + "DriveCXP.vhd";
                                if (bool2000 == true)
                                {
                                    strFile = strDirectory + "DriveC2K.vhd";
                                }
                                string strRename = strDirectory + "DriveCXP.rename";
                                if (bool2000 == true)
                                {
                                    strRename = strDirectory + "DriveC2K.rename";
                                }
                                if (Process.GetProcessesByName("gzip").GetLength(0) == 0)
                                {
                                    // GZIP not running - check to see if we have already extracted this file
                                    if (File.Exists(strFile))
                                    {
                                        // File exists - let's move on
                                        oWorkstation.NextRemoteVirtual(intID);
                                    }
                                    else
                                    {
                                        // Add code to only run if between 9PM and 6AM
                                        if (boolProduction == false || DateTime.Now.Hour >= 21 || DateTime.Now.Hour <= 6)
                                        {
                                            if (intLogging > 0)
                                            {
                                                oLog.WriteEntry(String.Format("Beginning extraction of VHD for " + strName), EventLogEntryType.Information);
                                            }
                                            // File does not exist, begin unzip
                                            StreamWriter oWriter = new StreamWriter(strVBS);
                                            oWriter.WriteLine("Dim objShell");
                                            oWriter.WriteLine("Set objShell = CreateObject(\"WScript.Shell\")");
                                            // FORMAT: objShell.Run("cmd.exe /c F:\WXP_SysPrep\gzip -d -k -c ""F:\WXP_SysPrep\WXP Pro SP2 CORPTEST.vhd.gz"" > R:\vsfiles\LUN01\WXP\TESTHEALY\DriveCXP.vhd")
                                            oWriter.WriteLine("objShell.Run(\"cmd.exe /c " + strZipPath + " -d -k -c \"\"" + strImage + "\"\" > " + strFile + "\")");
                                            oWriter.WriteLine("Set objShell = Nothing");
                                            oWriter.Flush();
                                            oWriter.Close();
                                            ILaunchScript oScript = new SimpleLaunchWsh(strVBS, "", true) as ILaunchScript;
                                            oScript.Launch();
                                            if (intLogging > 0)
                                            {
                                                oLog.WriteEntry(String.Format("FINISHED extraction of VHD for " + strName), EventLogEntryType.Information);
                                            }
                                        }
                                        else if (intLogging > 0)
                                        {
                                            oLog.WriteEntry(String.Format("Waiting until 9PM to start extraction of VHD for " + strName), EventLogEntryType.Information);
                                        }
                                    }
                                }
                                else if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format("GZIP already running - will not create VHD for " + strName), EventLogEntryType.Information);
                                }
                            }
                            break;

                        case 5:         // Step 5 - Creating Virtual Machine
                            oServer.CreateVirtualMachine(strName, strVirtualDir + "\\" + strName);
                            oWorkstation.NextRemoteVirtual(intID);
                            //    break;
                            //case 6:   // Step 6 - Modifying RAM
                            VMVirtualMachine oMachine = oServer.FindVirtualMachine(strName);
                            oMachine.Memory = intRam;
                            oMachine.ShutdownActionOnQuit = VMShutdownAction.vmShutdownAction_Shutdown;
                            oWorkstation.NextRemoteVirtual(intID);
                            //    break;
                            //case 7:   // Step 7 - Adding CD Drive
                            oMachine.AddDVDROMDrive(VMDriveBusType.vmDriveBusType_IDE, 1, 0);
                            oWorkstation.NextRemoteVirtual(intID);
                            //    break;
                            //case 8:   // Step 8 - Connecting Virtual Disks
                            VMSCSIController oSCSI = oMachine.AddSCSIController();
                            oSCSI.Configure(false, 7);
                            if (bool2000 == true)
                            {
                                oMachine.AddHardDiskConnection(strVirtualDir + "\\" + strName + "\\DriveC2K.vhd", VMDriveBusType.vmDriveBusType_SCSI, 0, 0);
                            }
                            else
                            {
                                oMachine.AddHardDiskConnection(strVirtualDir + "\\" + strName + "\\DriveCXP.vhd", VMDriveBusType.vmDriveBusType_SCSI, 0, 0);
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 9:         // Step 9 - Configuring Network
                            VMVirtualMachine oMachineNetwork = oServer.FindVirtualMachine(strName);
                            foreach (VMNetworkAdapter oAdap in oMachineNetwork.NetworkAdapters)
                            {
                                foreach (VMVirtualNetwork oNet in oServer.VirtualNetworks)
                                {
                                    if (oNet.Name.ToUpper() == strNetwork.ToUpper())
                                    {
                                        oAdap.AttachToVirtualNetwork(oNet);
                                    }
                                }
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 10:        // Step 10 - Updating Serial Number
                            VMVirtualMachine oMachineSerial = oServer.FindVirtualMachine(strName);
                            oMachineSerial.BaseBoardSerialNumber = strSerial;
                            oMachineSerial.ChassisSerialNumber   = strSerial;
                            oMachineSerial.BIOSSerialNumber      = strSerial;
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 11:        // Step 11 - Creating AD groups
                            // Create RemoteA group in OUg_Resources/OUc_WksMgmt (not for Windows 2000 workstations)
                            if (bool2000 == false)
                            {
                                strResult = oAD.CreateGroup(strGroupRemote, "Remote access group for virtual workstation", "Requires approval from one of the following:" + Environment.NewLine + "               " + strManager, "OU=OUc_WksMgmt,OU=OUg_Resources,", "GG", "S");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            else
                            {
                                strResult = oAD.CreateGroup(strGroupRemote2K, "Remote access group for virtual workstation", "Requires approval from one of the following:" + Environment.NewLine + "               " + strManager, "OU=OUc_WksMgmt,OU=OUg_Resources,", "GG", "S");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            if (intEnvironment != (int)CurrentEnvironment.CORPDMN && intEnvironment != (int)CurrentEnvironment.PNCNT_PROD)     // Not Production
                            {
                                // Create Adm group in OUc_Orgs/OUg_Admins
                                strResult = oAD.CreateGroup(strGroupAdmin, "Virtual Workstation; " + strManager, "", "OU=OUg_Admins,OU=OUc_Orgs,", "GG", "S");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                                // Create GSGw group in OUg_Resources
                                strResult = oAD.CreateGroup(strGroupW, "Virtual Workstation; " + strManager, "", "OU=OUg_Resources,", "GG", "S");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                                // Create Workstation Object in OUc_DmnCptrs/OUc_Wksts/OUw_Standard
                                strResult = oAD.CreateWorkstation(strName, "Virtual Workstation; " + strManager, "", "OU=OUw_Standard,OU=OUc_Wksts,OU=OUc_DmnCptrs,");
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                                // Add workstation to GSGw group
                                strResult = oAD.JoinGroup(strName, strGroupW, 0);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 12:
                            // Step 12 - Adding AD accounts
                            DataSet dsAccounts = oWorkstation.GetRemoteAccounts(strName);
                            foreach (DataRow drAccount in dsAccounts.Tables[0].Rows)
                            {
                                string strID = drAccount["xid"].ToString();
                                if (intEnvironment != (int)CurrentEnvironment.CORPDMN && intEnvironment != (int)CurrentEnvironment.PNCNT_PROD)     // Not Production
                                {
                                    strID = "E" + strID.Substring(1);
                                    if (oAD.Search(strID, false) == null)
                                    {
                                        strID = "T" + strID.Substring(1);
                                        if (oAD.Search(strID, false) == null)
                                        {
                                            strResult = oAD.CreateUser(strID, strID, strID, "Abcd1234", "", "", "");
                                            if (strResult.Trim() != "")
                                            {
                                                oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                            }
                                            if (intLogging > 0)
                                            {
                                                oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                            }
                                        }
                                    }
                                    if (drAccount["admin"].ToString() == "1")
                                    {
                                        strResult = oAD.JoinGroup(strID, strGroupAdmin, 0);
                                        if (strResult.Trim() != "")
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                        }
                                        if (intLogging > 0)
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                        }
                                    }
                                }
                                if (drAccount["remote"].ToString() == "1")
                                {
                                    if (bool2000 == false)
                                    {
                                        strResult = oAD.JoinGroup(strID, strGroupRemote, 0);
                                        if (strResult.Trim() != "")
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                        }
                                        if (intLogging > 0)
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                        }
                                    }
                                    else
                                    {
                                        strResult = oAD.JoinGroup(strID, strGroupRemote2K, 0);
                                        if (strResult.Trim() != "")
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                        }
                                        if (intLogging > 0)
                                        {
                                            oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                        }
                                    }
                                }
                            }
                            oWorkstation.NextRemoteVirtual(intID);
                            break;

                        case 13:
                            // Step 13 - Starting Machine
                            VMVirtualMachine oMachineStart = oServer.FindVirtualMachine(strName);
                            oMachineStart.Startup();
                            oWorkstation.NextRemoteVirtual(intID);
                            // Update INI File
                            DataSet dsINI = oWorkstation.GetRemoteAccounts(strName);
                            foreach (DataRow drINI in dsINI.Tables[0].Rows)
                            {
                                string strID = drINI["xid"].ToString();
                                if (intEnvironment != (int)CurrentEnvironment.CORPDMN && intEnvironment != (int)CurrentEnvironment.PNCNT_PROD)     // Not Production
                                {
                                    strID = "E" + strID.Substring(1);
                                    if (oAD.Search(strID, false) == null)
                                    {
                                        strID = "T" + strID.Substring(1);
                                    }
                                }
                                if (drINI["remote"].ToString() == "1")
                                {
                                    // FORMAT: EMJY13C=TXPVM001,XP,OHCLEVWH4004
                                    bool         boolAdd = true;
                                    string       strLine = strID + "=" + strName + "," + (bool2000 ? "2000" : "XP") + "," + strHost;
                                    StreamReader oINIr   = new StreamReader(strINI);
                                    while (oINIr.Peek() != -1)
                                    {
                                        string strCompare = oINIr.ReadLine();
                                        if (strCompare == strLine)
                                        {
                                            boolAdd = false;
                                            break;
                                        }
                                    }
                                    oINIr.Close();
                                    if (boolAdd == true)
                                    {
                                        StreamWriter oINI = new StreamWriter(strINI, true);
                                        oINI.WriteLine(strLine);
                                        oINI.Flush();
                                        oINI.Close();
                                    }
                                }
                            }
                            break;

                        case 14:
                            // Step 14 - ZEUS
                            break;

                        case 15:
                            // Step 15 - Installing Applications
                            break;

                        case 16:
                            // Step 16 - Complete Request
                            // Run ImageScan script
                            File.Copy(strImageScan, strVBSImageScan, true);
                            ILaunchScript oScriptImageScan = new SimpleLaunchWsh(strVBSImageScan, "", true) as ILaunchScript;
                            oScriptImageScan.Launch();
                            // Delete Files
                            if (File.Exists(strVBS) == true)
                            {
                                File.Delete(strVBS);
                            }
                            if (File.Exists(strVBSImageScan) == true)
                            {
                                File.Delete(strVBSImageScan);
                            }
                            // Reboot the workstation
                            VMVirtualMachine oMachineRestart = oServer.FindVirtualMachine(strName);
                            oMachineRestart.Reset();
                            oWorkstation.UpdateRemoteVirtualCompleted(intID);
                            break;
                        }
                    }
                }


                ds = oWorkstation.GetRemoteVirtualDecoms(strServer);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int    intID          = Int32.Parse(dr["id"].ToString());
                    int    intEnvironment = Int32.Parse(dr["environment"].ToString());
                    string strINI         = @"\\citrixfile.ntl-city.com\flexcfg$\vwcfg\VW.INI";
                    if (intEnvironment != 4)
                    {
                        strINI = @"\\citrixfiletest.tstctr.ntl-city.net\flexcfg$\vwcfg\VW.INI";
                    }
                    string strINITemp = @"\\citrixfile.ntl-city.com\flexcfg$\vwcfg\VW_TEMP.INI";
                    if (intEnvironment != 4)
                    {
                        strINITemp = @"\\citrixfiletest.tstctr.ntl-city.net\flexcfg$\vwcfg\VW_TEMP.INI";
                    }
                    AD     oAD                    = new AD(0, "", intEnvironment);
                    string strVirtualDir          = dr["virtualdir"].ToString();
                    string strName                = dr["name"].ToString();
                    string strGroupRemote         = "GSGu_WKS" + strName + "RemoteA";
                    string strGroupRemote2K       = "GSGu_WKS" + strName + "Remote2K";
                    string strGroupAdmin          = "GSGu_WKS" + strName + "Adm";
                    string strGroupW              = "GSGw_" + strName;
                    string strResult              = "";
                    bool   bool2000               = (strName.ToUpper().StartsWith("T2K") == true || strName.ToUpper().StartsWith("W2K") == true);
                    Type   typeVSClass            = typeof(VMVirtualServerClass);
                    Type   typeDCOM               = Type.GetTypeFromCLSID(typeVSClass.GUID, strServer, true);
                    object objDCOM                = Activator.CreateInstance(typeDCOM);
                    VMVirtualServerClass oServer  = (VMVirtualServerClass)System.Runtime.InteropServices.Marshal.CreateWrapperOfType(objDCOM, typeVSClass);
                    VMVirtualMachine     oMachine = oServer.FindVirtualMachine(strName);
                    if (oMachine.State == VMVMState.vmVMState_TurnedOff)
                    {
                        // Remove Workstation
                        oServer.DeleteVirtualMachine(oMachine);
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("Workstation " + strName + " has been deleted", EventLogEntryType.Information);
                        }
                        // Delete Folder
                        DeleteDirectory(strVirtualDir + "\\" + strName);
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The directory for workstation " + strName + " has been deleted", EventLogEntryType.Information);
                        }
                        // Delete AD Objects
                        DirectoryEntry oGroup;
                        if (bool2000 == false)
                        {
                            oGroup = oAD.GroupSearch(strGroupRemote);
                            if (oGroup != null)
                            {
                                strResult = oAD.Delete(oGroup);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                        }
                        else
                        {
                            oGroup = oAD.GroupSearch(strGroupRemote2K);
                            if (oGroup != null)
                            {
                                strResult = oAD.Delete(oGroup);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                        }
                        if (intEnvironment != (int)CurrentEnvironment.CORPDMN && intEnvironment != (int)CurrentEnvironment.PNCNT_PROD) // Not Production
                        {
                            oGroup = oAD.GroupSearch(strGroupAdmin);
                            if (oGroup != null)
                            {
                                strResult = oAD.Delete(oGroup);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            oGroup = oAD.GroupSearch(strGroupW);
                            if (oGroup != null)
                            {
                                strResult = oAD.Delete(oGroup);
                                if (strResult.Trim() != "")
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                }
                                if (intLogging > 0)
                                {
                                    oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                }
                            }
                            SearchResultCollection oComputers = oAD.ComputerSearch(strName);
                            if (oComputers.Count > 0)
                            {
                                oGroup = oComputers[0].GetDirectoryEntry();
                                if (oGroup != null)
                                {
                                    strResult = oAD.Delete(oGroup);
                                    if (strResult.Trim() != "")
                                    {
                                        oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Warning);
                                    }
                                    if (intLogging > 0)
                                    {
                                        oLog.WriteEntry(String.Format(strResult), EventLogEntryType.Information);
                                    }
                                }
                            }
                        }
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The AD groups for workstation " + strName + " have been deleted", EventLogEntryType.Information);
                        }
                        // Update the INI File
                        string       strCompare = "=" + strName + "," + (bool2000 ? "2000" : "XP") + "," + strServer;
                        StreamWriter oINI       = new StreamWriter(strINITemp, true);
                        StreamReader oINIr      = new StreamReader(strINI);
                        while (oINIr.Peek() != -1)
                        {
                            string strLine = oINIr.ReadLine();
                            if (strLine.EndsWith(strCompare) == false)
                            {
                                oINI.WriteLine(strLine);
                            }
                        }
                        oINIr.Close();
                        oINI.Flush();
                        oINI.Close();
                        if (File.Exists(strINI) == true)
                        {
                            File.Delete(strINI);
                        }
                        File.Copy(strINITemp, strINI, true);
                        if (File.Exists(strINITemp) == true)
                        {
                            File.Delete(strINITemp);
                        }
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The INI file [" + strINI + "] was updated", EventLogEntryType.Information);
                        }
                        oWorkstation.UpdateRemoteVirtualDecomCompleted(intID);
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The workstation " + strName + " has been decommissioned", EventLogEntryType.Information);
                        }
                    }
                    else if (oMachine.State != VMVMState.vmVMState_TurningOff)
                    {
                        oMachine.TurnOff();
                        if (intLogging > 0)
                        {
                            oLog.WriteEntry("The workstation " + strName + " is turning off", EventLogEntryType.Information);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                oLog.WriteEntry(String.Format(ex.Message) + " [" + System.Environment.UserName + "]", EventLogEntryType.Error);
            }
        }