WSH Question (Scripting)

Soldato
Joined
23 Nov 2004
Posts
3,794
Hey,

My boss has asked me to write a simple script, however he has told me i can NOT use a batch file. He has asked me to stop using them, and move onto WSH - Windows Scripting Host.

I have read up on the msdn wbesite, and also anything i have found in google.

The script needs to connect to a remote devices (140 different servers) and query a reg key (find out default printer) and output the server name , followed by the registry key value (HP/Lexmark/ETC)

For a batch file i would do a for loop for a text file containing all of the server names, and use a app i have called reg find which would query reg keys remotely.

This is what i have so far

Code:
//========================================
// Find Default Printer
//========================================
var WshShell = WScript.CreateObject("WScript.Shell");

var bKey = WshShell.RegRead ("HKLM\\Software\\Novell\\Login\\DefaultUserName");
WScript.Echo (bKey);

If i save this as a *.vbs/wsh/wsf it errors. However if i save it as a *.jscript it echo's the key to a msg box.

How would i write this to work with wscript to output to a text file, and loop for all devices in a text file?

Also, can anyone point me in the direction of any good tutorials or samples? Another also, what is it you type in start > run to launch the free vb editor in XP? I can't for the life of me remember.
 
Hi there,

The code there is jscript - the vbscript equivilent (with a different keyname substituted for the one in your example) would be something like below. Although I would recommend using StdRegProv rather than regread. Am a bit busy to go through the whole thing now, but this should get you on the way:

Code:
'========================================
' Find Default Printer
'========================================

Dim  WshShell : Set WshShell =  WScript.CreateObject("WScript.Shell")
Dim bKey : bKey = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir")
wscript.echo(bKey)

Cheers,
Jamie.
 
purejamie said:
Hi there,

The code there is jscript - the vbscript equivilent (with a different keyname substituted for the one in your example) would be something like below. Although I would recommend using StdRegProv rather than regread. Am a bit busy to go through the whole thing now, but this should get you on the way:

Code:
'========================================
' Find Default Printer
'========================================

Dim  WshShell : Set WshShell =  WScript.CreateObject("WScript.Shell")
Dim bKey : bKey = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir")
wscript.echo(bKey)

Cheers,
Jamie.

:( just tried it, it doesn't work. Also, why is it WSH files lcons look like shortcuts ?

Anyone else able to offer some advice or websites?

Thank in advance
 
The code brackets seem to have put spaces inbetween current and version in the code - might be that, code works ok here.

What is the error message you are getting?

Edit - the MS script centre is as good place to start as any: Here - some good examples and getting started tuts etc.
 
Last edited:
Back
Top Bottom