Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
T

turbosupramk3

@turbosupramk3
About
Posts
446
Topics
103
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How can I enumerate through OU's for nodes and add them to an existing treeview root node?
    T turbosupramk3

    Hello, I am populating the root nodes of the treenode1 via the formload() function, I guess you could say they are hard coded. After that I want to select a root node (which will be a domain) and enumerate the OUs of that domain and then make the outputted (via the code below) sub nodes of the root node (domain) that is already listed. The function below makes the output, root nodes under the formload() created root nodes instead of subnodes under the formload() created root nodes, how can I make them subnodes of the original formload() root nodes? Sorry if this is written in a confusing manner, I've tried to reread it and make it less confusing amidst my own confusion.

        private void searchForOus(string ouPath)
        {
    
            DirectoryEntry ADentry = new DirectoryEntry(ouPath, @"domain\\user", "password", AuthenticationTypes.Secure);
    
            DirectorySearcher Searcher = new DirectorySearcher(ADentry);
            Searcher.Filter = ("(objectClass=organizationalUnit)");
            foreach (DirectoryEntry entry in Searcher.SearchRoot.Children)
            {
                Console.WriteLine(entry.Path);
    
    
                if (entry.Path == "LDAP://OU=Core Member Servers,dc=XXX,dc=XXX,dc=XX,dc=XXX")
    
                {
                    if (ShouldAddNode(entry.SchemaClassName))
                    {
                        treeView1.Nodes.Add(GetChildNode(entry));
    
                    }
                }
            }
    
        private TreeNode GetChildNode(DirectoryEntry entry)
        {
            TreeNode node = new TreeNode(entry.Name.Substring(entry.Name.IndexOf('=') + 1));
    
            foreach (DirectoryEntry childEntry in entry.Children)
            {
                if (ShouldAddNode(childEntry.SchemaClassName))
                {
                    node.Nodes.Add(GetChildNode(childEntry));
    
                }
            }
    
    
    
    
            return node;
        }
    
        private bool ShouldAddNode(string schemaClass)
        {
            bool returnValue = false;
    
            if (schemaClass == "organizationalUnit")
            {
                returnValue = true;
            }
    
            return returnValue;
        }
    
    C# question css asp-net

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    I don't know why, but the addition of the thread sleep as pictured below fixed it?

                tbxXCoordinates.Text = "";
                tbxYCoordinates.Text = "";
                
                Thread.Sleep(250);
                SetWindowPos(this.Handle, HWND\_NOTOPMOST, 0, 0, 0, 0, NOTOPMOST\_FLAGS);
    
    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    Ok, thank you for trying!

    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    Sure thing, the first block is my Pininvoke code, then the standard function and then the test button. The standard function code will put the form to topmost, but will not remove the topmost flag. The test button will remove the topmost flag after the standard function places the topmost flag.

    private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
    private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
    private static readonly IntPtr HWND_TOP = new IntPtr(0);

        private const UInt32 SWP\_NOSIZE = 0x0001;
        private const UInt32 SWP\_NOMOVE = 0x0002;
        private const UInt32 SWP\_NOZORDER = 0x0004;
        private const UInt32 SWP\_NOREDRAW = 0x0008;
        private const UInt32 SWP\_NOACTIVATE = 0x0010;
        private const UInt32 SWP\_DRAWFRAME = 0x0020;
        private const UInt32 SWP\_FRAMECHANGED = 0x0020;
        private const UInt32 SWP\_SHOWWINDOW = 0x0040;
        private const UInt32 SWP\_HIDEWINDOW = 0x0080;
        private const UInt32 SWP\_NOCOPYBITS = 0x0100;
        private const UInt32 SWP\_NOOWNERZORDER = 0x0200;
        private const UInt32 SWP\_NOREPOSITION = 0x0200;
        private const UInt32 SWP\_NOSENDCHANGING = 0x0400;
        private const UInt32 SWP\_DEFERERASE = 0x2000;
        private const UInt32 SWP\_ASYNCWINDOWPOS = 0x4000;
    
        private const UInt32 TOPMOST\_FLAGS = SWP\_NOMOVE | SWP\_NOSIZE;
        private const UInt32 NOTOPMOST\_FLAGS = TOPMOST\_FLAGS | SWP\_SHOWWINDOW;
    
        \[DllImport("user32.dll")\]
        \[return: MarshalAs(UnmanagedType.Bool)\]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
        private void btnType\_Click(object sender, EventArgs e)
        {
            try
            {
                if (tbxTagList.Text == "")
                {
                    MessageBox.Show("Please enter in at least 1 tag");
                    return;
                }
    
                int x = Convert.ToInt32(tbxXCoordinates.Text);
                int y = Convert.ToInt32(tbxYCoordinates.Text);
                SimulateMouseClick(x, y);
                foreach (char character in tbxTagList.Text)
                {
    
                    if ((character != '\\n') && (character != '\\r'))
                    {
                        SendKeys.Send(character.ToString());
                    }
    
                    if (character == '\\n')
                    {
                        SendKeys.Send("{Enter}
    
    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    Thank you. Strangely enough when I have the above code in a separate button it removes the topmost flag correctly, but when I have it at the end of the send.keys function it does not remove the topmost flag? Any ideas on what could be causing that?

    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    It did not remove the topmost flag as the application is still set to topmost. I would like it to go from a topmost application back to a standard z ordered application as it is before the topmost flag is set. I was testing it with a test button for simplification is all, as soon as I get a working example I will then incorporate it into an else block

    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    Hi Luc, Here is what I tried, but it did not work for me

    private void btnTest_Click(object sender, EventArgs e)
    {
    SetWindowPos(this.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
    }

    And here is my pininvoke code

    private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
    private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
    private static readonly IntPtr HWND_TOP = new IntPtr(0);

        private const UInt32 SWP\_NOSIZE = 0x0001;
        private const UInt32 SWP\_NOMOVE = 0x0002;
        private const UInt32 SWP\_NOZORDER = 0x0004;
        private const UInt32 SWP\_NOREDRAW = 0x0008;
        private const UInt32 SWP\_NOACTIVATE = 0x0010;
        private const UInt32 SWP\_DRAWFRAME = 0x0020;
        private const UInt32 SWP\_FRAMECHANGED = 0x0020;
        private const UInt32 SWP\_SHOWWINDOW = 0x0040;
        private const UInt32 SWP\_HIDEWINDOW = 0x0080;
        private const UInt32 SWP\_NOCOPYBITS = 0x0100;
        private const UInt32 SWP\_NOOWNERZORDER = 0x0200;
        private const UInt32 SWP\_NOREPOSITION = 0x0200;
        private const UInt32 SWP\_NOSENDCHANGING = 0x0400;
        private const UInt32 SWP\_DEFERERASE = 0x2000;
        private const UInt32 SWP\_ASYNCWINDOWPOS = 0x4000;
    
        private const UInt32 TOPMOST\_FLAGS = SWP\_NOMOVE | SWP\_NOSIZE;
        private const UInt32 NOTOPMOST\_FLAGS = SWP\_SHOWWINDOW;
    
        \[DllImport("user32.dll")\]
        \[return: MarshalAs(UnmanagedType.Bool)\]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    Here is the button click function, would you like me to copy/paste the entire code?

    private void btnSelectTypingBox_Click(object sender, EventArgs e)
    {
    try
    {
    if (tempBlocker == false)
    {
    ////MessageBox.Show("1");
    if (btnSelectTypingBox.Text == "Select Box")
    {
    btnSelectTypingBox.Text = "Waiting";
    tempBlocker = false;
    SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); // set window foreground to top most window
    }
    else if (btnSelectTypingBox.Text == "Waiting")
    {
    btnSelectTypingBox.Text = "Select Box";

                    }
                }         
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " | " + ex.Source + " | " + ex.InnerException + " | " + ex.StackTrace);
            }
        }
    
    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    Sure, I am having the program go to top most after a button click and then selecting coordinates on the screen with the mouse and clicking another button to send keys to those coordinates and then after it is done I'd like for it to go back to standard Z order, but it is staying at top most.

    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    Hi, I've tried multiple variations of what I think is correct and it is not working. Here is an example of what I thought was correct

    SetWindowPos(this.Handle, HWND_TOP, 120, 240, 200, 400, 0);

    Can you tell me what I'm doing wrong? When using the above code, the window is still at the top most, even when I click on another window to bring it to the foreground.

    C# question help

  • Problem with setwindowPOS and returning from topmost to standard window position?
    T turbosupramk3

    I'm using the code below to temporarily set a window to top most foreground. How can I return it to the standard function of being in the foreground depending on the last time it was touched by the mouse? I can't seem to figure out which uint32 to use to achieve what I'd like?

    private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
    private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);

        private const UInt32 SWP\_NOSIZE = 0x0001;
        private const UInt32 SWP\_NOMOVE = 0x0002;
        private const UInt32 SWP\_NOZORDER = 0x0004;
        private const UInt32 SWP\_NOREDRAW = 0x0008;
        private const UInt32 SWP\_NOACTIVATE = 0x0010;
        private const UInt32 SWP\_DRAWFRAME = 0x0020;
        private const UInt32 SWP\_FRAMECHANGED = 0x0020;
        private const UInt32 SWP\_SHOWWINDOW = 0x0040;
        private const UInt32 SWP\_HIDEWINDOW = 0x0080;
        private const UInt32 SWP\_NOCOPYBITS = 0x0100;
        private const UInt32 SWP\_NOOWNERZORDER = 0x0200;
        private const UInt32 SWP\_NOREPOSITION = 0x0200;
        private const UInt32 SWP\_NOSENDCHANGING = 0x0400;
        private const UInt32 SWP\_DEFERERASE = 0x2000;
        private const UInt32 SWP\_ASYNCWINDOWPOS = 0x4000;
    
        private const UInt32 TOPMOST\_FLAGS = SWP\_NOMOVE | SWP\_NOSIZE;
        private const UInt32 NOTOPMOST\_FLAGS = SWP\_SHOWWINDOW;
    
        \[DllImport("user32.dll")\]
        \[return: MarshalAs(UnmanagedType.Bool)\]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    

    SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);

    Thanks!

    C# question help

  • How to index dynamically created controls and their values?
    T turbosupramk3

    I have dynamically created controls that I want to use to create and write an output file with. How can I organize the controls values based on their name?

    private TextBox txtBox1 = new TextBox();
    private ComboBox cmbx1 = new ComboBox();
    private TextBox txtBox2 = new TextBox();
    private TextBox txtBox3 = new TextBox();
    private Button btn1 = new Button();
    int configLineIndex = 1;
    private void btnCuRepairConfigAddLine_Click(object sender, EventArgs e)
    {
    configLineIndex++;
    tbxHorizontalIndex = 21;

    txtBox1 = new TextBox();
    txtBox1.Name = "line" + configLineIndex + "a";
    int tbxWidth = 285;
    this.txtBox1.Location = new System.Drawing.Point(tbxHorizontalIndex, tbxVerticalIndex + 30);
    this.txtBox1.Size = new System.Drawing.Size(tbxWidth, 20);
    this.Controls.Add(txtBox1);
    
    cmbx1 = new ComboBox();
    cmbx1.Name = "line" + configLineIndex + "b";
    this.cmbx1.Location = new Point(tbxHorizontalIndex + 299, tbxVerticalIndex + 30);
    this.cmbx1.Size = new Size(121, 21);
    this.cmbx1.Items.Add("addAfter");
    this.cmbx1.Items.Add("addBefore");
    this.cmbx1.Items.Add("Replace");
    this.Controls.Add(cmbx1);
    
    txtBox2 = new TextBox();
    txtBox2.Name = "line" + configLineIndex + "c";
    tbxWidth = 320;
    this.txtBox2.Location = new System.Drawing.Point(tbxHorizontalIndex + 435, tbxVerticalIndex + 30);
    this.txtBox2.Size = new System.Drawing.Size(tbxWidth, 20);
    this.Controls.Add(txtBox2);
    
    txtBox3 = new TextBox();
    txtBox3.Name = "line" + configLineIndex + "d";
    tbxWidth = 320;
    this.txtBox3.Location = new System.Drawing.Point(tbxHorizontalIndex + 770, tbxVerticalIndex + 30);
    this.txtBox3.Size = new System.Drawing.Size(tbxWidth, 20);
    this.Controls.Add(txtBox3);
    
    btn1 = new Button();
    btn1.Name = "line" + configLineIndex + "e";
    this.btn1.Location = new Point(tbxHorizontalIndex + 1110, tbxVerticalIndex + 30);
    this.btn1.Size = new Size(20, 20);
    this.btn1.Text = "X";
    this.Controls.Add(btn1);
    
    
    //tbxHorizontalIndex = tbxHorizontalIndex + tbxWidth + 10;
    tbxVerticalIndex = tbxVerticalIndex + 30;
    

    }

    C# question database graphics tutorial

  • Help with "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."
    T turbosupramk3

    Doh! Thank you, that worked!

    C# help question announcement

  • Help with "Invoke or BeginInvoke cannot be called on a control until the window handle has been created."
    T turbosupramk3

    Hi. What I'm trying to accomplish is to call this class, pass some controls and values and then have the new object update the existing control. Help with this would be appreciated? Maybe it is not possible since I cannot pass the handle value to the class? The error is a little misleading as the control is already created?

    private void btnGroupsForUserTest_Click(object sender, EventArgs e)
    {

      progressBarControl pbarcontrol = new progressBarControl();
      pbarcontrol.pbarIncrementValue = 1;
      pbarcontrol.pbarMaximum = 100;
      pbarcontrol.pbarThreadSleepIncrement = 250;
      pbarcontrol.pbarObject = pBarGroupsForUser;
      pbarcontrol.pbarLabel = lblGroupsForUserStatus;
    
      progressBarIncrementer = new Thread(new ThreadStart(pbarcontrol.pbarIncrementFunction));
      progressBarIncrementer.IsBackground = true;
      progressBarIncrementer.Start();
      }
    

    public class progressBarControl : FormGroupMemberShipCheckingTool
    {
    public ProgressBar pbarObject;// { get; set; }
    public Label pbarLabel;// { get; set; }

    public int pbarMaximum { get; set; }
    public int pbarIncrementValue { get; set; }
    public int pbarThreadSleepIncrement { get; set; }
    
    public void pbarIncrementFunction()
    {
    
        int incrementValue = pbarIncrementValue;
        do
        {
            this.Invoke((MethodInvoker)delegate()
            {
                if (incrementValue < pbarMaximum)
                {
                    pbarObject.Value = incrementValue;
                    pbarLabel.Text = incrementValue.ToString() + "% complete";
                    Application.DoEvents();
                }
            });
            incrementValue++;
            Thread.Sleep(pbarThreadSleepIncrement);
        } while (incrementValue < pbarMaximum);
    }
    

    }

    C# help question announcement

  • How can I speed up my code?
    T turbosupramk3

    I have not created a dictionary before, so do you recommend this be stored in a text file or in a database? This morning I got 323 group results in 65 seconds, I would imagine that when I try after lunch it will take 10x as long. Is it better for me to try and dictate which DC I am hitting? I can view which DC I'm hitting, so maybe my issue of sporadicness is actually a DC problem? What do you think?

    C# question com performance

  • How can I speed up my code?
    T turbosupramk3

    I am enumerating through groups recursively. There is a starting parent group, and I'm starting with the parent and enumerating through all of the child groups of that parent and every group that is a member of the child groups that are found. At my organization, there may be a nested hierarchy of 12 groups or more and unfortunately there may be some of the same groups nested in other groups as the local admin qualification is to have a pulse. Does that explain it better?

    C# question com performance

  • How can I speed up my code?
    T turbosupramk3

    My goal is to enumerate through the groups and subgroups and get all of the non duplicate groups/subgroups and put them into a list. After that I checked to see if a specific user is a member of any of the groups I've enumerated to the list of groups/subgroups.

    C# question com performance

  • How can I speed up my code?
    T turbosupramk3

    I am running this from one domain and against a different domain. The process is incredibly slow and I'm wondering how I can speed my code up so that instead of it taking 20 minutes, it will only take 1 minute. I have noticed that every once in a while it will only take 1 minute and I'm wondering if I need to point it to a specific DC in the domain I am looking through or maybe something else? getAllGroupMemberGroupsForGroup("membergroup", "domain.domain.com") private List getAllGroupMemberGroupsForGroup(string groupName, string domainName) { PrincipalContext context = new PrincipalContext(ContextType.Domain, domainName); GroupPrincipal objects = GroupPrincipal.FindByIdentity(context, groupName); List groupMembersList = new List(); PrincipalSearchResult objectMembers = null; if (objects != null) { objectMembers = objects.GetMembers(); } else { return groupMembersList; } foreach (Principal objectMember in objectMembers) { if (objectMember.StructuralObjectClass == "group") { string objectDomain = objectMember.Context.Name; groupMembersList.Add(objectMember.Name + "|" + objectDomain + "|" + objectMember.DistinguishedName); } } return groupMembersList; }

    C# question com performance

  • How can I run multiple powershell commands in a C#/powershell runspace?
    T turbosupramk3

    Here is what I ended up doing, this allows me to create a script in a string with multiple commands, it processes 1 command at a time and then creates a runspace in c# and runs all of the powershell commands

    string scriptText = @"$pw = convertto-securestring -AsPlainText -Force -String ''; $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist '\', $pw; $session = new-pssession -ConfigurationName Microsoft.Exchange -ConnectionUri '/powershell' -credential $cred; import-pssession $session; Set-ExecutionPolicy bypass -confirm:$false -force; $pic = ([System.IO.File]::ReadAllBytes('" + + "')); set-userphoto -identity -picturedata $pic -domaincontroller '' -confirm:$false;";

                runExchangeShellScript(scriptText);
    

    private string runExchangeShellScript(string scriptText)
    {

            Runspace runspace = RunspaceFactory.CreateRunspace();
    
            // open it
            runspace.Open();
    
            // create a pipeline and feed it the script text
            Pipeline pipeline = runspace.CreatePipeline();
            pipeline.Commands.AddScript(scriptText);
            RunspaceInvoke runSpaceInvoker = new RunspaceInvoke(runspace);
            runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
    
            // add an extra command to transform the script output objects into nicely formatted strings
            // remove this line to get the actual objects that the script returns. For example, the script
            // "Get-Process" returns a collection of System.Diagnostics.Process instances.
            //pipeline.Commands.Add("Out-String");
    
            // execute the script
            Collection<PSObject> results = null;
            try
            {
                results = pipeline.Invoke();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException + " - " + ex.Message + " - " + ex.Source + " - " + ex.StackTrace + " - " + ex.TargetSite + " - " + ex.Data);
                return "";
            }
    
    
            // close the runspace
            runspace.Close();
    
            // convert the script result into a single string
            StringBuilder stringBuilder = new StringBuilder();
            foreach (PSObject ob
    
    C# question csharp windows-admin tutorial

  • How can I run multiple powershell commands in a C#/powershell runspace?
    T turbosupramk3

    results = pipeline.Invoke() I need a working example of how to do this, and after that I can modify it to my own needs

    C# question csharp windows-admin tutorial
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups