473,378 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Using WMI to Join a Domain

I have the following code that I am trying to use to join a computer to a domain in a C# wizard application I am writing.

I get an unhandled exception from System.Management.dll as soon as I instantiate the ManagementClass (first line).

Has anyone been able to do this in the past? All of the examples I can find are using VBScript - nothing in C#:

try
{
System.Management.ManagementClass mc = new System.Management.ManagementClass("Win32_ComputerS ystem.Name='" + System.Environment.MachineName + "'");
mc.Scope.Options.Authentication = AuthenticationLevel.PacketPrivacy;
mc.Scope.Options.Impersonation = ImpersonationLevel.Impersonate;
mc.Scope.Options.EnablePrivileges = true;

System.Management.ManagementObjectCollection moc = mc.GetInstances();

System.Management.ManagementBaseObject oInputs = mc.GetMethodParameters("JoinDomainOrWorkgroup");

oInputs["Name"] = tbDomain.Text;

oInputs["Password"] = tbPwd.Text;

oInputs["UserName"] = tbUser.Text;

oInputs["AccountOU"] = null;

oInputs["FJoinOptions"] = (UInt32)0x00000011;

System.Management.ManagementBaseObject oResults = mc.InvokeMethod("JoinDomainOrWorkgroup", oInputs, null);

uint ret = (uint)(oResults.Properties["ReturnValue"].Value);

MessageBox.Show(ret.ToString());
}
catch (ManagementException ex)
{
MessageBox.Show(ex.Message + " : " + ex.ErrorCode);
}


Any help is appreciated.

Thanks!
Oct 31 '07 #1
1 3985
BTW, this is the exception I get:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.management.dll

Additional information: Specified argument was out of the range of valid values.
Oct 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
46
by: Leo Breebaart | last post by:
I've tried Googling for this, but practically all discussions on str.join() focus on the yuck-ugly-shouldn't-it-be-a-list-method? issue, which is not my problem/question at all. What I can't...
0
by: Justin | last post by:
Hi. I decided to tidy up some of my queries, but I came across something that stumpt me: mysql> SELECT -> jobs.jobId, -> jobs.active, -> jobs.title, -> jobs.listed, -> ...
1
by: Karl.Auer | last post by:
Hello group! i have a table "group_code" wich relates the names of nt-(domain)-groups to codes. now i want use the stored procedure xp_logininfo (asking for the group-membership of the current...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
3
by: Alex Kachanov | last post by:
Hi! running py module with the following code from shell: __ dir=os.path.join(os.path.expanduser("~/domains/domain.com/html"),'test') subprocess.call() __ returns: __ find:...
3
by: =?Utf-8?B?RGFuZGFuIFpoYW5n?= | last post by:
Now I have a web application, a web service and a SQL Server database. The Web application will invoke the web service, the web service invokes the SQL Server stored procedure. I let the web...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.