Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RegWrite non-string key

92 views
Skip to first unread message

Walter Briscoe

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to
The WSH example for RegWrite does not work. i.e.
> Set WshShell = WScript.CreateObject("WScript.Shell")
> WshShell.RegWrite "HKCU\ScriptEngine\Value", "Some string value"
> WshShell.RegWrite "HKCU\ScriptEngine\Key\", 1 ,"REG_DWORD"
Error: Invalid procedure call or argument
>

but curiously the following do
> WshShell.RegWrite "HKCU\ScriptEngine\Value", 1,"REG_DWORD"
> WshShell.RegWrite "HKCU\ScriptEngine\Key\", 1 ,"REG_SZ"

I would appreciate corrections for the following:
> WshShell.RegWrite "HKCU\ScriptEngine\Key\", 1 ,"REG_SZ"
> WshShell.RegWrite "HKCU\ScriptEngine\Key\", 1 ,"REG_EXPAND_SZ"
Error: Invalid procedure call or argument
> WshShell.RegWrite "HKCU\ScriptEngine\Key\", 1 ,"REG_DWORD"
Error: Invalid procedure call or argument
> WshShell.RegWrite "HKCU\ScriptEngine\Key\", 1 ,"REG_BINARY"
Error: Invalid procedure call or argument

Alternatively, is it true that registry keys can only hold strings?

I have a second point which has come up in preparing the work above.
I run a script with CSCRIPT in a Windows 95 OSR2 DOS box.
The paste control works in a very peculiar fashion in that DOS box.
In the clipboard, I put
WshShell.RegWrite "HKCU\ScriptEngine\Value", "Some string value"
The DOS box is windowed.
I press the DOS box paste key and NOTHING HAPPENS!
I minimise the box, put the focus back on it and STILL nothing happens
I do Alt+Enter to turn the box to full screen and WshShell.R is written.
I do Alt+Enter to restore the box to a window and
egWrite "HKCU\ScriptEngine\Value", " is added to the line.
I repeat that cycle until the clipboard is fully copied to the screen.

Explanation please?


This script (cut from one in "Windows Scripting Secrets" to the minimum
needed to make my point) shows the behavior.

set input = WScript.StdIn: set output = WScript.StdOut
do until false: output.Write "> ": ExecuteIt input.ReadLine: loop

sub ExecuteIt(command)
on error resume next
ExecuteGlobal command
if err<>0 then output.WriteLine "Error: " & err.description
end sub

--
Walter Briscoe

Michael Harris

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to
Walter,

These all work using WSH 2.0 on an NT4sp6a box (I'll try the same on a Win98 box later)... Note
that the REG_BINARY behaves differently depending on whether you use an explicit CLng() on the value
to be written...

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.RegWrite "HKCU\mykey\szKey\", "string key" ,"REG_SZ"
WshShell.RegWrite "HKCU\mykey\szValue", "string value" ,"REG_SZ"

WshShell.RegWrite "HKCU\mykey\expandszKey\", "string %PATH% key" ,"REG_EXPAND_SZ"
WshShell.RegWrite "HKCU\mykey\expandszValue", "string %PATH% value" ,"REG_EXPAND_SZ"

WshShell.RegWrite "HKCU\mykey\dwordKey\", 1 ,"REG_DWORD"
WshShell.RegWrite "HKCU\mykey\dwordValue", 1 ,"REG_DWORD"

WshShell.RegWrite "HKCU\mykey\binKey1\", 1 ,"REG_BINARY"
WshShell.RegWrite "HKCU\mykey\binValue1", 1 ,"REG_BINARY"

WshShell.RegWrite "HKCU\mykey\binKey2\", clng(1) ,"REG_BINARY"
WshShell.RegWrite "HKCU\mykey\binValue2", clng(1) ,"REG_BINARY"

As for the DOS box paste question -- I'm not on a Win9x box to test the behavior. I'm not sure what
you mean by the "DOS paste key" but in an NT console window, keyboard paste is ALT+space followed by
EP. Using that keystroke sequence, clipboard text pastes into a console window just fine, even when
if a full screen console window...

--
Michael Harris
MVP Scripting

Michael Harris

unread,
Jul 18, 2000, 3:00:00 AM7/18/00
to

All of the WshShell.RegWrite's work fine on Win98 as well (again, with WSH 2.0)...

--
Michael Harris
MVP Scripting


"Michael Harris" <Please....@To.NewsGroup> wrote in message news:eBKlj5M8$GA.134@cppssbbsa04...

Walter Briscoe

unread,
Jul 19, 2000, 3:00:00 AM7/19/00
to
In article <uXxfw$Q8$GA.148@cppssbbsa04> of Tue, 18 Jul 2000 16:28:02 in
microsoft.public.scripting.wsh, Michael Harris
<Please...@To.NewsGroup> writes

>
>All of the WshShell.RegWrite's work fine on Win98 as well (again, with WSH
>2.0)...

That was my experience too. I also repeated my test on an original W95
system at home and my experience was that only string registry keys
could be written. I am going to open another thread on the DOS box
experience. It was a mistake to combine the two.

--
Walter Briscoe

0 new messages