Solved

How do I convert a string to a Hex?

Posted on 2006-11-21
7
710 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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

832 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