24

I get a compilation error when I try to run the following vbs code from a command prompt in Windows 7.

Option Explicit
Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3
Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, strUserName

Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName 

strDriveLetter1 = "H:"
strDriveLetter2 = "P:"
strDriveLetter3 = "S:"
strRemotePath1 = "\\test\public\users\" & strUserName & "\"
strRemotePath2 = "\\test\public\groups\"
strRemotePath3 = "\\test\scans\"


'Section which maps two drives, M: and P: and S:
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3

'Extra code just to add a message box
WScript.Echo "Map drives " & strDriveLetter1 & " & " & strDriveLetter2 & " & " & strDriveLetter3

Wscript.Quit

It says the issue is with Line 1 Char 1. Any ideas?

Mike
  • 2,561
  • 7
  • 34
  • 56

3 Answers3

67

A possible problem is how your file was encoded; try to save it as ANSI and run it again.

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162
23

FYI for those with the same problem in the future, to fix this:

  1. Open the .vbs in notepad
  2. Go to file and "save as"
  3. Right under the file name box, you will see a drop down menu for encoding. Choose ANSI.
Ammar
  • 1,068
  • 2
  • 13
  • 20
0

Check you are not using extended charater like á é í ó ú ñ in a variable's name

  • 1
    When this error is thrown, it's not specifically because of variable names, but by the simple fact that there's an unsupported character contained in the file (which should be encoded to ANSI to work). – Yuuza Aug 27 '15 at 04:26