Link to home
Start Free TrialLog in
Avatar of Ben Hart
Ben HartFlag for United States of America

asked on

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?
Avatar of Ben Hart
Ben Hart
Flag of United States of America image

ASKER

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

Avatar of zalazar
zalazar

Did you already configure the execution of the script to run with "wscript.exe"
Name: %SystemRoot%\system32\wscript.exe
Parameters: "<path to vbs script>"
Ooo actually no. Would that possibly cause the tiny window to appear?
ASKER CERTIFIED SOLUTION
Avatar of zalazar
zalazar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
objComputer.SetInfo

Open in new window

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 :-)