VB Script Help.. help me understand what this script is doing

So I've got an old VB script that's supposed to capture the computers Description (in Windows) and apply that to the computer object in AD.  Now what's weird is that when I run this on a few random machines it displays nothing and does exactly what it should.  However I then created a GPO and called this VBS as a logon script.  When tested the user logs in and this GPO is processed a tiny Visual Basic Script window appears displaying the Description value and an OK button.

I am much better at Powershell than VB but I cannot understand, looking at this code, where it's creating a window with an OK button.

Below is the script itself.. can someone show me how to make this run invisibly?
LVL 14
Ben HartAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ben HartAuthor Commented:
Sorry, forgot the code /facepalm

On Error Resume Next
strComputer = "."

Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery("Select Description FROM Win32_OperatingSystem")
For Each object In objRegistry
	strDescription = object.Description 

Set objSysInfo = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
objComputer.Description = strDescription

Open in new window

Did you already configure the execution of the script to run with "wscript.exe"
Name: %SystemRoot%\system32\wscript.exe
Parameters: "<path to vbs script>"
Ben HartAuthor Commented:
Ooo actually no. Would that possibly cause the tiny window to appear?
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

From what I understand. You configured it as Logon script so within the GPO under "User Configuration\Policies\Windows Settings\Scripts (Logon/Logoff)\Logon"
And then filled in the name of the vbs file as "Script Name".
Can you maybe confirm that it's configured this way ?
Normally the script would then be executed via wscript already.

The script itself will not give any message if executed without any error.
Can you maybe create a screenshot of the exact window you are referring to ?

If the script is configured as Logon script in the User Configuration then the script will be executed under the credentials of the user.
The script reads the "Computer description" of the local computer and is writing this description to the Active Directory (AD) computer object.

The important part is that normal users do not have permissions to update or write to AD computer objects.

I did do a test with a normal user and without the line "On Error Resume Next"
I then get a window/messagebox from "Windows Script Host" with the path to the Script and the error "Access is denied".

To overcome this you can move the script from the Logon section to Startup.
Computer Configuration\Policies\Windows Settings\Scripts (Startup/Shutdown)\Startup
In this case it will be executed at Startup of the computer with the credentials of the SYSTEM account.

Also please note that the VBScript code can be simplified as the computers description is just a value in the registry.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ben HartAuthor Commented:
Thanks for the help, however I think your suggestion above about calling wscript with the argument of my script resolved it.  I wish I had kept a screenshot of the popup but basically it was a tiny, like 1x1in box with a title bar of Windows Script Host and the users name and the OK button.  That's it.  
With regards to permissions, I have made the required granular security changes allowing domain users to modify the Description field of computer objects.
It's been what.. almost a week and refreshing ADUC shows a lot more description fields populated.  Not all of them but enough that I think it's solved.  Well that and no other users have reported the popup.

Now if there is a better, meaning quicker, more reliable way to do this I'm def all ears.  You mentioned the registry.. I'm betting theres a way to export that key then import the value into AD.
You're welcome and good to hear that there are no popups anymore.
Within the script there is actually no such messagebox (with username and OK) configured.
The script has also the line "On Error Resume Next", which means that all errors are ignored and no error messages will be shown.
So the chances that the popup was generated via this script are small. Did you maybe check if there are other scripts that could cause this ?

This is how you could simplify the script although it's not much quicker and probably also not more reliable.
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
strDescription = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\srvcomment")

Set objSysInfo = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
objComputer.Description = strDescription

Open in new window

Ben HartAuthor Commented:
Actually no, I mean the day this happened I disabled that GPO and no other users complained. It could just be coincidence as I've seen some very weird things in the past 18 years ;)
Thanks :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.