Scripting Question

Get the IP and choose between which domain, using the ip address.

04/20/2015 2534 views
I am trying to have one image for 4 different companies, each company has a different domain, I want to have a K2000 image that will get the ip address and add it to the correct domain(using the ip address), without user input. If there is anything out there please let me know. If you guys have better ideas let me know.
Answer Summary:
0 Comments   [ + ] Show comments


Answer Chosen by the Author

I ended up fixing the issue, I had to add the path to the command line, It ended up looking like this "Cscript c:\Kace\applications\76\join_domain.vbs" Thank you for the assistance. 
Answered 05/06/2015 by: Jstump
White Belt

All Answers

I think this is related to your script to join the domain.

You can determine a IP address via VisualBasic Script

dim NIC1, Nic, StrIP
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC1
if Nic.IPEnabled then
StrIP = Nic.IPAddress(i)
MsgBox StrIP
end if

or you can do this via cmd

@echo off
for /f "delims=[] tokens=2" %%a in ('ping %computername% -n 1 -4 ^| findstr "["') do (set thisip=%%a)
echo %thisip%

and now create a if condition to join different domains based on the IP

Answered 04/21/2015 by: aragorn.2003
Red Belt

  • This is what I have right now, but it keeps coming up with an error.

    Cscript Join_Domain.vbs username password

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    'pulls IP address and trims the first 3 octets
    Set colAdapters = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=True")
    For Each objAdapter in colAdapters
    For Each strAddress in objAdapter.IPAddress
    arrOctets = Split(strAddress, ".")
    If arrOctets(0) <> "" Then
    strSubnet = arrOctets(0) & "." & arrOctets(1) & "." & arrOctets(2)
    x = 1
    Exit For
    End If
    If x = 1 Then
    Exit For
    End If

    Select Case strSubnet
    Case "10.70.240"
    strDomain = "cfpfire.com"
    Case "10.60.240"
    strDomain = "DomainB"
    End Select

    Const JOIN_DOMAIN = 1
    Const ACCT_CREATE = 2
    Const ACCT_DELETE = 4
    Const WIN9X_UPGRADE = 16
    Const JOIN_UNSECURE = 64
    Const DEFERRED_SPN_SET = 256
    Const INSTALL_INVOCATION = 262144

    If WScript.Arguments.Count < 3 or WScript.Arguments.Count > 4 Then
    ' Duff arguments so return non zero so the task is marked as failed.

    strUser = WScript.Arguments.Item(0)
    strPassword = WScript.Arguments.Item(1)

    'set DNS IP address
    If WScript.Arguments.Count = 4 Then
    strDNSIP = WScript.Arguments.Item(3)
    Set objShell = CreateObject("WScript.shell")
    objShell.Run "netsh int ip set dns ""local area connection"" static " & _
    strDNSIP &" primary", 0 , 0
    End If
    End If

    Set objNetwork = CreateObject("WScript.Network")
    strComputer = objNetwork.ComputerName

    Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
    strComputer & _
    "\root\cimv2:Win32_ComputerSystem.Name='" _
    & strComputer & "'")

    ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
    strPassword, _
    strDomain & "\" & strUser, _
    NULL, _

    • And what is the error message and error number?
      • Task ID: 75
        Task name: Jon Test Add to Domain
        Return code: 2
        Error description: The system cannot find the file specified.
    • Where do you set the variable strComputer in the first line. try it with localhost and this error is fixed. Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
      • I tried running it with "Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")" but came up with the same error.
    • OK, Task ID 75 and the error description is not an error within the vbs document but within the KACE configuration. Did you upload the .vbs file to the Post-installation Task. Another way is to change the error handling within the scripted installation to "Prompt on errors". The scripted installation will then stop the deployment at this position and provides you with the possibility to debug this error, e.g. by opening a command console.
      • The vbs is uploaded and the script i use in the command line is "Cscript New_Text.vbs username password" the uploaded vbs script is called New_Text.vbs and the run-time environment is windows. Everything is the same as the working join_domain.vbs except for the parts where I changed how the strDomain is found (via ip).
Can you please post a screenshot of this task. I should look like this one.

And did you try to enable the "Prompt on errors"?
Answered 05/06/2015 by: aragorn.2003
Red Belt


And prompt on errors is enabled.
Answered 05/06/2015 by: Jstump
White Belt

This content is currently hidden from public view.
Reason: Removed by member request For more information, visit our FAQ's.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ