Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logon vbs script errors

Status
Not open for further replies.

TSMJ

MIS
Nov 27, 2002
83
0
0
Hi
Just trying to put together a script to map a shared drive, a network printer and a default homepage. So far, I have 2 scripts, a homepage.vbs and another script doing the drive and printer. They both work perfectly when you run them separately, but when I copy the code from each into the same file I get the following message:

Line 8
Char 1
Error: Variable is undefined: 'oNet'
Code: 800A01F4
Source: MS VBScript runtime error


this is the "all in one" code:

'vb script to create homepage
Option Explicit
Dim WSHShell, RegKey
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\"
WSHShell.RegWrite regkey & "Start page", "
' vb script to create network dirve "shared"
Set oNet = CreateObject("Wscript.Network")
oNet.MapNetworkDrive "H:", "\\NT1\data\data\shared"

' vb script to add printers via login script
Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\Fujitsu\HP_DJ_840c"
PrinterDriver = "HP DeskJet 850C"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver

What haven't I done?

Thanks for any help - I'm also after some script to delete temp user profiles off the workstation after upload to the server, but 1 thing at a time, eh? :)
 
Do you need to DIM 0net? If that's the case then you'll also need to DIM WshNetwork else you may get another error.


:)I Leco
 
Hi
Sorry Leco, I'm new to VBS and havn't a clue what you just said... could you explain it a bit more simply? ;-)
 
Variables have to be declared before using them - in the case of this piece of code look at:

Dim WSHShell, RegKey
Set WSHShell = CreateObject("WScript.Shell")

After the "Dim" you can "Set" the variable to something or other.

Now look at the next bit:

' vb script to create network drive "shared"
Set oNet = CreateObject("Wscript.Network")
oNet.MapNetworkDrive "H:", "\\NT1\data\data\shared"

there is no Dim statement but only a "Set"

similarly:
' vb script to add printers via login script
Set WshNetwork = CreateObject("WScript.Network")

there is no "Set" here either

Possibly the next question you'll ask is what these two variables should be declared as - I'm afraid I don't know, but I'm sure someone will!


:)I Leco
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top