protected void btnSave_Click(Object Sender, EventArgs e) { int intResourceWorkflow = Int32.Parse(lblResourceWorkflow.Text); int intResourceParent = oResourceRequest.GetWorkflowParent(intResourceWorkflow); oResourceRequest.UpdateWorkflowName(intResourceWorkflow, txtCustom.Text, intProfile); ds = oResourceRequest.Get(intResourceParent); int intRequest = Int32.Parse(ds.Tables[0].Rows[0]["requestid"].ToString()); int intItem = Int32.Parse(ds.Tables[0].Rows[0]["itemid"].ToString()); int intStatus = Int32.Parse(oResourceRequest.GetWorkflow(intResourceWorkflow, "status")); double dblHours = double.Parse(lblUsed.Text); double dblTime = 5.00 / 60.00; foreach (RepeaterItem ri in rptView.Items) { CheckBox chkDelete = (CheckBox)ri.FindControl("chkDelete"); if (chkDelete.Checked == true) { Label lblId = (Label)ri.FindControl("lblId"); Label lblPath = (Label)ri.FindControl("lblPath"); Label lblEnvironment = (Label)ri.FindControl("lblEnvironment"); Variables oVariable = new Variables(Int32.Parse(lblEnvironment.Text)); DirectoryEntry oEntry = new DirectoryEntry(lblPath.Text, oVariable.Domain() + "\\" + oVariable.ADUser(), oVariable.ADPassword()); AD oAD = new AD(intProfile, dsn, Int32.Parse(lblEnvironment.Text)); if (oAD.Exists(oEntry)) { oAD.Enable(oEntry, false); } dblHours += dblTime; oADObject.UpdateDomainAccount(Int32.Parse(lblId.Text), intProfile); } } // Delete objects over a month old ds = oADObject.GetDomainAccountsDisabled(DateTime.Today.AddMonths(-1)); foreach (DataRow dr in ds.Tables[0].Rows) { int _environment = Int32.Parse(dr["environment"].ToString()); Variables oVariable = new Variables(_environment); DirectoryEntry oEntry = new DirectoryEntry(dr["path"].ToString(), oVariable.Domain() + "\\" + oVariable.ADUser(), oVariable.ADPassword()); AD oAD = new AD(intProfile, dsn, _environment); if (oAD.Exists(oEntry) && oAD.IsDisabled(oEntry) == true) { oAD.Delete(oEntry); oADObject.UpdateDomainAccountDisabled(Int32.Parse(dr["adid"].ToString()), -1); } else { oADObject.UpdateDomainAccountDisabled(Int32.Parse(dr["adid"].ToString()), -10); } } double dblTotal = double.Parse(oResourceRequest.GetWorkflow(intResourceWorkflow, "allocated")); double dblUsed = oResourceRequest.GetWorkflowUsed(intResourceWorkflow); dblHours = (dblHours - dblUsed); if (dblHours > 0.00) { oResourceRequest.UpdateWorkflowHours(intResourceWorkflow, dblHours); } Response.Redirect(Request.Path + "?rrid=" + intResourceWorkflow.ToString() + "&save=true"); }
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(); }
protected void btnApprove_Click(Object Sender, EventArgs e) { oResourceRequest.UpdateWorkflowHours(intResourceWorkflow); DataSet ds = oGroupRequest.GetMaintenance(intRequest, intItem, intNumber); int intUser = oRequest.GetUser(intRequest); DataSet dsParameters = oGroupRequest.GetMaintenanceParameters(intRequest, intItem, intNumber); string strMaintenance = ds.Tables[0].Rows[0]["maintenance"].ToString(); string strGroup = ds.Tables[0].Rows[0]["name"].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.GroupSearch(strGroup); if (oEntry != null) { switch (strMaintenance) { case "MOVE": // Group Move string strPath = dsParameters.Tables[0].Rows[0]["value"].ToString(); oRequest.AddResult(intRequest, intItem, intNumber, "Group Move", oAD.MoveGroup(oEntry, strPath), "Group " + strGroup + " was successfully moved", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser)); break; case "COPY": // Group Copy string strID = txtID.Text; string strScope2 = dsParameters.Tables[0].Rows[1]["value"].ToString(); if (strScope2 == "Domain Local") { strScope2 = "DLG"; } if (strScope2 == "Global") { strScope2 = "GG"; } if (strScope2 == "Universal") { strScope2 = "UG"; } string strType2 = dsParameters.Tables[0].Rows[2]["value"].ToString(); if (strType2 == "Security") { strType2 = "S"; } if (strType2 == "Distribution") { strType2 = "D"; } oRequest.AddResult(intRequest, intItem, intNumber, "Group Copy", oAD.CreateGroup(strID, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.GroupOU(), strScope2, strType2), "Group " + strGroup + " was successfully copied", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser)); foreach (ListItem oList in chkUsers.Items) { if (oList.Selected == true) { oRequest.AddResult(intRequest, intItem, intNumber, "Group Membership", oAD.JoinGroup(oList.Value, strID, 0), "Account " + oList.Value + " was successfully added to the group " + strGroup, intEnvironment, (oService.Get(intService, "notify_client") == "1"), ""); } } break; case "DELETE": // Group Deletion oRequest.AddResult(intRequest, intItem, intNumber, "Group Deletion", oAD.Delete(oEntry), "Group " + strGroup + " was successfully deleted", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser)); break; case "RENAME": // Group Rename string strI = txtID.Text; oRequest.AddResult(intRequest, intItem, intNumber, "Group Rename", oAD.Rename(oEntry, strI, "", ""), "Group " + strGroup + " was successfully renamed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser)); break; case "CHANGE": // Group Change string strScope3 = dsParameters.Tables[0].Rows[0]["value"].ToString(); if (strScope3 == "Domain Local") { strScope3 = "DLG"; } if (strScope3 == "Global") { strScope3 = "GG"; } if (strScope3 == "Universal") { strScope3 = "UG"; } string strType3 = dsParameters.Tables[0].Rows[1]["value"].ToString(); if (strType3 == "Security") { strType3 = "S"; } if (strType3 == "Distribution") { strType3 = "D"; } oRequest.AddResult(intRequest, intItem, intNumber, "Group Change", oAD.Change(oEntry, strScope3, strType3), "Group " + strGroup + " was successfully changed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser)); break; } } else if (strMaintenance == "CREATE") { // Group Creation string strScope1 = dsParameters.Tables[0].Rows[0]["value"].ToString(); if (strScope1 == "Domain Local") { strScope1 = "DLG"; } if (strScope1 == "Global") { strScope1 = "GG"; } if (strScope1 == "Universal") { strScope1 = "UG"; } string strType1 = dsParameters.Tables[0].Rows[1]["value"].ToString(); if (strType1 == "Security") { strType1 = "S"; } if (strType1 == "Distribution") { strType1 = "D"; } oRequest.AddResult(intRequest, intItem, intNumber, "Group Creation", oAD.CreateGroup(txtID.Text, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.GroupOU(), strScope1, strType1), "Group " + strGroup + " was successfully created", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser)); } oGroupRequest.UpdateMaintenance(intRequest, intItem, intNumber, 1, txtComments.Text); Complete(); }
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); } }