none
I have a script that works with no issues in XP but fails every time in Windows 7 RRS feed

  • Question

  • All the script is supposed to do is get the ip address of the client and add .5 to the last octet passing this ip address through to remote desktop. It performs fine in XP but fails on a join error in 7 or 8. Any help? 

    ' ************************************************************
    ' SCRIPT to determine IP address of Terminal Server in Field installation
    ' ASSUMPTIONS: terminal device has been booted after DHCP server
    ' is operational. Calculation of server IP address is based
    ' on terminal device's IP address.
    ' PROCESSING:
    ' Obtain IP Address from Registry (NB: WMI doesn't work...)
    '
    ' Compute server's IP Address by replacing own IP address's
    ' last octet with the number 5
    '
    ' Invoke the TS client in fullscreen mode using the newly
    ' computed address
    ' When done with session, present MSGBOX --  otherwise, the TS
    ' session times out and restarts, leaving a bunch of sessions active
    ' ************************************************************
    ' VERSION:1.1
    ' DATE:   September 6, 2007
    ' AUTHOR: Dom
    ' ************************************************************
    ' CHANGE LOG
    ' 1.0 Original, using registry hack
    ' 1.1 Modified to use WMI
    ' 1.2 May 2008 - Added msgbox 
    ' 1.3 August 2008 - Translate msgbox
    option explicit ' force all variables to be declared

    ' ************************************************************
    ' ***           Start of script                            ***
    ' ************************************************************
       Const wbemFlagReturnImmediately = &h10
       Const wbemFlagForwardOnly = &h20
       Dim WshShell, ObjNet
       Dim StrComputer, Server
       Dim objWMIService
       Dim colItems, objItem
       Dim strDefaultIPGateway, strIPAddress, strIPSubnet, cIPAddress
       Set WshShell = WScript.CreateObject("WScript.Shell")
       Set objNet=CreateObject("wscript.Network")
       'Get the Computer's network name
       strComputer=objNet.ComputerName
       ' Connect to root of management interface for this computer
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)
       For Each objItem In colItems
          strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",")
          strIPAddress = Join(objItem.IPAddress, ",")
          strIPSubnet = Join(objItem.IPSubnet, ",")
          exit for
       Next
       cIPAddress=split (strIPAddress,".",4)
       Server = cIPAddress(0) & "." & cIPAddress(1) & "." & cIPAddress(2)  & ".5" 
       WshShell.Run "%SystemRoot%\System32\mstsc.exe /v:" & server & " /f",,true
       dim answer
       answer = msgbox ("Click OK to log in to server, Cancel to terminate session" & vbcrlf & "Cliquez OK pour ouvrir une session sur le serveur, ou CANCEL pour fermer la session.",1 + 64 + 4096)
       if answer = 1 then 'that would be "OK"
           wshshell.run "wscript c:\windows\connect.vbs"
       else
          wshShell.run "shutdown -L"
       end if
    ' ************************************************************
    '                             END
    ' ************************************************************

    Thursday, December 19, 2013 2:18 PM

Answers

  • After removing all of the lines that do nothing or introduce subtle errors her eis swhat the script actually needs to do.

    ' get local address
    Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
    For Each objItem In colItems
        IPAddress = objItem.IPAddress(0)
    Next
    
    ' fix address
    ip=Split(IPAddress,".")
    ip(3) = 5
    TSServerIP = Join(ip,".")
    
    ' Run the ssession
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run "%SystemRoot%\System32\mstsc.exe /v:" & TSServerIP & " /f",,True
    
    '????
    answer = msgbox ("Click OK to log in to server, Cancel to terminate session" & vbcrlf & "Cliquez OK pour ouvrir une session sur le serveur, ou CANCEL pour fermer la session.",1 + 64 + 4096)
    if answer = 1 then 'that would be "OK"
        wshshell.run "wscript c:\windows\connect.vbs"
    Else
       wshShell.run "shutdown -L"
    end if
    

    Much shorter and much easier to understand.  Fewer logic errors.


    ¯\_(ツ)_/¯

    Thursday, December 19, 2013 4:17 PM

All replies

  • What does "fails on a join error" mean? (When you say that something didn't work, you have to say how it didn't work.)

    You need to post the exact error message and tell us on what line the error occurs.

    It would also help if you explain the purpose of the script.

    Bill

    Thursday, December 19, 2013 3:21 PM
    Moderator
  • Sorry

    It fails on line 48 Char 7

    Invalid use of of NULL:  Join

    800A005E

    The purpose is simply to take the ip of the client and change the last octet to .5 so it can use that address created with .5 as a terminal services address to connect terminal services. The reason is we have 4 distinct ip profiles out in the field and the script needs to work with each ip range of the terminal server.

    Thursday, December 19, 2013 3:38 PM
  • Remember, we can't see your screen.

    Which line is line 48?

    Bill

    Thursday, December 19, 2013 3:57 PM
    Moderator
  • You will likely have more than one adapter configuration.  Some may have no DefaultGateway.  That will give you a NULL error.


    ¯\_(ツ)_/¯

    Thursday, December 19, 2013 3:57 PM
  • On my system I have 25 instances of Win32_NetworkAdapterConfuguration.  Only the active one has a gate way and is is NOT the last one.

    You need to get the connected adapter.

    "SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=True"

    There are other issues that make it seem odd that this ever worked.


    ¯\_(ツ)_/¯

    Thursday, December 19, 2013 4:13 PM
  • After removing all of the lines that do nothing or introduce subtle errors her eis swhat the script actually needs to do.

    ' get local address
    Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
    For Each objItem In colItems
        IPAddress = objItem.IPAddress(0)
    Next
    
    ' fix address
    ip=Split(IPAddress,".")
    ip(3) = 5
    TSServerIP = Join(ip,".")
    
    ' Run the ssession
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run "%SystemRoot%\System32\mstsc.exe /v:" & TSServerIP & " /f",,True
    
    '????
    answer = msgbox ("Click OK to log in to server, Cancel to terminate session" & vbcrlf & "Cliquez OK pour ouvrir une session sur le serveur, ou CANCEL pour fermer la session.",1 + 64 + 4096)
    if answer = 1 then 'that would be "OK"
        wshshell.run "wscript c:\windows\connect.vbs"
    Else
       wshShell.run "shutdown -L"
    end if
    

    Much shorter and much easier to understand.  Fewer logic errors.


    ¯\_(ツ)_/¯

    Thursday, December 19, 2013 4:17 PM
  • That worked, thank you so much!
    Thursday, December 19, 2013 4:51 PM