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 = "\testpublicusers" & strUserName & ""
strRemotePath2 = "\testpublicgroups"
strRemotePath3 = "\testscans"
'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?
Troubleshooting Code 800A0408 – Invalid Character
Introduction to Code 800A0408
This error code, 800A0408 occurs when you execute a VBScript. A wild guess a problem with an apostrophe, possibly in a ‘REM statement.
The Symptoms You Get
The script does not execute as you had hoped. Instead you get a WSH message box like this picture:
The Cause of error 800A0408
Your VBScript contains an illegal character, often at the beginning of a line. It can happen if you copy the script from word, then paste into notepad. For example, to ‘Rem out a line we need the apostrophe, which is ASCII character 39; however if you paste from word you may get ASCII 96 (Grave accent).
Note the clue Source: Microsoft VBScript compilation error, this means a syntax error in your script.
The Solutions
Check the punctuation marks in your VBScript, particularly look out for apostrophes and commas that do not display correctly. The reference to Line: 1 Char 1, means that the very first symbol that is probably wrong.
‡
Example 1 of error code 800A0408 – Invalid Character
Note: The error ‘Rem VBScript
It should be ‘ Rem VBScript
‘ Rem VBScript
Set WshShell = WScript.CreateObject(«WScript.Shell»)
Set WshNetwork = WScript.CreateObject(«WScript.Network»)
Set AllDrives = WshNetwork.EnumNetworkDrives()
DriveLetter = «N:» ‘must be capitalized
RemotePath = «alanhome»
AlreadyConnected = False
For i = 0 To AllDrives.Count – 1 Step 2
If AllDrives.Item(i) = DriveLetter Then AlreadyConnected = True
Next
If AlreadyConnected = False then
WShNetwork.MapNetworkDrive DriveLetter, RemotePath
WshShell.PopUp «Drive » & DriveLetter & » connected successfully.»
Else
WShNetwork.RemoveNetworkDrive DriveLetter
WshShell.PopUp «Drive » & DriveLetter & » disconnected.»
End if
»
Example 2 Code 800A0408 – Invalid Character
I include this screen shot just to emphasise that Char: number need not be one. Thus Char: 20, or what ever your char number is, becomes a big clue in tracing obscure characters that may have sneaked into your script.
See More Windows Update Error Codes 8004 Series
• Error 800A101A8 Object Required •Error 800A0046 •Error 800A10AD •Error 800A000D
• Error 80048820 •Error 800A0401 •Review of SolarWinds Permissions Monitor
• Error 80040E14 • Error 800A03EA • Error 800A0408 • Error 800A03EE
Guy Recommends: WMI Monitor and It’s Free!
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems. Fortunately, SolarWinds have created the WMI Monitor so that you can examine these gems of performance information for free. Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.
Download your free copy of WMI Monitor
Do you need additional help?
- For interpreting the WSH messages check Diagnose 800 errors.
- For general advice try my 7 Troubleshooting techniques.
- See master list of 0800 errors.
- Codes beginning 08004…
- Codes beginning 08005…
- Codes beginning 08007…
- Codes beginning 0800A…
Give something back?
Would you like to help others? If you have a good example of this error, then please email me, I will publish it with a credit to you:
If you like this page then please share it with your friends
Troubleshooting Code 800A0408 – Invalid Character
Introduction to Code 800A0408
This error code, 800A0408 occurs when you execute a VBScript. A wild guess a problem with an apostrophe, possibly in a ‘REM statement.
The Symptoms You Get
The script does not execute as you had hoped. Instead you get a WSH message box like this picture:
The Cause of error 800A0408
Your VBScript contains an illegal character, often at the beginning of a line. It can happen if you copy the script from word, then paste into notepad. For example, to ‘Rem out a line we need the apostrophe, which is ASCII character 39; however if you paste from word you may get ASCII 96 (Grave accent).
Note the clue Source: Microsoft VBScript compilation error, this means a syntax error in your script.
The Solutions
Check the punctuation marks in your VBScript, particularly look out for apostrophes and commas that do not display correctly. The reference to Line: 1 Char 1, means that the very first symbol that is probably wrong.
‡
Example 1 of error code 800A0408 – Invalid Character
Note: The error ‘Rem VBScript
It should be ‘ Rem VBScript
‘ Rem VBScript
Set WshShell = WScript.CreateObject(«WScript.Shell»)
Set WshNetwork = WScript.CreateObject(«WScript.Network»)
Set AllDrives = WshNetwork.EnumNetworkDrives()
DriveLetter = «N:» ‘must be capitalized
RemotePath = «alanhome»
AlreadyConnected = False
For i = 0 To AllDrives.Count – 1 Step 2
If AllDrives.Item(i) = DriveLetter Then AlreadyConnected = True
Next
If AlreadyConnected = False then
WShNetwork.MapNetworkDrive DriveLetter, RemotePath
WshShell.PopUp «Drive » & DriveLetter & » connected successfully.»
Else
WShNetwork.RemoveNetworkDrive DriveLetter
WshShell.PopUp «Drive » & DriveLetter & » disconnected.»
End if
»
Example 2 Code 800A0408 – Invalid Character
I include this screen shot just to emphasise that Char: number need not be one. Thus Char: 20, or what ever your char number is, becomes a big clue in tracing obscure characters that may have sneaked into your script.
Guy Recommends: WMI Monitor and It’s Free!
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems. Fortunately, SolarWinds have created the WMI Monitor so that you can examine these gems of performance information for free. Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.
Download your free copy of WMI Monitor
Do you need additional help?
- For interpreting the WSH messages check Diagnose 800 errors.
- For general advice try my 7 Troubleshooting techniques.
- See master list of 0800 errors.
- Codes beginning 08004…
- Codes beginning 08005…
- Codes beginning 08007…
- Codes beginning 0800A…
Give something back?
Would you like to help others? If you have a good example of this error, then please email me, I will publish it with a credit to you:
If you like this page then please share it with your friends
Troubleshooting Code 800A0408 – Invalid Character
Introduction to Code 800A0408
This error code, 800A0408 occurs when you execute a VBScript. A wild guess a problem with an apostrophe, possibly in a ‘REM statement.
The Symptoms You Get
The script does not execute as you had hoped. Instead you get a WSH message box like this picture:
The Cause of error 800A0408
Your VBScript contains an illegal character, often at the beginning of a line. It can happen if you copy the script from word, then paste into notepad. For example, to ‘Rem out a line we need the apostrophe, which is ASCII character 39; however if you paste from word you may get ASCII 96 (Grave accent).
Note the clue Source: Microsoft VBScript compilation error, this means a syntax error in your script.
The Solutions
Check the punctuation marks in your VBScript, particularly look out for apostrophes and commas that do not display correctly. The reference to Line: 1 Char 1, means that the very first symbol that is probably wrong.
‡
Example 1 of error code 800A0408 – Invalid Character
Note: The error ‘Rem VBScript
It should be ‘ Rem VBScript
‘ Rem VBScript
Set WshShell = WScript.CreateObject(«WScript.Shell»)
Set WshNetwork = WScript.CreateObject(«WScript.Network»)
Set AllDrives = WshNetwork.EnumNetworkDrives()
DriveLetter = «N:» ‘must be capitalized
RemotePath = «alanhome»
AlreadyConnected = False
For i = 0 To AllDrives.Count – 1 Step 2
If AllDrives.Item(i) = DriveLetter Then AlreadyConnected = True
Next
If AlreadyConnected = False then
WShNetwork.MapNetworkDrive DriveLetter, RemotePath
WshShell.PopUp «Drive » & DriveLetter & » connected successfully.»
Else
WShNetwork.RemoveNetworkDrive DriveLetter
WshShell.PopUp «Drive » & DriveLetter & » disconnected.»
End if
»
Example 2 Code 800A0408 – Invalid Character
I include this screen shot just to emphasise that Char: number need not be one. Thus Char: 20, or what ever your char number is, becomes a big clue in tracing obscure characters that may have sneaked into your script.
See More Windows Update Error Codes 8004 Series
• Error 800A101A8 Object Required •Error 800A0046 •Error 800A10AD •Error 800A000D
• Error 80048820 •Error 800A0401 •Review of SolarWinds Permissions Monitor
• Error 80040E14 • Error 800A03EA • Error 800A0408 • Error 800A03EE
Guy Recommends: WMI Monitor and It’s Free!
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems. Fortunately, SolarWinds have created the WMI Monitor so that you can examine these gems of performance information for free. Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.
Download your free copy of WMI Monitor
Do you need additional help?
- For interpreting the WSH messages check Diagnose 800 errors.
- For general advice try my 7 Troubleshooting techniques.
- See master list of 0800 errors.
- Codes beginning 08004…
- Codes beginning 08005…
- Codes beginning 08007…
- Codes beginning 0800A…
Give something back?
Would you like to help others? If you have a good example of this error, then please email me, I will publish it with a credit to you:
If you like this page then please share it with your friends
- Remove From My Forums
-
Question
-
Hello, reviving an old one on this forum: http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/special-characters-in-vbscript-strings/ and
also as posted on: http://itknowledgeexchange.techtarget.com/itanswers/escaping-special-characters-in-run-with-administrator-privileges-script/I used this script:
Here is a VB Script Vall Script that will get around the Password Prompt when «RunAs» is called…
‘Start
‘————————————————————————————
‘ To Run other VB Scripts or even Batch Files with Admin Priviliges’
‘———————————————————————————-
Dim WshShell, objFSO
suser
= «YourAdminAccount@YourDomain.com»sPass = «YourPassWord»
‘——————————————————————————————————————————————————————————————
‘Put your Domain Account and Password in between the qoutes, REMEMBER! the Password will be clear text. If this is a standalone just take off the @YourDomain.com
‘——————————————————————————————————————————————————————————————
sCommand = «wscript \UNCServerNameShareFolderYourScript.vbs»
‘—————————————————————————————————————————————————————————————————————
‘This will be the path were the scripted you want called will be at. Please note you can substitute the ablove for a local directory (Example: C:FolderYourScript.vbs)
‘————————————————————————————————————————————————————————————————————-
Set objComputer = CreateObject(«Shell.LocalMachine»)
Set WshNetwork = CreateObject(«WScript.Network»)
Set WshShell = CreatObject(«WScript.Shell»)
Set WshEnv = wshShell.Environment(«Process»)
WinPath = WshEnv(«SystemRoot»)&»System32runas.exe»
rc = WshShell.Run («runas /noprofile /user:» & suser & » » $ Chr(34) & sCommand & Chr(34))
WScript.Sleep 900
WshShell. AppActivate(WinPath)
WScript.quit
‘End
Answers
-
…
suser = «YourAdminAccount@YourDomain.com»
sPass = «YourPassWord»
…
rc = WshShell.Run («runas /noprofile /user:» & suser & » » $ Chr(34) & sCommand & Chr(34))
WScript.Sleep 900
WshShell. AppActivate(WinPath)
…This is definitely ill-advised. There is a reason the runas program does not accept a password on its command line. To quote
Raymond Chen:
The RunAs program demands that you type the password manually. Why doesn’t it accept a password on the command line?
This was a conscious decision. If it were possible to pass the password on the command line, people would start embedding passwords into batch files and logon scripts, which is laughably insecure.
In other words, the feature is missing to remove the temptation to use the feature insecurely.
In other words, you should not do this.
Bill
-
Proposed as answer by
Wednesday, May 2, 2012 6:16 PM
-
Marked as answer by
IamMred
Sunday, May 6, 2012 11:59 PM
-
Proposed as answer by
Problem
I am receiving the vbscript error “Invalid Character 800A0408 compilation error at Line 1 Char 1” while running a vbscript file which contains following code (this is just a sample code).
Option Explicit Dim strUser strUser = "Morgan" WScript.Echo "Hello ! " & strUser Wscript.Quit
I have received below error:
Script: C:Test.vbs Line: 1 Char: 1 Error: Invalid character Code: 800A0408 Source: Microsoft VBScript compilation error
Fix/Solution
This issue was occurs due to the Encoding method UTF-8 which I used to save the .vbs file. We should use the Encoding method ANSI to save .vbs file. Follow the below steps to fix this issue:
1. Open the vbscript file in Notepad
2. Go to File and click “Save as”
3. Under the file name, you will see a drop down menu for Encoding. Choose ANSI.
4. Save the file.
Guy Recommends: WMI Monitor and It’s Free!
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems. Fortunately, SolarWinds have created the WMI Monitor so that you can examine these gems of performance information for free. Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.
Download your free copy of WMI Monitor
Do you need additional help?
- For interpreting the WSH messages check Diagnose 800 errors.
- For general advice try my 7 Troubleshooting techniques.
- See master list of 0800 errors.
- Codes beginning 08004…
- Codes beginning 08005…
- Codes beginning 08007…
- Codes beginning 0800A…
Give something back?
Would you like to help others? If you have a good example of this error, then please email me, I will publish it with a credit to you:
If you like this page then please share it with your friends
- Remove From My Forums
-
Question
-
Hello, reviving an old one on this forum: http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/special-characters-in-vbscript-strings/ and
also as posted on: http://itknowledgeexchange.techtarget.com/itanswers/escaping-special-characters-in-run-with-administrator-privileges-script/I used this script:
Here is a VB Script Vall Script that will get around the Password Prompt when «RunAs» is called…
‘Start
‘————————————————————————————
‘ To Run other VB Scripts or even Batch Files with Admin Priviliges’
‘———————————————————————————-
Dim WshShell, objFSO
suser
= «YourAdminAccount@YourDomain.com»sPass = «YourPassWord»
‘——————————————————————————————————————————————————————————————
‘Put your Domain Account and Password in between the qoutes, REMEMBER! the Password will be clear text. If this is a standalone just take off the @YourDomain.com
‘——————————————————————————————————————————————————————————————
sCommand = «wscript \UNCServerNameShareFolderYourScript.vbs»
‘—————————————————————————————————————————————————————————————————————
‘This will be the path were the scripted you want called will be at. Please note you can substitute the ablove for a local directory (Example: C:FolderYourScript.vbs)
‘————————————————————————————————————————————————————————————————————-
Set objComputer = CreateObject(«Shell.LocalMachine»)
Set WshNetwork = CreateObject(«WScript.Network»)
Set WshShell = CreatObject(«WScript.Shell»)
Set WshEnv = wshShell.Environment(«Process»)
WinPath = WshEnv(«SystemRoot»)&»System32runas.exe»
rc = WshShell.Run («runas /noprofile /user:» & suser & » » $ Chr(34) & sCommand & Chr(34))
WScript.Sleep 900
WshShell. AppActivate(WinPath)
WScript.quit
‘End
Answers
-
…
suser = «YourAdminAccount@YourDomain.com»
sPass = «YourPassWord»
…
rc = WshShell.Run («runas /noprofile /user:» & suser & » » $ Chr(34) & sCommand & Chr(34))
WScript.Sleep 900
WshShell. AppActivate(WinPath)
…This is definitely ill-advised. There is a reason the runas program does not accept a password on its command line. To quote
Raymond Chen:
The RunAs program demands that you type the password manually. Why doesn’t it accept a password on the command line?
This was a conscious decision. If it were possible to pass the password on the command line, people would start embedding passwords into batch files and logon scripts, which is laughably insecure.
In other words, the feature is missing to remove the temptation to use the feature insecurely.
In other words, you should not do this.
Bill
-
Proposed as answer by
Wednesday, May 2, 2012 6:16 PM
-
Marked as answer by
IamMred
Sunday, May 6, 2012 11:59 PM
-
Proposed as answer by
Problem
I am receiving the vbscript error “Invalid Character 800A0408 compilation error at Line 1 Char 1” while running a vbscript file which contains following code (this is just a sample code).
Option Explicit Dim strUser strUser = "Morgan" WScript.Echo "Hello ! " & strUser Wscript.Quit
I have received below error:
Script: C:Test.vbs Line: 1 Char: 1 Error: Invalid character Code: 800A0408 Source: Microsoft VBScript compilation error
Fix/Solution
This issue was occurs due to the Encoding method UTF-8 which I used to save the .vbs file. We should use the Encoding method ANSI to save .vbs file. Follow the below steps to fix this issue:
1. Open the vbscript file in Notepad
2. Go to File and click “Save as”
3. Under the file name, you will see a drop down menu for Encoding. Choose ANSI.
4. Save the file.