public void SetUp() { // test user _testUser = new Netapi32.USER_INFO_1(); _testUser.usri1_name = "WaffleTestUser"; _testUser.usri1_password = Guid.NewGuid().ToString(); _testUser.usri1_priv = 1; _testUser.usri1_home_dir = null; _testUser.comment = "Waffle test user."; _testUser.usri1_script_path = null; int rc = Netapi32.NetUserAdd(null, 1, ref _testUser, 0); Assert.AreEqual(0, rc, new Win32Exception(rc).Message); // computer _computerName = Environment.MachineName; // fqn _testUserFqn = string.Format("{0}\\{1}", _computerName, _testUser.usri1_name); // join status IntPtr pDomain = IntPtr.Zero; rc = Netapi32.NetGetJoinInformation(null, out pDomain, out _joinStatus); Assert.AreEqual(Netapi32.NERR_Success, rc, new Win32Exception(rc).Message); _memberOf = Marshal.PtrToStringAuto(pDomain); Netapi32.NetApiBufferFree(pDomain); }
public static string IsDomainJoined() { // returns Compuer Domain if the system is inside an AD (an nothing if it is not) try { NetJoinStatus status = NetJoinStatus.NetSetupUnknownStatus; IntPtr pDomain = IntPtr.Zero; int result = Netapi32.NetGetJoinInformation(null, out pDomain, out status); if (pDomain != IntPtr.Zero) { Netapi32.NetApiBufferFree(pDomain); } if (result == Win32.ErrorSuccess) { // If in domain, return domain name, if not, return empty return(status == NetJoinStatus.NetSetupDomainName ? Environment.UserDomainName : ""); } } catch (Exception ex) { Beaprint.GrayPrint(string.Format(" [X] Exception: {0}\n Trying to check if domain is joined using WMI", ex.Message)); return(IsDomainJoinedWmi()); } return(""); }
public void SetUp() { // computer _computerName = Environment.MachineName; // join status IntPtr pDomain = IntPtr.Zero; Assert.AreEqual(Netapi32.NERR_Success, Netapi32.NetGetJoinInformation(null, out pDomain, out _joinStatus)); _memberOf = Marshal.PtrToStringAuto(pDomain); Netapi32.NetApiBufferFree(pDomain); }
/// <summary> /// Constructor with a computer name. /// </summary> /// <param name="computerName">Computer name.</param> public WindowsComputerImpl(string computerName) { _computerName = computerName; IntPtr pDomain = IntPtr.Zero; try { int rc = Netapi32.NetGetJoinInformation(computerName, out pDomain, out _joinStatus); if (rc == Netapi32.NERR_Success && _joinStatus != Netapi32.NetJoinStatus.NetSetupUnjoined) { _memberOf = Marshal.PtrToStringAuto(pDomain); } } finally { if (pDomain != IntPtr.Zero) { Netapi32.NetApiBufferFree(pDomain); } } }