Jump to content

aek

Member
  • Posts

    5
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    United States

Everything posted by aek

  1. When our machine boots in WinPE, it gets name of DNS Servers for our primary domain from the DHCP Server. This helps us perform AD queries in the primary domain. During our build process we would also want to search in a testing AD Domain. That DNS Server is on a different subnet. We want to add the name of the DNS Server (for that testing domain) in our Win PE process, so that we can also search in that testing AD domain alongwith the primary domain. I am using this VB Code, but it comes back with Automation error. Any help/thoughts on how to get it to work in Win PE Environment? Dim aDNS(3) Dim strComputer Dim objWMIService Dim errDNS Dim objItem Dim colItems 'For all the enthusiasts who will just copy and run this script msgbox "Please write down your DNS Search order: " 'DNS server search order aDNS(0) = "1.1.1.1" aDNS(1) = "1.1.1.2" aDNS(2) = "1.1.1.3" adns(3) = "1.1.1.4" 'Set Networking Managing Objects strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = 1") For Each objItem In colItems errDNS = objItem.SetDNSServerSearchOrder() 'WScript.Sleep 120000 errDNS = objItem.SetDNSServerSearchOrder(aDNS) Next Set objWMIService = Nothing Set colItems = Nothing msgbox "Just changed your DNS Search order: "
  2. Got it. Hope it helps someone. Call this API and it might just work. Option Explicit MsgBox GetPDCName("computername", "domainnname") 'The NetGetDCName function returns the name of the Primary Domain Controller (PDC) for the specified domain. 'API calls Private Declare Function NetGetDCName Lib "netapi32.dll" (ServerName As Any, DomainName As Any, lpBuffer As Long) As Long Private Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal pBuffer As Long) As Long Private Declare Sub CopyMem Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long) Private Declare Function lstrlenW Lib "kernel32.dll" (ByVal lpString As Long) As Long 'API Constants Private Const NERR_Success As Long = 0& 'Module Private Function PtrToString(lpwString As Long) As String 'Convert a LPWSTR pointer to a VB string Dim Buffer() As Byte Dim nLen As Long If lpwString Then nLen = lstrlenW(lpwString) * 2 If nLen Then ReDim Buffer(0 To (nLen - 1)) As Byte CopyMem Buffer(0), ByVal lpwString, nLen PtrToString = Buffer End If End If End Function 'ComputerName 'Pointer to string containing the name of the remote server on which the function is to execute. A NULL string specifies the local computer. 'DomainnNme 'Pointer to a string containing the name of the domain. A NULL string indicates that the function returns the name of the domain controller for the primary domain. Public Function GetPDCName(ComputerName As String, DomainName As String) As String Dim bComputer() As Byte Dim bDomain() As Byte Dim ret As Long Dim lpBuffer As Long Dim s As String If Trim(ComputerName) = "" Then 'Local users bComputer = vbNullChar Else 'Check the syntax of the ServerName string If InStr(ComputerName, "\\") = 1 Then bComputer = ComputerName & vbNullChar Else bComputer = "\\" & ComputerName & vbNullChar End If End If If Trim(DomainName) = "" Then 'Default Domain bDomain = vbNullChar Else bDomain = DomainName & vbNullChar End If ret = NetGetDCName(bComputer(0), bDomain(0), lpBuffer) If ret = NERR_Success And lpBuffer Then s = PtrToString(lpBuffer) End If If lpBuffer Then Call NetApiBufferFree(lpBuffer) End If GetPDCName = s End Function 'Usage
  3. I have VB, ADSI, OLEDB, ADO, SQL Server and maybe a bunch more
  4. I have a LDAP query that I use to query AD. I query AD for a specific useraccoutnname in my Win PE environment. I query AD before even the machine gets ghosted and way before even I log into any domain. I need to use the name of my DC in my LDAP query that queries AD because without that my query fails. Currently I have been harcoding the name of the Domain controller, but can you get the name of the nearest DC in WinPE environment before logging to any domain. This is what I had tried, but did not work for me. Set MyDomain = GetObject("LDAP://RootDSE") MyDC = MyDomain.Get("dnsHostName") The above query basically gives me the name of the DC. I then tried to use this MyDC variable in my LDAP search but this did not work in WinPE (works fine from my machine as I am already logged on the domain). Any thoughts or suggestions of getting the name of Domain Controller.
×
×
  • Create New...