Failed Logon Script in W7

IT.vbsTrying to push out a Logon script through GPO. It doesn't work. I am trying to map drives and printers.
Leah WhitneyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
what part doesnt work ??
 most seems like the one i have in use.

'option explicit

on error resume next

dim oDomGrp, oNet, oDrives, iCount, Result
dim sUserName, sComputerName, sNTDomain, sProductId, sPCModel
dim sQuery
dim oUser, oComputer

' Other things

set oNet=CreateObject("WScript<wbr ></wbr>.Network")<wbr ></wbr>
set oDrives = oNet.EnumNetworkDrives
Set WShell = Wscript.CreateObject("Wscr<wbr ></wbr>ipt.Shell"<wbr ></wbr>)
Set aError = False

sComputerName=oNet.Compute<wbr ></wbr>rName 

'=========================<wbr ></wbr>==========<wbr ></wbr>==========<wbr ></wbr>==========<wbr ></wbr>==========<wbr ></wbr>===
'--------------- do the mappings ------------------------
Result = MapDrive("T:", "\\Scud\Tools")

sHomeShare = WShell.ExpandEnvironmentSt<wbr ></wbr>rings("%HO<wbr ></wbr>MESHARE%")<wbr ></wbr>
Result = MapDrive("H:", sHomeShare)

oNet.AddWindowsPrinterConn<wbr ></wbr>ection "\\VENUS\CS231 PS Right"
'=========================<wbr ></wbr>==========<wbr ></wbr>==========<wbr ></wbr>==========<wbr ></wbr>==========<wbr ></wbr>===

function MapDrive(sDriveLetter, sShareName)
on error resume next

for iCount = 0 to oDrives.Count - 1 step 2
  if oDrives.Item(iCount) = sDriveLetter then
    oNet.RemoveNetworkDrive sDriveLetter, True, True  ' Delete mapping if it already exists
    wscript.sleep 500
  end if


While (RetryLoop<4) and (MapDrive=False)
  Result = MapDriveExec(sDriveLetter,<wbr ></wbr> sShareName)  ' Create new mapping

  if Result = 0 then
    MapDrive = true
    MapDrive = false    ' Yes I know this is not required...
    wscript.sleep 1000  ' Pause for 1 second so it does not cache attempt
  end if
  RetryLoop = RetryLoop + 1

end function
function MapDriveExec(sDriveLetter, sShareName)
  MapdriveExec = 10000
  on error resume next
'  ieecho("Mapping now")
  MapDriveExec = oNet.MapNetworkDrive(sDriveLetter, sShareName, False)  ' Create new mapping
end Function

Open in new window

Leah WhitneyAuthor Commented:
Getting syntax errors. I'm not VB scripting expert by no means.
There's quite a bit wrong in IT.vbs
Line 13 - you've not defined a variable called "user_profile".
Try adding this line before it:
user_profile = &h28
Line 15 - needs uncommenting out or else line 20 breaks.
Lines 22 to 24 - you only need to set the path once.
Lines 28-29 - if these were not commented out they'd be redundant anyway.  You don't need three instances of the same object.
Lines 44-45 - just use objNetwork

Remove line 17 until you've debugged it.

But really, why use VBScript at all?  Use Group Policy Preferences to map your drives and printers.  It's soooo much easier!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

I agree with cantrois. Unless there is a specific reason for the VB script, do it through Group Policy Preferences, which is far more user friendly.
Robberbaron (robr)Commented:
i go a little the other way as i find it easier to test vbs scripts.  and scripts can do other things as well like install dll's.

but back to the topic....
loud1982 , I have cleaned up your script much as cantoris suggested.

amd have attached part of a working script for comparison. we use tennis players as our server names so just have to find and change those.
Leah WhitneyAuthor Commented:
I went ahead and used GPO User Preferences to map drives. Worked immediately!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.