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

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

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.
¯\_(ツ)_/¯

Similar Messages

  • I need a USB Headset with Mic to use for Webinar's and Go To Meeting sessions. There looks to be very few options that work with the Mac as they seem to be designed for Windows.  Any suggestions on equipment?

    I am looking for a binaural USB headset with microphone to use during Go To Meeting sessions and Webinar's. Seems to be little that works with the iMac and most of the web searches have not been encouraging. Any suggestions on units that work.  I have a new iMac running Snow Leopard 10.6.8.
    Bob

    I am looking for a binaural USB headset with microphone to use during Go To Meeting sessions and Webinar's. Seems to be little that works with the iMac and most of the web searches have not been encouraging. Any suggestions on units that work.  I have a new iMac running Snow Leopard 10.6.8.
    Bob

  • I have been trying to update my cc info and for some reason it has kept saying that the cc info does not match with the bank so the transcation failed every time I was trying to download something even when it's free but my cc got charged $1.- each time.

    I have been trying to update my cc info but for some reason it has kept saying the cc info did not match with the bank info so the transaction failed every time I made an attempt to download something even it was free. However, I saw my cc online got charged $1.00 everything I was trying to update my cc info ...why?

    Im wondering why my post hasn't been answered yet.  I did file a report with the BBB and I had a rude representative from Verizon call me named Steve. He said I can file all of the reports I want and I will just keep getting calls from him.  I can understand why my phone couldn't be replaced because of the small crack.  I guess I have to eat that one (but it sucks because the lollipop update is what caused the problems)  but what about all of the data overage I had to pay for for trying to fix this phone because of a lollipop update.  I dont think it is fair to have to pay that as well. In addition,  because I have an east coast phone number but live on the west coast, I cannot have tech support after 8pm.  Verizon has cut this off.  Im very dissatisfied and I have been a customer of Verizon for 13 years.  Im hoping for a response this time.

  • I'm on OX X and am trying to work with iMovie 09.  It keeps crashing every time i open iMovie.  Any suggestions?

    I'm on OX X - version 10.9 and trying to work with iMovie 09 and it keeps crashing...any suggestions?

    As a first step, you may want to try deleting iMovie preferences.
    AppleMan1958 outlines the steps in his excellent User Tip here:
    https://discussions.apple.com/docs/DOC-4061
    Matt

  • Can you have 2 apple tvs working with one computer - both active at the same time?

    Can 2 Apple TVs - Generation 3 - work off the same computer?
    I can't seem to get the 2nd Apple TV to find the network yet I have full signal and the Network name is correct.
    Can they work at the same time using different content?

    Hi SwedelostinAmerica,
    Welcome to the Apple Support Communities!
    The iPhone can maintain multiple pairing records, but it can only connect to one headset or hands-free device at a time. However, in your situation there may be a solution. You can connect the iPhone via Bluetooth for calls and use the 3.5mm jack on your iPhone and car radio to connect for music.
    The following article explains Bluetooth pairing and usage. Please use it as a reference.
    iOS: Third-party Bluetooth accessories
    http://support.apple.com/kb/HT1664
    Have a great day,
    Joe

  • My macbook pro makes that ejecting noise when i open it but not every time usually when i ve been away for awhile then take it out of sleep it makes the noise is this normal?

    Hi ive had my macbook pro for a week or so and when i open after its been in sleep mode for quite a while it will usually make that ejecting noise. It doesnt make the ejecting noise evreytime i open it just sometimes. Is this normal HELP

    Yes, it's normal.
    Apple released a firmware update a couple of years ago that was supposed to stop the drive from making that noise in certain models that were available then, but even the update didn't work all the time. The noise is completely harmless and not indicative of any problem. Just ignore it.

  • Is there a firefox that works with google chrome os I have a samsung chrome book

    I recently purchased a google chrome book and would like to know if you have a version that works with the google chrome os The unit I purchased was the samsung chromebook
    I have used firefox for as long as i can remember and would like to continue
    Regards
    Jeff Williams

    Please use the [[Suggestion Box]]

  • I have air printer that works on iPhones but not iPad 2

    I have air printer that works with both iPhones but not with iPad2

    Just to build on red_menace's answer a bit...
    set MyText to do shell script "ps -A | grep '[M]ac VNC 2.1.app' | awk '{print $5}'"
    log "MyText=" & MyText
    set content of text field "Dir" of front window to MyText
    The log command will write the results of the "do shell script" to Xcode's run log window. If you see the correct output there then you know that part is working correctly and the problem is in the way you're trying to insert the string into the text field. Maybe "Dir" doesn't match the name you've given your text field in IB? Or maybe your text field is contained within another view, such as an NSBox or an NSTabView?
    Also, I guess "of front window" should work in AppleScript Studio but I always give my windows AppleScript names in IB and then explicitly specify the window in my scripts. Like this:
    set content of text field "Dir" of window "MyWindow" to MyText
    Steve

  • I am trying to connect to my Wifi Network. It is a Galaxy Nexus. I am trying to connect to this Hotspot. I have an iMac that works fine with my network but for some reason with this computer I cannot connect.

    So far I have pulled the system configuration file, I have reset safari, I deleted all old passwords from the wifi network in Keychain I restarted both devices. I am at the end here and I cannot get it to work I have an iMac that works fine with my network but for some reason this computer will not connect. It is system wide specifically to my personal hotspot. I can connect fine to any other network (wifi) but just not mine. I have not changed any wifi settings. I have been trying to figure this out. I have a MacBook Pro Late 2006 model running Lion (10.7.5) So any ideas anyone? Please help!

    12. At a WiFi hotspot, you can't get connected.  The most frequent reason is the login screen for the WiFi hotspot is only able to be connected with a single type of browser.  If Safari doesn't work, try Firefox, Chrome, Omniweb, or Opera. 
    From my tip:
    https://discussions.apple.com/docs/DOC-6411

  • I have an older HP5550C flatbed scanner that works with 10.5 and 10.6 but not on my new iMac running 10.7

    I have an older HP5550C flatbed scanner that works with 10.5 and 10.6 but not on my new iMac running 10.7. Surely there is software that will allow older scanners to work on OS10.7. My MacBook Pro runs 10.6 and the

    Although the HP Scanjet shows up in the system profile for the computer it is generic and is not configured (as in screen shot).  It also does not show up in the ;ist of pritnters, scanner when I open Image Capture.  I can't load the software that came with the printer because it is out of date so that would make it impossible to configure the scanner on the new iMac. see below:  Too bad there isn't some generic profile I could load that would cover the 5550c. I have a new all in one printer-fax-scanner but the old one can scann in slides and negatives which I have.

  • HT202274 Apple ID has my old email address. It will not allow me to change the address and will not accept my password or ID questions.   I recently upgraded to OSX Yosemite 10.10.1.  I also have an Apple ID that works with iTunes and would like to keep i

    Apple ID has my old email address. It will not allow me to change the address and will not accept my password or ID questions.   I recently upgraded to OSX Yosemite 10.10.1.  I also have an Apple ID that works with iTunes and would like to keep it as my primary.

    To change the iCloud ID on your devices you have to go to Settings>iCloud, tap Delete Account, provide the password for the old ID when prompted (if using iOS 7), then sign back in with your current ID.
    If you don't know the password for your old ID, or if it isn't accepted, you will have to temporarily recreate it in order to delete the existing account.  To do this, go to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iPhone on your device, even though it prompts you for the password for your old account ID. Then save any photo stream photos that you wish to keep to your camera roll.  When finished go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • I have an ipod touch and just updated my software to ios 7.1.2. Now I get the message that my adapter, accessory does not support my device. Is there a new adapter that I need to buy that works with the ios 7.1.2?

    i have an ipod touch and just updated my software to ios 7.1.2. Now I get the message that my adapter, accessory does not support my device. Is there a new adapter that I need to buy that works with the ios 7.1.2?

    This is not my problem. However, I think it may be related to an old speaker. I was using the 30 pin adapter for about a week after the upgrade to 7.1.2. But I think with the update the speaker won't work anymore. I will try with a new speaker system. Thank you for trying to assist.

  • I have an airport extreem network that works with two MacBooks.  I am trying to get my PC (IBM ThinkPad) to connect to the network.  The PC has airport for the PC downloaded but it will not recognize the network.  Any suggestons please!

    I have an airport extreem network that works with my two MacBooks and a iMAC.  I am having no luck in getting a PC (IBM ThinkPad0 that has the PC airport software to be recognized by the network.  Any suggestions?

    When you introduced the AirPort Extreme, you had a condition where you have two routers in series. The simpliest solution is to reconfigure the downstream router (in this case the Extreme) as a bridge. This will allow the upstream router to provide the required NAT & DHCP services to all network clients regardless of which router they are connected to.
    To reconfigure the Extreme as a bridge, you will use the AirPort Utility. (Note: I will provide the steps for using AirPort Utility v5.x)
    AirPort Utility > Select the AirPort > Manual Setup
    Internet > Internet Connection tab > Connection Sharing = Off (Bridge Mode)

  • Etting support through this site is terrible. Having said that I have been trying to access the store in order to order PS CC and I have  been unable to connect. I have  an internet connection that works with everyone else. The URL comes up in the browse

    Getting support through this site is terrible. Having said that I have been trying to access the store in order to order PS CC and I have  been unable to connect. I have  an internet connection that works with everyone else. The URL comes up in the browse window and the address simply hangs. This has been going on for the past three hours.

    Please read, and reply back here with information https://forums.adobe.com/thread/1499014
    -and try some steps such as changing browsers and turning off your firewall for downloads
    http://myleniumerrors.com/installation-and-licensing-problems/creative-cloud-error-codes-w ip/
    http://helpx.adobe.com/creative-cloud/kb/failed-install-creative-cloud-desktop.html
    BLANK Cloud Screen http://forums.adobe.com/message/5484303 may help
    -and step by step http://forums.adobe.com/thread/1440508?tstart=0
    -and http://helpx.adobe.com/creative-cloud/kb/blank-white-screen-ccp.html
    Mac Spinning Wheel https://forums.adobe.com/message/5470608
    -Similar in Windows https://forums.adobe.com/message/5853430

  • I have an older G5 tower Power PC and the OS 10.5.8, but the firefox and safari browers are no longer supporting this computer. How can I download an older version that works with this computer?

    I have an older G5 tower Power PC and the OS 10.5.8, but the firefox and safari browers are no longer supporting this computer. How can I download an older version that works with this computer?
    Or what is the newest OS system I can load onto this computer?
    I think it is from 2006

    Hello,
    10.5.8 is the highest OSX it can run.
    TenFourFox is the most up to date browser for our PPCs, they even have G4 & G5 optimized versions...
    http://www.floodgap.com/software/tenfourfox/
    I'd avoid vesrion 24 though, as it no longer supports plug-ins like Flash.
    SeaMonkey seems pretty fast also, with many options...
    http://www.seamonkey-project.org/
    http://www.seamonkey-project.org/releases/
    Might also look into iCab & OmniWeb versions.

Maybe you are looking for

  • Sending an email through J2ME

    What is the easiest way to send an email to an email account using J2ME? I browsed google, and all of the results appeared very complex. Is there a simple way to do it (like you can with PHP)? Thanks!

  • Skype Getting Problem

    Hi There I just purchased Nokia E-63 and Installed Skype from OVI store and Skype installed Successfully and when i start skype and login into it than skype automatically shutdown and my E-63 mobile restarted. Plz tell me the solution if any have. Th

  • OIM 11.1.1.5 software for Windows 64 bit

    Hi, I have installed weblogic server 10.3.5 and SOA 11.1.1.5 on my windows 64 bit machine. I am having hard time to find the software for OIM 11.1.1.5. Can you please let me know the url where I can download it? I found 11.1.1.2 and patch 11.1.1.5. D

  • I'm getting a kernel panic that I can't figure out

    I have a power mac g4 1.25 with 1.5 ram. I'm getting a kernel panic that I can't figure out. I have changed the graphic card, ram, logic board, keyboard and mouse. It happens right when it starts and sometimes 5 minutes after I log in. I erased and r

  • Jdbc tables and columns

    hi Im trying to write a small jdbc program that retrieves all the tables in an MS Access database...so far so good. DatabaseMetaData dbMetaData = con.getMetaData(); ResultSet rs = dbMetaData.getTables(null,null, null, new String[]{"TABLE"});Now for e