2013-04-10 144 views
0

我在医院环境中工作,现在正在进行PC部署。部分部署要求我们在网络驱动器上查看2个文件,以查找有关旧系统的信息。他们使用特定的端口和/或TTY来查看每个部门的信息。在记事本中打开ini文件和配置文件的VBScript

我想创建一个VBS文件,可以在2个不同的记事本窗口中打开2个文件。第一个打开,但pcview.cfg不断给我一个错误。我试图链接到HBOWEM32指向的相同位置。谁能解决?出于安全原因,我已经拿出了网络驱动器的确切位置。下面的代码提示输入一个特定的文件夹名称,这是旧的pc名称。输入数据后,它会打开HBOWEM32文件,但表示无法找到其他部分。我已经手动查看文件夹内和pcview.cfg文件存在。我只想要一个更快的方法来打开这些,而不是通过运行提示进行粗暴强制。

这是代码。

CONST strDir = "<Netowrk Location)" 
Dim WshShell 

set objShell = CreateObject("WScript.Shell") 
set objFSO = CreateObject("Scripting.FileSystemObject") 

function findFolder(strDir, strFlag) 
    set objFolder = objFSO.GetFolder(strDir) 
    for each objSubFolder in objFolder.SubFolders 
     if (inStr(objSubFolder.Name, strFlag)) then 
      findFolder = objSubFolder.Path 
      exit function 
     else   
      findFolder = findFolder (objSubFolder.Path, strFlag) 
     end if 
    next 
end function 

strFlag = inputBox("Enter Computer Name:") 
strWeb = findFolder(strDir, strFlag) & "\HBOWEM32.ini" 
objShell.Run strWeb 

Set WshShell = CreateObject ("WScript.Shell") 
WshShell.Run ("notepad.exe """ + "\\<same location as above>\Pcview.cfg""") 

回答

2
  1. 使用显式的选项
  2. 不要创建你不使用的变量(的WshShell,objShell)
  3. 提高你的变量名(strFlag似乎是一个计算机名称,strWeb似乎是文件的完整规范)
  4. 不要混为一谈不同的信息到一个变量(strWeb包含的文件夹路径,重新使用和具体的文件名)
  5. 使用诊断输出(至少在开发)

在代码:

Option Explicit 
...  
Dim strComputer : strComputer = InputBox("Enter Computer Name:") 
Dim strFolder : strFolder = findFolder(strDir, strComputer) 
Dim strIniFSpec : strIniFSpec = objFSO.BuildPath(strFolder, "HBOWEM32.ini") 
WScript.Echo "will run '" & strIniFSpec & "'" 
objShell.Run strIniFSpec 

Dim WshShell : Set WshShell = CreateObject("WScript.Shell") 
Dim strCfgFSpec : strCfgFSpec = objFSO.BuildPath(strFolder, "Pcview.cfg") 
Dim strCmd  : strCmd  = "notepad.exe """ & strCfgFSpec & """" 
WScript.Echo "will run '" & strCmd & "'" 
WshShell.Run strCmd 

(未测试,请小心)

+0

给我和错误代码时,我尝试运行 行:3 字符:1 错误:预期语句 代码:800A0400 来源:Microsoft VBScript编译错误 – BigBrutalisk 2013-04-10 15:17:58

+0

什么错误(数字,消息)? – 2013-04-10 15:19:40

相关问题