Need help in writing a vbs script RRS feed

  • Question

  • I am very new to scripting and need help in scripting the following:

    When the Windows 7 machine boots up or a user logs on (easy to do with GPO), I want to execute a script that starts some services ONLY if the length of the computer name is less than or equal to 15 else it should exit. It has to be done in the background without any user interaction.

    The script should be able to work for both x86 and x64 version of Win7.

    Any help would be greatly appreciated.

    Thanks in advance.



    • Moved by Bill_Stewart Sunday, July 13, 2014 2:46 PM Abandoned drive-by question
    Thursday, April 17, 2014 11:14 PM

All replies

  • No can do.  If you are having issues with GPOs we have a support group that meets on Friday nights.  We have a good group. We discuss these troublesome issues at great length and then have coffee an pizza.  You should join our group.

    Yes - the x86 issue is a problem.

    Can you please post your script for us. We will take it up at our next meeting.  Rest assured that your issue will be taken very seriously.

    We will need your script, all error messages in the exact form and all seismographic events caused by your issues.

    We are here to serve.


    Friday, April 18, 2014 12:21 AM
  • Hi,

    I highly recommend that you skip VBScript and learn PowerShell instead. This is pretty trivial in PowerShell:

    If ($env:COMPUTERNAME.Length -le 15) {
        # Do stuff
        # HINT: Look into Start-Service
        Write-Host "Under limit: $env:COMPUTERNAME"
    } Else {
        # Do optional stuff
        Write-Host "Over limit: $env:COMPUTERNAME"

    (OT: jrv - happy? =])

    If you must stick with VBScript for some odd reason, here's an example to get you started:

    Set wshNetwork = WScript.CreateObject( "WScript.Network" )
    strComputerName = wshNetwork.ComputerName
    If Len(strComputerName) <= 15 Then 
    	'Do stuff here when the name is short enough
    	WScript.Echo "Under limit: " & strComputerName
    	'Do stuff here when the name is too long (only if you want to)
    	WScript.Echo "Over limit: " & strComputerName
    End If

    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    Friday, April 18, 2014 12:55 AM