Announcement

Collapse
No announcement yet.

adjust RDP properties - for my Project

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • adjust RDP properties - for my Project

    I need a little help to put some VB scripts (or any other scripting language) together for my project.


    My project is to:

    1. Find the IP address of the current machine.

    2. Make a shortcut of a RDC (Remote Desktop Connection) from that IP + 100 (i.e: If the IP address of my machine is 172.16.9.10, then the IP on the shortcut will be 172.16.9.110. If the IP address of the machine is 172.16.9.200 then the IP on the RDC short cut will be 172.16.10.55 and so on)

    3. Adjust the properties of RDC

    a. Open RDC to display as Full Screen
    b. Adjust display color to "High Color (24 bit)"
    c. Hide the "Connection Bar" when use Full Screen
    d. Adjust experience to "LAN (10Mbs or higher)

    ==================================

    Here are the scripts that I have

    1. Get IP Address and output to a file (working)
    Code:
    On Error Resume Next
    Dim WSH, FSO, RunIPConfig, TempDir, CMD, OpenFile, AllText, IntStr1, IntCounter
    Dim FileExist, IPText, IntStr2, IPStart, IPEnd, IPDiff, IPAddress, StartPos, IntStr3, IPAddress1
    Dim strComputerName, FinalIP
    Set WSH = WSCript.CreateObject("WScript.Shell")
    Set WshNtwk = WScript.CreateObject("WScript.Network")
    Set FSO = CreateObject("Scripting.FileSystemObject")
    TempDir = WSH.ExpandEnvironmentStrings("%TEMP%")
    CMD = WSH.ExpandEnvironmentStrings("%Comspec% /C")
    StartPos = 1
    ' Silently run ipconfig; output to temporary file
    RunIPConfig = WSH.run(CMD & " Ipconfig > %TEMP%\000001.tmp", 0, True)
    WSCript.Sleep 200
    FileExist = FSO.FileExists(TempDir & "\000001.tmp")
    2. Make a shortcut of a RDC (working)
    Code:
    set WshShell = WScript.CreateObject("WScript.Shell" )
    strStartup = WshShell.SpecialFolders("C:\Users\administrator\Desktop" )
    set oShellLink = WshShell.CreateShortcut(strStartup & "\Users\administrator\Desktop\0900 Start.lnk" )
    oShellLink.TargetPath = "%windir%\system32\mstsc.exe"
    oShellLink.WindowStyle = 1
    oShellLink.IconLocation = "%windir%\system32\mstsc.exe"
    oShellLink.Description = "TESTING"
    oShellLink.WorkingDirectory = "%windir%\system32"
    oShellLink.Save
    +++++++++++++++++++++++++++++++++++
    + Still Missing the IP + 100 to the RDC short cut +
    +++++++++++++++++++++++++++++++++++

    3. Still missing commands to adjust the RDC' properties


    Please let me know. Thank you everyone.
    Last edited by Rems; 26th March 2013, 11:30.

  • #2
    Re: Lite Scripts for Project

    Since this is fairly clearly your college homework, wouldn't it be better if you did the research yourself -- feel free to post completed scripts for comment, but if you take one someone gives you and pass it off as your own, it is called plagiarism and is frowned upon by all academic institutions.

    Since is one of your key sources these days, the following may point you in the right direction -- note the search phrase used
    https://www.google.co.uk/search?q=sc...FciihgfX5IGoDw
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Lite Scripts for Project

      Thank you Tom for pointing this out (search phrase used).

      I am helping to speed up the process of creating images of more than 600 laptops with this script. Since I'm not a scripting guru. I'm looking out for help to put things together.

      Thanks

      Comment


      • #4
        Re: Lite Scripts for Project

        Sorry, when you said "project" originally, it looked like a piece of university work -- we have had several posters wanting us to do their classwork for them and generally frown upon that!

        If it is a real world "project" that is, of course, different!
        Various WMI settings here: http://www.virtualizationadmin.com/a...-settings.html

        Microsoft Scripting Guy: http://technet.microsoft.com/en-us/s.../ee364707.aspx (various links to go further)

        Could you give us a clue about the client and server OSes involved?
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment


        • #5
          Re: Lite Scripts for Project

          This script is to eliminate the manual typing and shortcut creation for the Help Desk team.

          Here is the scope of this project:

          1. These 600 laptops (Windows 7 x64) will act as thin clients and will RDC into VMs (also Windows 7 x64) that sit on the internal cloud that we built.

          2. The 600 VMs will be created on the fly and will be assigned IP address based on the given virtual MAC address and location/subnet.

          3. These 600 VMs will be assigned to many different subnet (based on the location). Each location/subnet will have around 20 to 30 laptops.

          4. The DHCP server will assign IP address to each individual laptop, based on its MAC address and location/subnet (i.e. 00-00-00-00-00-01 = 172.16.9.10/24)

          For example, Location A will have 30 laptops with IP address range from 172.16.9.10 to 172.16.9.40 /24. Once the laptop connect to the network, and boot up, and auto login. The RDC icons will be automatically create on each laptop's desktop and will point to those VMs on the cloud that has the IP address range from 172.16.9.110 to 172.16.9.140.

          The laptop with the IP 172.16.9.10 itself will RDC directly to 172.16.9.110 and so on.

          Hope this clarify my points.

          Thanks

          Comment


          • #6
            Re: Lite Scripts for Project

            Originally posted by pdiep View Post
            [...]

            3. Adjust the properties of RDC
            1. Open RDC to display as Full Screen
            2. Adjust display color to "High Color (24 bit)"
            3. Hide the "Connection Bar" when use Full Screen
            4. Adjust experience to "LAN (10Mbs or higher)

            ==================================
            Not all 4 settings can be accomplished with the available mstsc.exe command line parameters. Therefore you should use a .rdp settings file to start with mstsc.exe.


            other subjects,

            1. Find the IP address of the current machine.
            To get the dhcp ip address check this old script see if it works for you, GetDHCPIPaddress.vbs http://www.tek-tips.com/faqs.cfm?fid=5908
            The script defines the ActiveDHCPIPAddress variable.

            2b. from that IP count +100 to the decimal value of the last octet
            arrIP = split(ActiveDHCPIPAddress,".")
            TargetIPAddress = arrIP(0) & "." & arrIP(1) & "." & arrIP(2) & "." & (arrIP(3)+100)


            2a. Make a shortcut that starts the rdc
            The shortcut best can run the script, and the script launches the rdp. This way you are sure getting the correct target ip address.


            putting it all together,
            Code:
            ' ## give this vbs script a nice name*)
            
            ' ## Copy the vbs script to the user's computer.
            ' ## The first time you 'runas the user' it once from this location.
            ' ## Then never move the vbs file from this location again.
            ' ## The script will now be executed every time the user clicks the shortcut on the desktop.
            
            ' ## *) note, the name of this script will also used for
            ' ## the name of the .rdp file in the users's temp folder
            ' ## and for the name of the .lnk shortcut on the user's desktop.
            
            On Error Resume Next
            
            Const HKEY_LOCAL_MACHINE = &H80000002
            Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
            ".\root\default:StdRegProv")
            
            Set WSHShell = CreateObject("Wscript.Shell")
            strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
            oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
            
            For Each subkey In arrSubKeys
            
            	DHCPAddress = WSHShell.RegRead("HKLM\" & strKeyPath & subkey & "\DhcpIPAddress")
            	If DHCPAddress <> "0.0.0.0" And Left(DHCPAddress,3) <> "169" Then
            		ActiveDHCPIPAddress = DHCPAddress	
            	End If
            Next
            
            '==========================================================================
            
            arrIP = split(ActiveDHCPIPAddress,".")
            TargetIPAddress = arrIP(0) & "." & arrIP(1) & "." & arrIP(2) & "." & (arrIP(3)+100)
            
            '==========================================================================
            
            Set FSO = CreateObject("Scripting.FileSystemObject")
            set WshShell = WScript.CreateObject("WScript.Shell")
            
            scriptPath = WScript.ScriptFullName
            baseName = FSO.GetBaseName(scriptPath)
            usrTempFldr = FSO.GetSpecialFolder(2)
            usrDesktopFldr = WshShell.SpecialFolders("Desktop")
            
            rdpFile = usrTempFldr & "\_" & baseName & ".rdp"
            lnkFile = usrDesktopFldr & "\_" & baseName & ".lnk"
            
            '==========================================================================
            
            ' ## create .rdp settings file in the temp folder
            Set stream = FSO.CreateTextFile(rdpFile, True, 1)
            arrRDPfile = array( _
               "full address:s:" & TargetIPAddress, _
               "screen mode id:i:2", _
               "session bpp:i:24", _
               "displayconnectionbar:i:0", _
               "connection type:i:6", _
               "networkautodetect:i:0", _
               "", _
               "; other", _
               "username:s:", _
               "desktopwidth:i:", _
               "desktopheight:i:", _
               "winposstr:s:0,3,0,0,800,600", _
               "compression:i:1", _
               "keyboardhook:i:2", _
               "audiocapturemode:i:0", _
               "videoplaybackmode:i:1", _
               "bandwidthautodetect:i:1", _
               "enableworkspacereconnect:i:0", _
               "disable wallpaper:i:0", _
               "allow font smoothing:i:1", _
               "allow desktop composition:i:1", _
               "disable full window drag:i:0", _
               "disable menu anims:i:0", _
               "disable themes:i:0", _
               "disable cursor setting:i:0", _
               "bitmapcachepersistenable:i:1", _
               "audiomode:i:0", _
               "redirectprinters:i:1", _
               "redirectcomports:i:0", _
               "redirectsmartcards:i:1", _
               "redirectclipboard:i:1", _
               "redirectposdevices:i:0", _
               "drivestoredirect:s:", _
               "autoreconnection enabled:i:1", _
               "authentication level:i:2", _
               "prompt for credentials:i:0", _
               "negotiate security layer:i:1", _
               "remoteapplicationmode:i:0", _
               "alternate shell:s:", _
               "shell working directory:s:", _
               "gatewayhostname:s:", _
               "gatewayusagemethod:i:4", _
               "gatewaycredentialssource:i:4", _
               "gatewayprofileusagemethod:i:0", _
               "promptcredentialonce:i:0", _
               "use redirection server name:i:0", _
               "rdgiskdcproxy:i:0", _
               "kdcproxyname:s:" _
            )
            for n = 0 to ubound(arrRDPfile)
              stream.WriteLine arrRDPfile(n)
            next
            stream.close
            
            '==========================================================================
            
            If not FSO.FileExists(lnkFile) Then
               ' ## create the .lnk file on the desktop
               set oShellLink = WshShell.CreateShortcut(lnkFile)
               oShellLink.TargetPath = scriptPath
               oShellLink.WindowStyle = 1
               oShellLink.IconLocation = "%windir%\system32\mstsc.exe"
               oShellLink.Description = "start virtual"
               oShellLink.WorkingDirectory = "."
               oShellLink.Save
            Else
               ' ##  launch mstsc
               strCmd = "mstsc.exe """ & rdpFile & """"
               strComputer = "."
               With GetObject("winmgmts:" _
                 & "{impersonationLevel=impersonate}!\\" & strComputer _
                 & "\root\cimv2:Win32_Process")
                 erRet = .Create(strCmd, null, null, intProcessID)
               End With
            End If
            set oShellLink = Nothing
            
            '==========================================================================
            
            wscript.quit
            It is possible to run this script as user logon script every time a user logs-in. In that case to avoid launching mstsc during logon you should adjust the script - Use script arguments for the logon script. the parameter instructs it just to create the shortcut and not launch mstsc.

            /Rems
            Last edited by Rems; 28th March 2013, 22:47.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: adjust RDP properties - for my Project

              Good morning Rems,

              Thank you for your help. The scripts work pretty well for all IP address below x.x.x.255. Once the laptop hits DHCP range above 172.16.9.157 the scripts stop working because it point to the address of 172.16.9.257 (which is NOT a valid IP range for IPv4). Once the 4th octet reaches 255, we need to increase the 3rd octet by one and reset the 4th octet to zero.

              arrIP = split(ActiveDHCPIPAddress,".")
              TargetIPAddress = arrIP(0) & "." & arrIP(1) & "." & arrIP(2) & "." & (arrIP(3)+100)


              I believe that I need the extra coding for this.

              arrIP = split(ActiveDHCPIPAddress,".")
              TargetIPAddress = arrIP(0) & "." & arrIP(1) & "." & arrIP(2) & "." & (arrIP(3)+100)

              If (arrIP(3) + 100 > 255
              Then increase the count for (arrIP(2) by 1
              Reset the count of (arrIP(3) to Zero + whatever left from the 100 count

              For example, if the DHCP server release an IP address of 172.16.9.157 for the laptop, then the RDC shortcut would need to point to IP 172.16.10.2 (because 255 - 157 = 98. So, we have 2 left)

              Thanks again for your time.

              pdiep

              Comment


              • #8
                Re: adjust RDP properties - for my Project

                Originally posted by pdiep View Post
                If (arrIP(3) + 100 > 255
                Then increase the count for (arrIP(2) by 1
                Reset the count of (arrIP(3) to Zero + whatever left from the 100 count

                For example, if the DHCP server release an IP address of 172.16.9.157 for the laptop, then the RDC shortcut would need to point to IP 172.16.10.2 (because 255 - 157 = 98. So, we have 2 left)
                Code:
                ' ## sample input...
                ActiveDHCPIPAddress = "172.16.9.157"
                
                arrIP = split(ActiveDHCPIPAddress,".")
                Octet3 = arrIP(2) : Octet4 = arrIP(3) + 100
                If 255 - Octet4 < 1 then Octet3 = Octet3 + 1 : Octet4 = Abs(255 - Octet4)
                TargetIPAddress = arrIP(0) & "." & arrIP(1) & "." & Octet3 & "." & Octet4
                
                ' ## echo output...
                wsh.echo "input   :" , ActiveDHCPIPAddress & vbnewline & "output :" , TargetIPAddress
                /Rems

                This posting is provided "AS IS" with no warranties, and confers no rights.

                __________________

                ** Remember to give credit where credit's due **
                and leave Reputation Points for meaningful posts

                Comment


                • #9
                  Re: adjust RDP properties - for my Project

                  Hi Rems and everyone,

                  I put the scripts from Rems together and it works very well.

                  Again, thank you very much for your help.

                  pdiep

                  Comment

                  Working...
                  X