Solved

How do I convert a string to a Hex?

Posted on 2006-11-21
7
712 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.

730 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