VBS详细教程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VBS详细教程相关的知识,希望对你有一定的参考价值。
我要VBS的教程,要详细的,不要基础的,最好是入门的,有的人就发到我的邮箱来:240133914@qq.com 谢谢
发了之后我加分
1楼你发的是简明教程,网上一大把,学的也只是基础,我早就看过了的,。。
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.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 取得本机计算机名
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
Wscript.Echo objComputer.Name
Next
--------------------------------------------------------------------------------
4 检查升级包
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Echo objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion
Next
--------------------------------------------------------------------------------
5 检查 Hot Fix
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery ("Select * from Win32_QuickFixEngineering")
For Each objQuickFix in colQuickFixes
Wscript.Echo "Description: " & objQuickFix.Description
Wscript.Echo "Hot Fix ID: " & objQuickFix.HotFixID
Next
--------------------------------------------------------------------------------
6 检查本地管理员数目
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 磁盘系统
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = 3")
For Each objDisk in colDisks
Wscript.Echo "Disk drive: "& objDisk.DeviceID & " -- " & objDisk.FileSystem
Next
--------------------------------------------------------------------------------
8 检测自动登录是否开启
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 关闭自动登录
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 检查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 disabled."
Else
Wscript.Echo "The Guest account is enabled."
End If
--------------------------------------------------------------------------------
11 关闭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 检索本地共象
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.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 脚本检索一个文件夹下.txt文件 汗哦 值得学习
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colFiles = objWMIService.ExecQuery("SELECT * FROM CIM_DataFile WHERE Path = '\\Documents and Settings\\Administrator\\桌面\\' 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 我如何向用户显示一个用来选择文件的对话框?
问:
嗨,Scripting Guy!有没有什么方法可以让我使用脚本向用户显示一个对话框,供用户选择文件使用?
-- BF
答:
您好,BF。如果您使用的是 Windows 2000,我们不知道实现此操作的方法,至少操作系统中没有内置这样的方法。
但如果您使用的是 Windows XP,情况就不同了。在 Windows XP 上,
您可以使用“UserAccounts.CommonDialog”对象向用户显示一个标准的“文件打开”对话框。可以用类似以下代码的脚本:
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
这是一个小脚本,所以让我们逐行进行解释吧。我们首先创建一个对 UserAccounts.CommonDialog
对象的对象引用(名为“objDialog”)。接着,我们设置对话框的“筛选”属性。我们要显示所有文件,
所以我们将筛选设置成这样:
objDialog.Filter = "All Files|*.*"
假如我们只想显示文本文件,那该怎么办?在这种情况下,我们将使用以下筛选:
objDialog.Filter = "Text Files|*.txt"
您也许能够看出它是如何运行的:我们为文件类型提供说明 (Text Files),然后插入一个竖线分隔符 (|),
最后使用标准的通配符来指示所有 .txt 文件 (*.txt)。是不是想默认显示 .txt 文件,然后为用户提供查看所有文件的选项?
那么可以使用以下代码:
objDialog.Filter = "Text Files|*.txt|All Files|*.*"
试一试,您就明白我们的意思了。
然后,我们指定默认文件夹。默认情况下,我们希望对话框显示位于驱动器 C 的根文件夹中的文件,
所以我们这样设置“InitialDir”属性:
objDialog.InitialDir = "C:\"
希望显示 C:\Windows 文件夹中的文件吗?那么可以使用以下代码:
objDialog.InitialDir = "C:\Windows"
不必担心:这是一个真正的“文件打开”对话框,所以您可以随意单击,并且可以随时停下来。
您从 C:\Windows 开始并不意味着您只能打开该文件夹中的文件。
最后,我们使用下面这行代码显示对话框:
intResult = objDialog.ShowOpen
现在,我们只需坐下来,等待用户选择文件并单击“确定”(或者等待用户单击“取消”)。如果用户单击“取消”,
则变量 intResult 将被设置为 0。在我们的脚本中,我们检查 intResult 的值,如果是 0,
我们将只需要使用 Wscript.Quit 来终止此脚本。
但是如果用户实际上选择了文件并单击了“确定”,那该怎么办?在这种情况下,intResult 将被设置为 -1,
“FileDialog”属性将被设置为所选文件的路径名。我们的脚本只回显路径名,这意味着我们将得到类似以下内容的输出:
C:\WINDOWS\Prairie Wind.bmp
不用说,您并不局限于只回显文件路径。实际上,您可以使用 WMI、FileSystemObject 或一些其他技术来绑定该文件,
然后对其执行删除、复制、压缩或检索文件属性等操作 — 您对文件能够执行的操作差不多都可以对它执行。
但无论如何,您都需要使用脚本。
顺便说一句,使用此方法,您一次只能选择一个文件,而不能按住“Ctrl”键选择多个文件。有一种方法可以选择多个文件,
至少在 XP 计算机上可以,但是我们只能将此问题留到以后的专栏中讨论了。
--------------------------------------------------------------------------------
15 我如何确定进程是在哪个帐户下运行的?
问:
嗨,Scripting Guy!我有一个脚本,它返回关于计算机上运行的所有进程的信息,
只是我不知道如何获得这些进程在其下运行的用户帐户的名称。您可以帮助我吗?
-- DL
答:
您好,DL。是的,我们可以帮助您。确定进程是在哪个帐户下运行的,实际上相当简单,
只是如何着手执行此操作并不是特别显而易见的。如果您与大多数人一样,
那么您可能会通过扫描 Win32_Process 类的属性来查找名为 Account 或 UserName 或类似的属性。您很有可能找不到。
出现这种情况的原因是:Win32_Process 没有可以告诉您进程在哪个帐户下运行的属性。
您需要使用“GetOwner”方法来捕捉此信息。下面这个脚本可以告诉您 Microsoft Word (Winword.exe) 在哪个帐户下运行:
strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.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
我们最感兴趣的是下面这行代码:
objProcess.GetOwner strNameOfUser, strUserDomain
我们在此所做的就是调用“GetOwner”方法。GetOwner 返回两个“输出参数”,
一个返回负责该进程的用户的名称,一个返回该用户所属的域。为捕获这两个输出参数,我们需要为 GetOwner 方法提供两个变量。
在这个示例脚本中,我们使用了两个分别叫做 strUserName 和 strUserDomain 的变量。名称可以随意选择;您可以将变量称为 A 和 B 或 X 和 Y 或任何其他您想要的名称。
不过,变量的顺序不能随意设置:返回的第一个值总是用户名,第二个值总是域。这意味着,如果您希望用 X 表示用户名,用 Y 表示域,那么您要确保您的代码像下面这行代码一样:
objProcess.GetOwner X, Y
调用 GetOwner 之后,我们就可直接回显进程名和所有者。请注意,我们可以稍微来点儿花样儿 – 使用域\用户格式。这样,我们就可以回显类似于“fabrikam\kenmyer”的名称。
下面附带提供了另一个脚本,该脚本可以列出计算机上的所有进程以及各个进程的所有者:
strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.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
可能有人感到奇怪,2005 年 1 月 3 日正好是 Microsoft 员工的正式休息日。
那么今天为什么会有“嗨,Scripting Guy!”专栏?这只能是由于 Microsoft 脚本专家表现出来的对工作的难以置信的奉献和投入精神。
或者,也可能是由于某个脚本专家 – 还说不出他或她的名字 – 没有意识到今天是假日,所以照常来了(而且是在早上 7 点啊!)。
--------------------------------------------------------------------------------
16 可以将脚本的输出复制到剪贴板吗?
问:
嗨,Scripting Guy!有办法将脚本输出复制到剪贴板吗?
-- ZW, Marseilles, France
答:
您好,ZW.如果您不介意用一些疯狂的解决方法,那么实际上将脚本输出复制到剪贴板相当容易。
首先,您需要构造一个字符串,其中包含想要的输出。然后,创建 Internet Explorer 的一个实例,
然后在其中打开一个空白页。接着,利用 Internet Explorer 对象模型的内置功能,将字符串复制到剪贴板;
特别是, 可以使用 clipboardData.SetData 方法来实现这个技巧。将某些数据复制到剪贴板的示例脚本如下:
strCopy = "This text has been copied to the clipboard."
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate("about:blank")
objIE.document.parentwindow.clipboardData.SetData "text", strCopy
objIE.Quit
运行脚本,然后打开 Notepad,然后单击“粘贴”;应该可以看到所复制的字符串。
顺便说一下,所有这一切都是在“幕后”发生的,Internet Explorer 并不会真的出现在屏幕上。
这是因为,在默认情况下,通过脚本创建的任何 IE 实例在运行时都是隐藏的,除非您利用如下语句将其显示出来:
objIE.Visible = True 参考技术A 哈哈 进我的空间吧 绝对会有意想不到的收获。 空间里整合了不少VBS的技巧 如VBS网络操作 系统控制 文件操作 还有VBS界面等。个人学了一年的VBS 感觉VBS其实本身挺容易 算法一般简单 关键还是资料的搜集有点难度。 下面几点是我个人学习VBS的感受和建议:
1)提高VBS的水平,最好的方法莫过于去百度知道上尝试着去回答各类关于VBS的问题。光看教程是没用的,在练习和比较的过程中才可以提高水平达到融会贯通。
1) VBS毕竟是脚本,能力有限(功能少 这个你以后会体会到,限制多 比如说访问剪贴板都有限制。),不过VBS和VB倒是有很多相同之处,可以作为跳板学习VB。
2) VBS本身没有界面之类的,不过可以结合html和简单的jscript做界面。但是你会发现用html做界面的话 一个很严重的问题就是VBS不能后台运行 即响应了当前事件后 必须等到这个事件处理完才可以处理下一个事件 从而使程序假死 解决的终极方案是做成HTA的文件 结合复杂点jscript可以实现多线程和后台运行 界面可以做的非常华丽。
附简单的VBS+HTML做有控件的界面程序。
URL:http://blog.csdn.net/zshwlw/archive/2008/05/23/2474485.aspx
还有很多很多问题吧,这里就不详细的说了。 楼主以后要是有什么问题的话,或许我可以帮你。本回答被提问者采纳 参考技术B 我已经发过去了
vbs中namespace的用法
Set objshell = CreateObject("Shell.Application")
Set objNS = objshell.namespace(&h2f)
Set colitems = objNS.items
For Each objitem In colitems
WScript.Echo objitem.name
Next
这里面的namespace的详细用法。objNS的所有属性!
Set objNS = objshell.namespace(&h2f)什么意思?
namespace的参数可以是表示各种路径的字符串,如"c:\\test"等;也可以是表示特殊路径的ShellSpecialFolderConstants,其值见此网页:
http://msdn.microsoft.com/en-us/library/bb774096(VS.85).aspx
关于objNS的属性,可以在vbsedit这个工具中一览无余:
参考技术A Shell.Application组件使用详解1、创建 Shell 对象
var Shell = new ActiveXObject("Shell.Application");
2、使用 Shell 属性及方法
Shell.Application
Shell.Parent
Shell.CascadeWindows()
Shell.TileHorizontally()
Shell.TileVertically()
Shell.ControlPanelItem(sDir) /* 比如:sysdm.cpl */
Shell.EjectPC()
Shell.Explore(vDir)
Shell.Open(vDir)
Shell.FileRun()
Shell.FindComputer()
Shell.FindFiles()
Shell.Help()
Shell.MinimizeAll()
Shell.UndoMinimizeALL()
Shell.RefreshMenu()
Shell.SetTime()
Shell.TrayProperties()
Shell.ShutdownWindows()
Shell.Suspend()
oWindows = Shell.Windows() /* 返回ShellWindows对象 */
fFolder = Shell.NameSpace(vDir) /* 返回所打开的vDir的Folder对象 */
oFolder = Shell.BrowseForFolder(Hwnd, sTitle, iOptions [, vRootFolder]) /* 选择文件夹对话框 */
/*示例:
function BrowseFolder()
var Message = "清选择文件夹";
var Shell = new ActiveXObject( "Shell.Application" );
var Folder = Shell.BrowseForFolder(0,Message,0x0040,0x11);
if(Folder != null)
Folder = Folder.items(); // 返回 FolderItems 对象
Folder = Folder.item(); // 返回 Folderitem 对象
Folder = Folder.Path; // 返回路径
if(Folder.charAt(varFolder.length-1) != "\\")
Folder = varFolder + "\\";
return Folder;
*/
/*示例:
var Folder = Shell.NameSpace("C:\\"); // 返回 Folder对象
*/
3、使用 Folder 对象
[ oApplication = ] Folder.Application // Contains the Application object.
[ oParentFolder= ] Folder.ParentFolder // Contains the parent Folder object.
[ oTitle = ] Folder.Title // Contains the title of the folder.
Folder.CopyHere(vItem [, vOptions]) // Copies an item or items to a folder.
Folder.MoveHere(vItem [, vOptions]) // Moves an item or items to this folder.
/*
vItem: Required. Specifies the item or items to move. This can be a string that represents a file name, a FolderItem object, or a FolderItems object.
vOptions Optional. Specifies options for the move operation. This value can be zero or a
combination of the following values. These values are based upon flags defined for use with the
fFlags member of the C++ SHFILEOPSTRUCT structure. These flags are not defined as such for
Microsoft? Visual Basic?, Visual Basic Scripting Edition (VBScript), or Microsoft JScript?, so you
must define them yourself or use their numeric equivalents.
4 Do not display a progress dialog box.
8 Give the file being operated on a new name in a move, copy, or rename operation if a file with
the target name already exists.
16 Respond with "Yes to All" for any dialog box that is displayed.
64 Preserve undo information, if possible.
128 Perform the operation on files only if a wildcard file name (*.*) is specified.
256 Display a progress dialog box but do not show the file names.
512 Do not confirm the creation of a new directory if the operation requires one to be created.
1024 Do not display a user interface if an error occurs.
2048 Version 4.71. Do not copy the security attributes of the file.
4096 Only operate in the local directory. Don't operate recursively into subdirectories.
9182 Version 5.0. Do not move connected files as a group. Only move the specified files.
*/
Folder.NewFolder(bName) // Creates a new folder.
ppid = Folder.ParseName(bName) // Creates and returns a FolderItem object that represents a specified item.
/*
bName: Required. A string that specifies the name of the item.
*/
oFolderItems = Folder.Items() // Retrieves a FolderItems object that represents the collection of items in the folder.
sDetail = Folder.GetDetailsOf(vItem, iColumn) // Retrieves details about an item in a folder. For example, its size, type, or the time of its last modification.
/*
vItem: Required. Specifies the item for which to retrieve the information. This must be a FolderItem object.
iColumn: Required. An Integer value that specifies the information to be retrieved. The
information available for an item depends on the folder in which it is displayed. This value
corresponds to the zero-based column number that is displayed in a Shell view. For an item in the
file system, this can be one of the following values:0 Retrieves the name of the item.
1 Retrieves the size of the item.
2 Retrieves the type of the item.
3 Retrieves the date and time that the item was last modified.
4 Retrieves the attributes of the item.
-1 Retrieves the info tip information for the item.
*/
4、使用 FolderItems 对象
/*示例:
var FolderItems = Shell.NameSpace("C:\\").Items(); // 返回 FolderItems 对象
*/
[ oApplication = ] FolderItems.Application
[ iCount = ] FolderItems.Count
[ oParent = ] FolderItems.Parent
oFolderItem = FolderItems.Item([iIndex]) // 返回 FolderItem 对象
5、使用 FolderItem 对象
/*示例:
var FolderItem = Shell.NameSpace("C:\\").Items().Item(iIndex); // 返回 FolderItems 对象
*/
[ oApplication = ] FolderItem.Application
[ oParent = ] FolderItem.Parent
[ sName = ] FolderItem.Name(sName) [ = sName ]
[ sPath = ] FolderItem.Path
[ iSize = ] FolderItem.Size
[ sType = ] FolderItem.Type
[ bIsLink = ] FolderItem.IsLink
[ bIsFolder = ] FolderItem.IsFolder
[ bIsFileSystem = ] FolderItem.IsFileSystem
[ bIsBrowsable = ] FolderItem.IsBrowsable
[ oGetLink = ] FolderItem.GetLink // 返回 ShellLinkObject 对象
[ oGetFolder = ] FolderItem.GetFolder // 返回 Folder 对象
[ oModifyDate= ] FolderItem.ModifyDate(oModifyDate) [ = oModifyDate ] // Sets or retrieves the date and time that the item was last modified.
vVerb = FolderItem.Verbs() // 返回 FolderItemVerbs 对象. This object is the collection of verbs
that can be executed on the item.
FolderItem.InvokeVerb( [vVerb]) // Executes a verb on the item.
6、使用 FolderItemVerbs 对象
/*示例:
var FolderItem = Shell.NameSpace("C:\\").Items().Item(iIndex).Verbs(); // 返回 FolderItems 对象
*/
[ oApplication = ] FolderItemVerbs.Application
[ oParent = ] FolderItemVerbs.Parent
[ iCount = ] FolderItemVerbs.Count
oVerb = FolderItemVerbs.Item( [iIndex]) // 返回 FolderItemVerb 对象.
7、使用 FolderItemVerb 对象
/*示例:
var FolderItem = Shell.NameSpace("C:\\").Items().Item(iIndex).Verbs().Item(iIndex); // 返回 FolderItems 对象
*/
[ oApplication = ] FolderItemVerbs.Application
[ oParent = ] FolderItemVerbs.Parent
[ oName = ] FolderItemVerbs.Name
FolderItemVerb.DoIt() // Executes a verb on the FolderItem associated with the verb.
8、使用 ShellLinkObject 对象
[ sWorkingDirectory = ]ShellLinkObject.WorkingDirectory(sWorkingDirectory) [ = sWorkingDirectory ]
[ intShowCommand = ]ShellLinkObject.ShowCommand(intShowCommand) [ = intShowCommand ]
/*
intShowCommand Integer that specifies or receives the link's show state. This can be one of the
following values.
1 Activates and displays a window. If the window is minimized or maximized, the system restores
it to its original size and position.
2 Activates the window and displays it as a minimized window.
3 Activates the window and displays it as a maximized window.
*/
[ sArguments = ] ShellLinkObject.Arguments(sArguments) [ = sArguments ]
[ sDescription = ] ShellLinkObject.Description(sDescription) [ = sDescription ]
[ iHotkey = ] ShellLinkObject.Hotkey(iHotkey) [ = iHotkey ]
/*
iHotkey Integer that specifies or receives the link's hot key code. The virtual key code is in
the low-order byte, and the modifier flags are in the high-order byte. The modifier flags can be a
combination of the following values.
1 SHIFT key
2 CTRL key
4 ALT key
8 Extended key
*/
[ sPath = ] ShellLinkObject.Path(sPath) [ = sPath ]
iIcon = ShellLinkObject.GetIconLocation(sPath)
ShellLinkObject.Resolve(fFlags)
/*
fFlags Required. Flags that specify the action to be taken. This can be a combination of the following values.
1 Do not display a dialog box if the link cannot be resolved. When this flag is set, the high-
order word of fFlags specifies a time-out duration, in milliseconds. The method returns if the link
cannot be resolved within the time-out duration. If the high-order word is set to zero, the time-out
duration defaults to 3000 milliseconds (3 seconds).
4 If the link has changed, update its path and list of identifiers.
8 Do not update the link information.
16 Do not execute the search heuristics.
32 Do not use distributed link tracking.
64 Disable distributed link tracking. By default, distributed link tracking tracks removable
media across multiple devices based on the volume name. It also uses the Universal Naming Convention
(UNC) path to track remote file systems whose drive letter has changed. Setting this flag disables
both types of tracking.
128 Call the Microsoft? Windows? Installer.
*/
ShellLinkObject.Save( [sFile])
ShellLinkObject.SetIconLocation(sPath, iIndex)
/*
sPath Required. String value that contains the fully qualified path of the file that contains the icon.
iIndex Required. Integer that is set to the index of the icon in the file specified by sPath.
*/
9、使用 ShellWindows 对象
[ intCount = ] ShellWindows.Count
oShellWindows = ShellWindows._NewEnum() // Creates and returns a new ShellWindows object that is a copy of this ShellWindows object.
oFolder = ShellWindows.Item( [iIndex]) // Retrieves an InternetExplorer object that represents the Shell window.
10、说明
通过第一步创建 Shell 对象,并进行相关函数调用,就可以返回以上各种对象,并进行相关操作。
另外,在学习的过程中,发现了两个在msdn中提及却没相关的函数:
ShellApp.ShellExecute("cmd.exe");
ShellApp.NameSpace(vDir).Items().InvokeVerbEx(vVerb); /*vVerb:如delete*/
还有些特殊的用法:
//var myprinterfolder = Shell.NameSpace("shell:PrintersFolder");
//var mydocsfolder = Shell.NameSpace("shell:personal");
//var mycompfolder = Shell.NameSpace("shell:drivefolder");
//Shell.ShellExecute( "wiaacmgr.exe","/SelectDevice" );
//Shell.ShellExecute( "rundll32.exe", "shell32.dll,Control_RunDLL sysdm.cpl,,1" )
//Shell.ShellExecute( "rundll32.exe", "shell32.dll,Control_RunDLL netcpl.cpl,,1" );
//Shell.ShellExecute( "rundll32.exe", "shell32.dll,Control_RunDLL sysdm.cpl,,1" );
The following command will run Rundll32.exe.
Rundll32.exe <dllname>,<entrypoint>,<optional arguments>
The following code sample shows how to use the command.
Rundll32.exe Setupx.dll,InstallHinfSection 132 C:\Windows\Inf\Shell.inf
//Shell.ShowBrowserBar("C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1", true);
真不知道,没有公开的函数调用还有多少,而msdn给我们的使用的只是九牛一毛而已!
11、使用 Shell.UIHelper.1 对象
ShellUI = new ActiveXObject("Shell.UIHelper.1");
ShellUI.AddChannel(sURL)
ShellUI.AddFavorite(sURL [, vTitle])
bBool = ShellUI.IsSubscribed(sURL) // Indicates whether or not a URL is subscribed to.
ShellUI.AddDesktopComponent(sURL, sType [, Left] [, Top] [, Width] [, Height])
/*
sURL Required. A String value that specifies the URL of the new favorite item.
sType Required. A String value that specifies the type of item being added. This can be one of the following values:
image The component is an image.
website The component is a web site.
Left Optional. Specifies the position of the left edge of the component, in screen coordinates.
Top Optional. Specifies the position of the top edge of the component, in screen coordinates.
Width Optional. Specifies the width of the component, in screen units.
Height Optional. Specifies the height of the component, in screen units.
*/
Rundll 32.exe User.exe,ExitWindows
function FileSearch()
SearchAsst = new ActiveXObject("SearchAssistantOC.SearchAssistantOC");
SearchAsst.FindFilesOrFolders();
//ShellApp = new ActiveXObject("Shell.Application");
//ShellApp.ShowBrowserBar("C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1", true);
//与上效果相同
function PersonSearch()
SearchAsst = new ActiveXObject("SearchAssistantOC.SearchAssistantOC");
SearchAsst.FindPeople();
function ShellExecuteExe()
ShellApp = new ActiveXObject("Shell.Application");
//var myprinterfolder = shell.NameSpace("shell:PrintersFolder");
//var mydocsfolder = shell.NameSpace("shell:personal");
//var mycompfolder = shell.NameSpace("shell:drivefolder");
//ShellApp.ShowBrowserBar("C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1", true);
ShellApp.ShellExecute("cmd.exe");
//ShellApp.ShellExecute("wiaacmgr.exe","/SelectDevice");
//ShellApp.ShellExecute("rundll32.exe", "shell32.dll,Control_RunDLL sysdm.cpl,,1")
//ShellApp.ShellExecute("rundll32.exe", "shell32.dll,Control_RunDLL netcpl.cpl,,1");
//ShellApp.ShellExecute("rundll32.exe", "shell32.dll,Control_RunDLL sysdm.cpl,,1");
//对于FolderItems对象可以用InvokeVerbEx Method
//ShellApp.NameSpace("c:\\xxx").Items().InvokeVerbEx("delete");
//而通过InvokeVerb(x.Items().Item(0).Verbs().Item(i).Name);可以访问某个命令
// win = ShellApp.NameSpace("c:\\xxx").Items().Item(0)
// e = win.Verbs();
// for(i=0;i<e.Count;i++)
// document.writeln(e.Item(i).Name);
//
// win.InvokeVerb(e.Item(0).Name);
//=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
//
// BindToSA
//
// Bind to the specified url and return the cdo object for it.
//
function BindToSA(szURL)
var adModeRead = 1;
var oDoc = new ActiveXObject("CDO.KnowledgeStartAddress")
oDoc.DataSource.Open(szURL, null, adModeRead, -1, 0, "", "")
return oDoc;
//=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
//
// BindToUrl
//
// Bind to the specified url and return the cdo object for it.
//
function BindToUrl(szURL)
var adModeRead = 1;
var oDoc = new ActiveXObject("CDO.KnowledgeDocument")
oDoc.DataSource.Open(szURL, null, adModeRead, -1, 0, "", "")
return oDoc;
function Msg(str)
//<object id=FolderControl classid="clsid:787e8fd0-7ad6-11d3-83da-00c04f505f43" style="position: absolute; left: 0px; top: 0px; visibility: hidden;">
//var FolderControl = new ActiveXObject("Tahoe.FolderControl");
FolderControl.TraceMsg(str);
ShellApp = new ActiveXObject("Shell.Application");
//ShellApp.ShowBrowserBar("C4EE31F3-4768-11D2-BE5C-00A0C9A83DA1", true);
//ShellApp.ShellExecute("Rundll32.exe","shell32.dll,SHCreateLocalServerRunDll 601ac3dc-786a-4eb0-bf40-ee3521e70bfb");
//ShellApp.ShellExecute("Rundll32.exe","shdocvw.dll,OpenURL");//Internet 快捷方式
//ShellApp.ShellExecute("Rundll32.exe","msconf.dll,OpenConfLink");//SpeedDial
//ShellApp.ShellExecute("Rundll32.exe","zipfldr.dll,RouteTheCall");//压缩文件夹shdocvw.dll,OpenURL
//ShellApp.ShellExecute("Rundll32.exe","netplwiz.dll,UsersRunDll");//用户帐户
//ShellApp.ShellExecute("Rundll32.exe","shell32.dll,Options_RunDLL 0");//文件夹选项
//ShellApp.ShellExecute("Rundll32.exe","shell32.dll,Options_RunDLL 1");//显示任务栏和开始菜单
//ShellApp.ShellExecute("rundll32.exe", "shell32.dll,Control_RunDLL sysdm.cpl,,1")appwiz.cpl,NewLinkHere
//ShellApp.ShellExecute("rundll32.exe", "shell32.dll,Control_RunDLLAsUser")
//ShellUI = new ActiveXObject("Shell.UIHelper.1");
//ShellUI.AddFavorite("http://www.microsoft.com/msdn","MSDN")
//ShellUI.AddChannel("http://www.microsoft.com/")
ShellApp.ShellExecute("c:\\windows\\system32\\mshta.exe","C:\\xx.hta")
//var s = ShellApp.ShellExecute("rundll32.exe", "kernel32.dll,GetVersionExA"+","+so);
/*var p = "C:\\"
sha = new ActiveXObject("Shell.Application");
var g = sha.NameSpace(p).Items().Item("xxx");
var v = g.Verbs();
var str=null;
for(i=0;i<v.Count;i++)
str = v.item(i).Name;
if(str.search("重命名")!=-1)break;
str = null
if(str)
g.InvokeVerbEx(str,"c:\\xx");
else
alert('no')
//g.InvokeVerbEx("重命名","xx");
*/本回答被提问者采纳
以上是关于VBS详细教程的主要内容,如果未能解决你的问题,请参考以下文章