Solved

How do I convert a string to a Hex?

Posted on 2006-11-21
7
709 Views
Last Modified: 2008-02-01
How do I convert the "disabled" to hex so I can & it with UF_ACCOUNTDISABLE))?  Thanks

int UF_ACCOUNTDISABLE = 0x2;
string disabled = deChild.Properties["userAccountControl"].Value.ToString();

          if ((disabled.ToString("X2")) & (UF_ACCOUNTDISABLE))
0
Comment
Question by:lapucca
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17990830
what type is the value in
deChild.Properties["userAccountControl"].Value ?
0
 

Author Comment

by:lapucca
ID: 17990923
0
 

Author Comment

by:lapucca
ID: 17990939
I'm trying to determin if the account is disabled.  Would that make the end result 1 or 0?  Thanks.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:lapucca
ID: 17991023
Following the example on http://msdn2.microsoft.com/en-us/library/ms180916.aspx

My following code is getting me an error.  How can I correct this?  Thanks.

Error      2      Cannot implicitly convert type 'int' to 'bool'      C:\Projects\UnityAdmin\Main.cs      821


int disabled = (int)deChild.Properties["userAccountControl"].Value;
if ((disabled) & (UF_ACCOUNTDISABLE))//if disable then use the disabled icon
    newLvNode = NodeDetail.Items.Add
        (new ListViewItem(new string[] { commonName, os, osVersion }, 2));
else
    newLvNode = NodeDetail.Items.Add
        (new ListViewItem(new string[] { commonName, os, osVersion }, 11));
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17991107
I believe that the if statement you want should be this...

int UF_ACCOUNTDISABLE = 0x2;
bool disabled = (deChild.Properties["userAccountControl"].Value & UF_ACCOUNTDISABLE == UF_ACCOUNTDISABLE);

          if (disabled)
          {
          }
0
 
LVL 7

Accepted Solution

by:
Mohamed Zedan earned 500 total points
ID: 17991122
I believe that the if statement you want should be this...


int UF_ACCOUNTDISABLE = 0x2;
bool disabled = ((deChild.Properties["userAccountControl"].Value & UF_ACCOUNTDISABLE) == UF_ACCOUNTDISABLE);
//forgot these    ^                                                                                                       ^
          if (disabled)
          {
          }
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 17991199
If it gives you an error please send it here... and try this next

int UF_ACCOUNTDISABLE = 0x2;
bool disabled = (((int)deChild.Properties["userAccountControl"].Value & UF_ACCOUNTDISABLE) == UF_ACCOUNTDISABLE);

          if (disabled)
          {
          }
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
XML & .net 5 41
Class object 2 27
Syntax error 9 45
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now