David Regev
asked on
VBS Runtime error 800A000D - Type mismatch
Set wshShell = CreateObject( "WScript.Shell" )
Set objNetwork = CreateObject("Wscript.Netw ork")
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(strCompu ter & "_For"), "REG_BINARY"
with this function
Function StringToByteArray(parmStri ng)
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
Set objNetwork = CreateObject("Wscript.Netw
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(strCompu
with this function
Function StringToByteArray(parmStri
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
ASKER
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.Netw ork")
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(parmStri ng)
Dim OStream
Set OStream = CreateObject("ADODB.Stream ")
oStream.Open
oStream.Type = 1 '=adTypeBinary
oStream.WriteText parmString
StringToByteArray = oStream.Read
End Function
Thx
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.Netw
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(parmStri
Dim OStream
Set OStream = CreateObject("ADODB.Stream
oStream.Open
oStream.Type = 1 '=adTypeBinary
oStream.WriteText parmString
StringToByteArray = oStream.Read
End Function
Thx
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
iAddressLength = len(parmString)
Dim ByteArray(iAddressLength-1
For x = 1 to iAddressLength
ByteArray(x-1) = Asc(Mid(parmString, x ,1))
Next
ASKER
I'm sorry , I'm new in this
where do i put this lines please ?
Thx
where do i put this lines please ?
Thx
in your function stringtobytearray, remove the code that you have there
ASKER
Hi
Can you copy paste this line to the code please ??
David
Can you copy paste this line to the code please ??
David
Function StringToByteArray(parmStri ng)
iAddressLength = len(parmString)
Dim ByteArray(iAddressLength-1 )
For x = 1 to iAddressLength
ByteArray(x-1) = Asc(Mid(parmString, x ,1))
Next
StringToByteArray=ByteArra y
End Function
iAddressLength = len(parmString)
Dim ByteArray(iAddressLength-1
For x = 1 to iAddressLength
ByteArray(x-1) = Asc(Mid(parmString, x ,1))
Next
StringToByteArray=ByteArra
End Function
ASKER
Hi
Set wshShell = CreateObject( "WScript.Shell" )
Set objNetwork = CreateObject("Wscript.Netw ork")
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(parmStri ng)
iAddressLength = len(parmString)
Dim ByteArray(iAddressLength-1 )
For x = 1 To iAddressLength
ByteArray(x-1) = Asc(Mid(parmString, x ,1))
Next
StringToByteArray=ByteArra y
End Function
now i got this error - 21, 16) Microsoft VBScript compilation error: Expected integer constant
Thx
Set wshShell = CreateObject( "WScript.Shell" )
Set objNetwork = CreateObject("Wscript.Netw
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(parmStri
iAddressLength = len(parmString)
Dim ByteArray(iAddressLength-1
For x = 1 To iAddressLength
ByteArray(x-1) = Asc(Mid(parmString, x ,1))
Next
StringToByteArray=ByteArra
End Function
now i got this error - 21, 16) Microsoft VBScript compilation error: Expected integer constant
Thx
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.
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.
Change
Dim ByteArray(iAddressLength-1
to
ReDim ByteArray(iAddressLength-1
Regards,
Rob.
ASKER
hi
how do you Recommend Re- phrase the question ?
Thx
how do you Recommend Re- phrase the question ?
Thx
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.
Rob.
ASKER
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.Netw ork")
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(parmStri ng)
iAddressLength = len(parmString)
ReDim ByteArray(iAddressLength-1 )
For x = 1 To iAddressLength
ByteArray(x-1) = Asc(Mid(parmString, x ,1))
Next
StringToByteArray=ByteArra y
End Function
Thx
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.Netw
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(parmStri
iAddressLength = len(parmString)
ReDim ByteArray(iAddressLength-1
For x = 1 To iAddressLength
ByteArray(x-1) = Asc(Mid(parmString, x ,1))
Next
StringToByteArray=ByteArra
End Function
Thx
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:
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
ASKER
Hi Rob
now i don't get any error on the script but no value is written to registry
i attach the registry file .
now i don't get any error on the script but no value is written to registry
i attach the registry file .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works like a charm
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?