关于WSH在VB中的用法 这里,我们只讨论读写注册表和建立快捷方式。 首先在工程的References中选中Windows Scripting Host Object Model,再来看一下下面的代码。 Dim WSH_shell, urlLink, deskPath Set WSH_shell = New IWshShell_Class WSH_shell.RegWrite "HKLM\Software\ArchTide\", "first" ´以上两句新建了一个IWshShell_Class实例,然后在HKEY_LOCAL_MACHINE下 ´建立一个主键,并写入字符串值。注意应用HKCU代表HKEY_CURRENT_USER、 ´HKCR代表HKEY_CLASSES_ROOT,以此类推... ´与注册表相关的函数原型如下: ´Function RegRead(bstrName As String) 读注册表,bstrName为键名 ´Sub RegDelete(bstrName As String) 删除主键 ´Sub RegWrite(bstrName As String, pvValue, [pvarType]) ´[pvarType]可以省略,或为“REG_DWORD”、“REG_BINARY” deskPath = WSH_shell.SpecialFolders("Desktop") ´获得桌面路径 ´可以用WSH_shell.ExpandEnvironmentStrings("%windir%")获得Windows路径 Set urlLink = WSH_shell.CreateShortcut(deskPath & "\ok.lnk") With urlLink .TargetPath = deskPath & "\无标题.txt" .IconLocation = "D:\DevStudio\MyProjects\Desktop Arrow\Res\doc.ico" .Hotkey = "CTRL+SHIFT+D" .WorkingDirectory = deskPath ´起始位置 .WindowStyle = WshNormalFocus ´可以设的值有WshHide、WshMaximizedFocus、WshMinimizedFocus、 ´WshMinimizedNoFocus、WshNormalFocus、WshNormalNoFocus End With urlLink.Save ´保存快捷方式 |