0

I work in a hospital environment and right now im doing PC deployments. Part of the deployment requires us to view 2 files on a network drive looking for information regarding the old systems. They use specific ports and or TTY's to view information in each department.

I am trying to create a VBS file that can open 2 files in 2 different notepad windows. The first one opens up but the pcview.cfg keeps giving me an error. Im trying to link to the same location that the HBOWEM32 is pointed to. Can anyone solve? For security reasons I have taken out the exact location of the network drive. The code below prompts for a specific folder name which is the old pc name. After entering that data it opens the HBOWEM32 files fine but says it cannot find the other part. I Have manually looked inside the folder and the pcview.cfg file DOES exist. I just want a faster way of opening these rather than brute forcing through the run prompt.

Here is the code.

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""")

1 Answers1

2
  1. Use Option Explicit
  2. Don't create variables you don't use (WshShell, objShell)
  3. Improve your variable names (strFlag seems to be a computer name, strWeb seems to be the full specification of a file)
  4. Don't lump different info into one variable (strWeb contains the folder path to re-use and the specific file name)
  5. Use diagnostics output (at least while developing)

In code:

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

(not tested, please be carefull)

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • gives me and error code when i try to run Line:3 Char:1 Error: Expected Statement Code: 800A0400 Source: Microsoft VBScript Compilation Error – BigBrutalisk Apr 10 '13 at 15:17