# Solved: Runtime errors in custom Java Script



## Anti-Intel2 (Dec 31, 2002)

Hello all!,

I am trying to create a login script that will make registry changes on XP and Vista machines. The reg keys are for disabling autorun/autoplay features of XP and Vista. I used and existing js file i had for making registry changes that worked, but when i put in the keys for the new script i get the following errors:


For the XP script:

Line: 2
Char:1
Error: Invalid procedure call or argument
Code: 800A0005
Source:Microsoft JScript runtime error

For the Vista script:

Line: 2
Char: 118
Error: Invalid Character
Code: 800A03F6
Source: Microsoft JScript compilation error

I am not a programmer by any stretch. If anyone can help me debug this you would be my hero!:up:


Here are the codes XP version on top Vista below that:

##########################################################################################################################################################
XP script:



var objShell = WScript.CreateObject("WScript.Shell");
objShell.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\Explorer\\HonorAutoRunSetting

", 0x01, "REG_WORD");
objShell.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\Explorer\\NoDriveTypeAutoRun"

, 0xFF, "REG_WORD");
objShell.RegWrite("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\Explorer\\NoDriveTypeAutoRun", 

0xFF, "REG_WORD");
WScript.Echo("AutoRun has been disabled.");



##########################################################################################################################################################
Vista Script


var objShell = WScript.CreateObject("WScript.Shell");
objShell.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\WindowsNT\\CurrentVersion\\IniFileMapping\\Autorun.inf", @=@SYSoesNotExist);
WScript.Echo("Autorun has been successfully disabled.");


----------



## TheOutcaste (Aug 8, 2007)

That should be *REG_DWORD*

Some examples here:
http://www.devguru.com/Technologies/wsh/quickref/wshshell_RegWrite.html


----------



## helpful (Sep 18, 2009)

first off you need to define const that you have used.

1. Please add these lines to the start of script


```
Const HKEY_CLASSES_ROOT   = &H80000000
Const HKEY_CURRENT_USER   = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS          = &H80000003
```
2. You also have spacing errors "Curren tVersion" and "Current Version" should be just "CurrentVersion"

3. Second remove unnecessary slashes from regwrite

Correct:

```
objShell.RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer\NoDriveTypeAutoRun", 0xFF, "REG_WORD");
```
Incorrect:


```
objShell.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Curren  tVersion\\policies\\Explorer\\HonorAutoRunSetting", 0x01, "REG_WORD");
```
4. see above post from TheOutcaste

5. These are syntax errors but you mave have logic errors in your script.


----------



## Anti-Intel2 (Dec 31, 2002)

OutCaste: it was DWORD....that fixed the XP script.

helpful: The spacing is from the formating of this page. in the script they have no spaces.

Something is still amiss on the Vista script....but i dont think it matters as I can install the same reg keys from XP to vista and it fixes the issue...

Thank you for the help!


----------



## TheOutcaste (Aug 8, 2007)

You can avoid the forum's spacing glitches by putting your code inside code tags. It also avoids the smiley's from creeping in; usually
In the advanced editor, highlight the code and click the # symbol
Or just type [noparse[[/plain] and paste your code in between the tags.

On the Vista script, there should be a space in Windows NT, and the @= part is not needed, that would be used in a .reg file, you just need to specify the value.
And to set the Default value, you specify the Key name with a trailing \
So give this a try:

```
var objShell = WScript.CreateObject("WScript.Shell");
objShell.RegWrite("HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\IniFileMapping\\Autorun.inf\\","@SYS:DoesNotExist");
WScript.Echo("Autorun has been successfully disabled.");
```
HTH

Jerry


----------



## Anti-Intel2 (Dec 31, 2002)

TheOutCaste......you are the man. 

That fixed the Vista script! 

I was pressed for time and had to write a batchfile referencing a reg file with the keys.,..it did the same thing. But now I have these js for this and can tighten up security against autorun malware!

Thank you very much for the assistance!


----------

