应用 WSH 读写注册表和建立快捷方式

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 wxj_lake 的 blog

关于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 '保存快捷方式

  wsh的功能很强大,还有许多应用不是一时讲得完的,大家好好发掘吧^_^

本文关键:应用 WSH 读写注册表和建立快捷方式
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top