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?
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 
Next 


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

Open in new window

0
zalazarCommented:
Did you already configure the execution of the script to run with "wscript.exe"
Name: %SystemRoot%\system32\wscript.exe
Parameters: "<path to vbs script>"
0
Ben HartAuthor Commented:
Ooo actually no. Would that possibly cause the tiny window to appear?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

zalazarCommented:
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.
0

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.
0
zalazarCommented:
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
objComputer.SetInfo

Open in new window

0
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 ;)
0
zalazarCommented:
Thanks :-)
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.