Solved

VBS Runtime error 800A000D - Type mismatch

Posted on 2014-09-27
17
502 Views
Last Modified: 2014-09-29
Set wshShell = CreateObject( "WScript.Shell" )
Set objNetwork = CreateObject("Wscript.Network")
strComputer = LCase (objNetwork.ComputerName)
strComputer1 = objNetwork.ComputerName

wshShell.RegWrite "HKCU\New\",""
wshShell.RegWrite "HKCU\New\" & strComputer1 & "\",""
wshShell.RegWrite "HKCU\New\" & strComputer1 & "_For" &  "\",""

wshShell.RegWrite "HKCU\New\" & strComputer1 & "\Test\",""
wshShell.RegWrite "HKCU\New\" & strComputer1 & "_For" &  "\Test\",""

wshShell.RegWrite "HKCU\New\" & strComputer1 & "\Test" & "\Password", strComputer , "REG_BINARY"
wshShell.RegWrite "HKCU\New\" & strComputer1 & "_For" & "\Test" & "\Password", strComputer & "_For" , "REG_BINARY"

But when I run i get this error "VBS Runtime error 800A000D - Type mismatch" on line 13


i try to replace this line to :

'wshShell.RegWrite "HKCU\New\" & strComputer1 & "_For" & "\Test" & "\Password", StringToByteArray(strComputer & "_For"), "REG_BINARY"

with this function
Function StringToByteArray(parmString)
      Dim OStream
      Set OStream = CreateObject("ADODB.Stream")
      oStream.Open
      oStream.Type = 1            '=adTypeBinary
      oStream.WriteText parmString
      StringToByteArray = oStream.Read
End Function
But when I run i get this error "VBS Runtime error 800A0C93 - Operation is not allowed in this context"

Any know why is not working or what is needed to change to make work?
Thank you
0
Comment
Question by:David Regev
  • 8
  • 5
  • 4
17 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40347721
I note that you have used 2 variables, strComputer1 and strComputer, but you are trying to write a binary value, which should be an integer.

What is the value of strComputer as it looks like its a string not an integer. If it is a string then why do you need to force it to be an integer in the registry?
0
 

Author Comment

by:David Regev
ID: 40347771
Hi

i fix the vbs

the purpose  of the vbs is to create key (password) with binary value of the computer name

but now i got this error - (23, 2) ADODB.Stream: Operation is not allowed in this context.

is there any way to fix this problem

Set wshShell = CreateObject( "WScript.Shell" )
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

wshShell.RegWrite "HKCU\New\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "\",""
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" &  "\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "\Test\",""
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" &  "\Test\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer)) , "REG_BINARY"
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer & "_For")), "REG_BINARY"


Set wshShell = Nothing

Function StringToByteArray(parmString)
      Dim OStream
      Set OStream = CreateObject("ADODB.Stream")
      oStream.Open
      oStream.Type = 1            '=adTypeBinary
      oStream.WriteText parmString
      StringToByteArray = oStream.Read
End Function

Thx
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40347843
To create the byte array, use this

iAddressLength = len(parmString)
Dim ByteArray(iAddressLength-1)

For x = 1 to iAddressLength
      ByteArray(x-1) = Asc(Mid(parmString, x ,1))
Next
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:David Regev
ID: 40347868
I'm sorry  , I'm new in this

where do i put this lines please ?

Thx
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40347952
in your function stringtobytearray, remove the code that you have there
0
 

Author Comment

by:David Regev
ID: 40348289
Hi

Can you copy paste this line to the code please ??

David
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40348295
Function StringToByteArray(parmString)
iAddressLength = len(parmString)
 Dim ByteArray(iAddressLength-1)

 For x = 1 to iAddressLength
       ByteArray(x-1) = Asc(Mid(parmString, x ,1))
 Next
 StringToByteArray=ByteArray
 End Function
0
 

Author Comment

by:David Regev
ID: 40348302
Hi

Set wshShell = CreateObject( "WScript.Shell" )
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

wshShell.RegWrite "HKCU\New\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "\",""
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" &  "\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "\Test\",""
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" &  "\Test\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer)) , "REG_BINARY"
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer & "_For")), "REG_BINARY"

Set wshShell = Nothing

Function StringToByteArray(parmString)
iAddressLength = len(parmString)
 Dim ByteArray(iAddressLength-1)

 For x = 1 To iAddressLength
       ByteArray(x-1) = Asc(Mid(parmString, x ,1))
 Next
 StringToByteArray=ByteArray
 End Function

now i got this error  - 21, 16) Microsoft VBScript compilation error: Expected integer constant

Thx
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40348312
OK, it seems that RegWrite cannot accept a byte array, just an integer when you use REG_Binary as a parameter. This is beyond my knowledge as its a different issue to the original question.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40348429
I believe if you are trying to declare a variable (in this case ByteArray) as an array, but use a variable value, you will get this error.  To get around this, you should be able to use ReDim instead.
Change
  Dim ByteArray(iAddressLength-1)
to
  ReDim ByteArray(iAddressLength-1)

Regards,

Rob.
0
 

Author Comment

by:David Regev
ID: 40348431
hi

how do you Recommend Re- phrase the question ?

Thx
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40348448
I don't think you need to rephrase it.  You were originally dealing with a binary value, and still are, so I think it's appropriate.

Rob.
0
 

Author Comment

by:David Regev
ID: 40348487
Hi Rob

i try to replace this to what you suggest

but now i got this error : (13, 1) Microsoft VBScript runtime error: Type mismatch , 800A000D

Set wshShell = CreateObject( "WScript.Shell" )
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

wshShell.RegWrite "HKCU\New\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "\",""
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" &  "\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "\Test\",""
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" &  "\Test\",""

wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer)) , "REG_BINARY"
wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer & "_For")), "REG_BINARY"

Set wshShell = Nothing

Function StringToByteArray(parmString)
iAddressLength = len(parmString)
ReDim ByteArray(iAddressLength-1)

 For x = 1 To iAddressLength
       ByteArray(x-1) = Asc(Mid(parmString, x ,1))
 Next
 StringToByteArray=ByteArray
 End Function


Thx
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40348542
Oh, I just remembered, RegWrite does not support writing to Binary values:
http://msdn.microsoft.com/en-us/library/yfdfhz1b(v=vs.84).aspx

You need to use the SetBinaryValue method:
http://msdn.microsoft.com/en-us/library/aa393286(v=vs.85).aspx

So with your byte array, try this:
Set wshShell = CreateObject( "WScript.Shell" )
 Set objNetwork = CreateObject("Wscript.Network")
 strComputer = objNetwork.ComputerName

Const HKEY_CURRENT_USER = &H80000001
Set objRegistry = GetObject("Winmgmts:root\default:StdRegProv")

 wshShell.RegWrite "HKCU\New\",""

 wshShell.RegWrite "HKCU\New\" & strComputer & "\",""
 wshShell.RegWrite "HKCU\New\" & strComputer & "_For" &  "\",""

 wshShell.RegWrite "HKCU\New\" & strComputer & "\Test\",""
 wshShell.RegWrite "HKCU\New\" & strComputer & "_For" &  "\Test\",""

 'wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer)) , "REG_BINARY"
 'wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer & "_For")), "REG_BINARY"
intReturn = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, "New\" & strComputer & "_For\Test\Password", "", StringToByteArray (LCase (strComputer & "_For")))

 Set wshShell = Nothing

 Function StringToByteArray(parmString)
 iAddressLength = len(parmString)
 ReDim ByteArray(iAddressLength-1)

  For x = 1 To iAddressLength
        ByteArray(x-1) = Asc(Mid(parmString, x ,1))
  Next 
  StringToByteArray=ByteArray
  End Function

Open in new window

0
 

Author Comment

by:David Regev
ID: 40348554
Hi Rob

now i don't get any error on the script but no value is written to registry

i attach the registry file .
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 40349011
Try this.  I was trying to write to the default value in the Password key, but instead it looks you want to write the Password value in the Test key.

Regards,

Rob.

Set wshShell = CreateObject( "WScript.Shell" )
 Set objNetwork = CreateObject("Wscript.Network")
 strComputer = objNetwork.ComputerName

Const HKEY_CURRENT_USER = &H80000001
Set objRegistry = GetObject("Winmgmts:root\default:StdRegProv")

 wshShell.RegWrite "HKCU\New\",""

 wshShell.RegWrite "HKCU\New\" & strComputer & "\", ""
 wshShell.RegWrite "HKCU\New\" & strComputer & "_For\", ""

 wshShell.RegWrite "HKCU\New\" & strComputer & "\Test\", ""
 wshShell.RegWrite "HKCU\New\" & strComputer & "_For\Test\", ""

 'wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer)) , "REG_BINARY"
 'wshShell.RegWrite "HKCU\New\" & strComputer & "_For" & "\Test" & "\Password", StringToByteArray (LCase (strComputer & "_For")), "REG_BINARY"
intReturn = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, "New\" & strComputer & "\Test\", "Password", StringToByteArray (LCase (strComputer)))
intReturn = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, "New\" & strComputer & "_For\Test\", "Password", StringToByteArray (LCase (strComputer & "_For")))

 Set wshShell = Nothing

 Function StringToByteArray(parmString)
 iAddressLength = len(parmString)
 ReDim ByteArray(iAddressLength-1)

  For x = 1 To iAddressLength
        ByteArray(x-1) = Asc(Mid(parmString, x ,1))
  Next 
  StringToByteArray=ByteArray
  End Function

Open in new window

0
 

Author Comment

by:David Regev
ID: 40349648
Works like a charm
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question