Common vbs scripts with Instances

Source: Internet
Author: User
Tags blank page

1. vbs obtains the IP address of the local machine.
Strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set ipconfigset = ob1_miservice. execquery ("select IPaddress from
Win32_networkadapterconfiguration where ipenabled = true ")
For each ipconfig in ipconfigset
If not isnull (ipconfig. IPaddress) then
For each straddress in ipconfig. IPaddress
Wscript. Echo straddress
Next
End if
Next
2. Obtain the name of the Local Computer
Strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set colcomputers = obw.miservice. execquery ("select * From win32_computersystem ")
For each objcomputer in colcomputers
Wscript. Echo objcomputer. Name
Next
4. Check the upgrade package
Strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set coloperatingsystems = obw.miservice. execquery ("select * From win32_operatingsystem ")
For each objoperatingsystem in coloperatingsystems
Wscript. Echo objoperatingsystem. servicepackmajorversion &"."&
Objoperatingsystem. servicepackminorversion
Next
5 check hot fix
Strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set colquickfixes = obw.miservice. execquery ("select * From win32_quickfixengineering ")
For each objquickfix in colquickfixes
Wscript. Echo "Description:" & objquickfix. Description
Wscript. Echo "Hot Fix ID:" & objquickfix. hotfixid
Next
6. Check the number of local administrators.
Set objnetwork = Createobject ("wscript. Network ")
Strcomputer = objnetwork. computername
Set objgroup = GetObject ("winnt: //" & strcomputer & "/administrators, group ")
For each objuser in objgroup. Members
Wscript. Echo objuser. Name
Next
7. Disk System
Strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set coldisks = ob1_miservice. execquery ("select * From win32_logicaldisk where drivetype =
3 ")
For each objdisk in coldisks
Wscript. Echo "disk drive:" & objdisk. DeviceID & "--" & objdisk. filesystem
Next
8. Check whether automatic logon is enabled.
Const HKEY_LOCAL_MACHINE = & h80000002
Strcomputer = "."
Set objreg = GetObject ("winmgmts :\\" & strcomputer & "\ Root \ default: stdregprov ")
Strkeypath = "SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Winlogon"
Strvaluename = "AutoAdminLogon"
Objreg. getdwordvalue HKEY_LOCAL_MACHINE, strkeypath, strvaluename, dwvalue
If dwvalue = 1 then
Wscript. Echo "auto logon is enabled ."
Else
Wscript. Echo "auto logon is disabled ."
End if
9 Disable Automatic Logon
Const HKEY_LOCAL_MACHINE = & h80000002
Strcomputer = "."
Set objreg = GetObject ("winmgmts :\\" & strcomputer & "\ Root \ default: stdregprov ")
Strkeypath = "SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Winlogon"
Strvaluename = "AutoAdminLogon"
Dwvalue = 0
Oreg. setdwordvalue HKEY_LOCAL_MACHINE, strkeypath, strvaluename, dwvalue
10 check whether the guest is disabled
Set objnetwork = Createobject ("wscript. Network ")
Strcomputer = objnetwork. computername
Set objuser = GetObject ("winnt: //" & strcomputer & "/guest ")
If objuser. accountdisabled then
Wscript. Echo "the Guest account is disabled ."
Else
Wscript. Echo "the Guest account is enabled ."
End if
11 close guest
Set objnetwork = Createobject ("wscript. Network ")
Strcomputer = objnetwork. computername
Set objuser = GetObject ("winnt: //" & strcomputer & "/guest ")
If objuser. accountdisabled then
Wscript. Echo "the Guest account is already disabled ."
Else
Objuser. accountdisabled = true
Objuser. setinfo
Wscript. Echo "the Guest account has been disabled ."
End if
12. Search for local Images
Strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set colshares = ob1_miservice. execquery ("select * From win32_share ")
For each objshare in colshares
Wscript. Echo "name:" & objshare. Name
Wscript. Echo "Path:" & objshare. Path
Wscript. Echo "type:" & objshare. Type
Next
13. The TXT document is hard to learn.
Set ob1_miservice = GetObject ("winmgmts: \. \ Root \ cimv2 ")
Set colfiles = ob1_miservice. execquery ("select * From cim_datafile where Path = '\ Documents ents
And Settings \ Administrator \ Desktop \ 'and drive = 'e:' and extension = 'txt '")
Wscript. Echo "Number of. txt files found:" & colfiles. Count
For each AA in colfiles
NL = NL & vbcrlf & aa. Name
Next
Wscript. Echo NL
14. How can I display a dialog box for selecting documents to users?
Q:
Hi, scripting guy! Is there any way for me to use a script to display a dialog box for users to choose a document?
-- BF
A:
Hello, BF. If you are using Windows 2000, we do not know how to implement this operation, at least
Sample method. However, if you are using Windows XP, the situation is different. On Windows XP, you can use
The "useraccounts. commondialog" Object displays a standard "document open" dialog box to users. The following code can be used: Code
Script:
Set objdialog = Createobject ("useraccounts. commondialog ")
Objdialog. Filter = "all files | *. *" objdialog. initialdir = "C: \" intresult =
Objdialog. showopen
If intresult = 0 then wscript. Quit else wscript. Echo objdialog. filename end if
This is a small script, so let's explain it line by line. First, create a useraccounts. commondialog object.
Object Reference (named "objdialog "). Next, we configure the "filter" attribute in the dialog box. We want to display any document
Configure the filter as follows:
Objdialog. Filter = "all files | *.*"
What should we do if we only want to display text documents? In this case, we will use the following filters:
Objdialog. Filter = "text files | *. txt"
You may be able to see how it runs: We provide instructions for document types (text files) and insert a vertical Separator
(|), And then use a standard wildcard to indicate any. txt document (*. txt ). Do you want to display the. txt document by default?
Does the user provide the option to view any documentation? The following code can be used:
Objdialog. Filter = "text files | *. txt | all files | *.*"
Try it and you will understand what we mean.
Then, we specify the default document folder. By default, we want the dialog box to display the document in the root folder of drive C
Configure the "initialdir" attribute as follows:
Objdialog. initialdir = "C :\"
Do you want to display the documents in the C: \ Windows folder? The following code can be used:
Objdialog. initialdir = "C: \ Windows"
Don't worry: this is a real "Open Document" dialog box, so you can click and stop at will. From
C: \ Windows does not mean that you can only open the document in this document folder.
Finally, use the following line of code to display the dialog box:
Intresult = objdialog. showopen
Now, we only need to sit down and wait for the user to select the document and click "OK" (or wait for the user to click "cancel "). Assume that
If you click "cancel", the variable intresult is set to 0. In our script, we check the value of intresult, for example, 0.
, We only need to use wscript. Quit to terminate this script.
But what if the user selects the document and clicks "OK? In this case, intresult will be configured
-1. The "filedialog" attribute is configured as the path name of the selected document. Our script only returns the path name, which means we will get
Output is similar to the following:
C: \ windows \ prairie wind.bmp
Needless to say, you are not limited to only echo the document path. In fact, you can use WMI, FileSystemObject, or some other technology
To bind the document, and then perform operations such as delete, copy, compress, or retrieve document attributes on it-the operations you can perform on the document are not
All of them can be executed on him.
However, you must use the script in any case.
By the way, you can select only one document at a time, rather than holding down the "Ctrl" key to select multiple documents. There is one way
Multiple documents can be selected, at least on the XP computer, but we can only leave this question to a later column for discussion.
15. How do I determine under which account the process runs?
Q:
Hi, scripting guy! I have a script that returns information about any processes running on the computer, but I don't know how to get
Obtain the name of the user account under which these processes run. Can you help me?
-- DL
A:
Hello, DL. Yes, we can help you. Determining the account under which the process runs is actually quite simple, just how to execute it
This operation is not particularly obvious. If you are the same as most people, you may scan
To search for attributes named account, username, or similar. It is very difficult for you to find. The reason for this is:
Win32_process cannot tell you which account the process runs.
You need to use the "getowner" method to capture this information. The following script can tell you Microsoft Word (winword.exe)
Under which account to run:
Strcomputer = "." Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set colprocesslist = obw.miservice. execquery _ ("select * From win32_process where name =
'Winword.exe '")
For each objprocess in colprocesslist objprocess. getowner strusername, struserdomain
Wscript. Echo "process" & objprocess. Name & "is owned by" _ & struserdomain &"\"&
Strusername & "." Next
We are most interested in the following line of code:
Objprocess. getowner strnameofuser, struserdomain
What we are doing here is to call the "getowner" method. Getowner returns two "Output Parameters", one of which is responsible for the process
User name, a domain to which the user belongs. To capture these two output parameters, we need to provide two changes for the getowner method.
Quantity. In this example, we use two variables, strusername and struserdomain, respectively. The name can be
You can name the variable A and B, X and Y, or any other name you want.
However, the order of variables cannot be configured at will: the first value returned is always the user name, and the second value is always the domain. This means that if you want
Make sure that your code is the same as the following line of code:
Objprocess. getowner X, Y
After calling getowner, we can directly display the process name and anyone. Please note that we can use a little bit of tricks.
Domain \ User format. In this way, we can echo the name similar to "fabrikam \ kenmyer.
Another script is provided below, which can list any process on the computer together with any of the processes:
Strcomputer = "." Set ob1_miservice = GetObject ("winmgmts: \" & strcomputer & "\ Root \ cimv2 ")
Set colprocesslist = obw.miservice. execquery _ ("select * From win32_process ")
For each objprocess in colprocesslist objprocess. getowner strusername, struserdomain
Wscript. Echo "process" & objprocess. Name & "is owned by" _ & struserdomain &"\"&
Strusername & "." Next
It may be strange that January 3, 2005 is a formal day off for Microsoft employees. Why is there "hi" today?
, Scripting guy !" Column? This is only because of the incredible dedication and investment of Microsoft scripting experts.
Spirit. Or, it may be because a script expert-who can't tell him or her name-doesn't realize that today is a holiday, so
Come as usual (and at a.m !).
16 Can I copy the Script output to the clipboard?
Q:
Hi, scripting guy! Is there a way to copy the Script output to the clipboard?
-- ZW, Marseilles, France
A:
Hello, ZW. If you don't mind using some crazy solutions, it is quite easy to copy the Script output to the clipboard. First,
You need to construct a string containing the desired output. Then, create an Internet Explorer instance and
Open a blank page. Next, use the built-in functions of the Internet Explorer Object Model to copy strings to the clipboard.
You can use the clipboardData. setdata method to implement this technique. Sample scripts that copy some data to the clipboard, such
Below:
Strcopy = "this text has been copied to the clipboard ."
Set objie = Createobject ("internetexplorer. application ")
Objie. navigate ("about: blank ")
Objie.doc ument. parentwindow. clipboardData. setdata "text", strcopy
Objie. Quit
Run the script, open notepad, and click paste. The copied string is displayed.
By the way, everything is happening behind the scenes, and Internet Explorer does not actually appear on the screen. This is because
Yes. By default, any ie instances created using scripts are hidden at runtime, unless you use the following statement to display them
Come:
Objie. Visible = true

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.