Code _vbs to change the description of a computer with the VBS implementation

Source: Internet
Author: User

Ask:
Hello, Scripting Guy! When you connect to a remote computer by using Windows Explorer, you can see the description of the computer in the details pane. How do I change the description of my computer?
--GF
For:
Hello, GF. Just to make sure everyone knows what we're talking about, we don't talk about the description attribute in Active Directory, but about the computer instructions that are broadcast across the network. (If what you really want to know is how to change the description attribute in Active Directory, see this "Hello, Scripting Guy!") Column )
For example, in Windows XP, you can view the computer description by right-clicking My computer, clicking Properties, and then viewing the contents of the Computer Name tab of the System Properties dialog box:
As you mentioned, if you connect to the computer by using Windows Explorer, the description also appears in the details pane:
We also think it's exciting.
So how do you change the computer description? Yes, you can start Regedit.exe and then manually change the registry values Hkey_local_machine\system\currentcontrolset\services\lanmanserver\parameters\ Srvcomment. or run a script similar to the following script:

Copy Code code as follows:

const hkey_local_machine = &h80000002 
strcomputer =  "."  
set objregistry = getobject _ 
     ("winmgmts:\\"  & strComputer &  "\root\default:StdRegProv")  
strkeypath =  " System\currentcontrolset\services\lanmanserver\parameters " 
strvaluename = " Srvcomment "  
strdescription =  "description changed programmatically"  
Objregistry.setstringvalue hkey_local_machine, strkeypath, strvaluename, strdescription  
Of course it's easy; Do you really think that we will suddenly start to provide complex and convoluted answers to your questions? We first define a constant named HKEY_LOCAL_MACHINE and set its value to &H80000002; after a while, we will use this constant to tell the script the registry hive we are working on. Then we connect to the WMI service (in this case, it's on the local machine, but it's almost as simple to modify the registry on the remote computer) and bind to the StdRegProv class. (And that class, as we've been so tired of telling you, happens to be in the root\default namespace.) )
Next, we assign values to three variables:
strKeyPath = "System\currentcontrolset\services\lanmanserver\parameters"
strValueName = "Srvcomment"
strdescription = "Description changed programmtically"
The variable strKeyPath represents the path within the registry HKEY_LOCAL_MACHINE section, strValueName represents the registry value to be changed (Srvcomment), and Strdescription, Yes: Strdescription represents a new computer description. Your observation is very sharp.
Note: What we want to say is that you are much better at this than we are, but we don't want the manager to know anything about it. Indeed: For a Microsoft manager, understanding the situation will be most important!
All we have to do now is call the SetStringValue method and pass the HKEY_LOCAL_MACHINE and our three variables as method arguments:
Objregistry.setstringvalue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strdescription
A script like this really does make life meaningful, doesn't it?
Note: Note that even if you make this change in the registry, the new instructions may still have to take effect after the computer restarts. It's just a place to pay attention to.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.