Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VBScript not working as it should

Reply
 
Old 10-14-2008   #1 (permalink)
Tridec


 
 

VBScript not working as it should

I am testing a new vbscript that I created by searching the internet.
I have one user called Test which is in the group test1. Also this users is
the only one in has OU.
When I log in now it does seem to run it, cause if I change something that
isn't scripting it gives me an error in script.

I attached the script only to the gpo called test_loginscript. Which is only
link to the OU of test. The script should run by the user
configuration\Windows Settings\Scripts\Logon\

Below you can find the script can someone please tell me what I am doing
wrong?
It should create a W: drive. Rights are set correctly.

It is just a test, but if it works I want to expand it with printers.

René Klomp

ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path


Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
DomainString = Wshnetwork.UserDomain
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

UserString = WSHNetwork.UserName
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

strComputer = WSHNetwork.ComputerName

wscript.sleep 300

For Each GroupObj In UserObj.Groups
Select Case UCase(GroupObj.Name)
Case "test1"
WSHNetwork.MapNetworkDrive "w:", "\\Sbserver\Test",True
End Select
Next

WSHPrinters.Item(LOOP_COUNTER +1),True,True


My System SpecsSystem Spec
Old 10-14-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: VBScript not working as it should

Tridec wrote:
Quote:

>I am testing a new vbscript that I created by searching the internet.
> I have one user called Test which is in the group test1. Also this users
> is
> the only one in has OU.
> When I log in now it does seem to run it, cause if I change something that
> isn't scripting it gives me an error in script.
>
> I attached the script only to the gpo called test_loginscript. Which is
> only
> link to the OU of test. The script should run by the user
> configuration\Windows Settings\Scripts\Logon\
>
> Below you can find the script can someone please tell me what I am doing
> wrong?
> It should create a W: drive. Rights are set correctly.
>
> It is just a test, but if it works I want to expand it with printers.
>
> René Klomp
>
> ON ERROR RESUME NEXT
>
> Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,
> Path
>
>
> Set WSHShell = CreateObject("WScript.Shell")
> Set WSHNetwork = CreateObject("WScript.Network")
> DomainString = Wshnetwork.UserDomain
> WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
>
> UserString = WSHNetwork.UserName
> Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
>
> strComputer = WSHNetwork.ComputerName
>
> wscript.sleep 300
>
> For Each GroupObj In UserObj.Groups
> Select Case UCase(GroupObj.Name)
> Case "test1"
> WSHNetwork.MapNetworkDrive "w:", "\\Sbserver\Test",True
> End Select
> Next
>
> WSHPrinters.Item(LOOP_COUNTER +1),True,True
>
I would remove "On Error Resume Next". This statement serves no purpose in
this script except to make troubleshooting nearly impossible. Then run the
script manually (at a command prompt) after logging in as the user.

I believe the problem is that you compare UCase(GroupObj.Name) with "test1".
You should compare with "TEST1".

There is no need for the Sleep command. I would suggest the following:
=========
Set objNetwork = CreateObject("Wscript.Network")
strUser = objNetwork.UserName
strDomain = objNetwork.UserDomain
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")

' Bind to the group object.
strGroup = "test1"
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")

' Check if the user is a member using the IsMember method of the group
object.
If (objGroup.IsMember(objUser.AdsPath) = True) Then
objNetwork.MapNetworkDrive "W:", "\\Sbserver\Test", True
End If
========
For a FAQ on configuring logon scripts see this link:

http://www.rlmueller.net/LogonScriptFAQ.htm
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 10-14-2008   #3 (permalink)
Tridec


 
 

Re: VBScript not working as it should

It worked!
Finally after trying and adjusting 4 scripts...
Now I want to add a printer to it.
How do I do that cause I only find local printers on the website.

Thanks so far!

"Richard Mueller [MVP]" wrote:
Quote:

> Tridec wrote:
>
Quote:

> >I am testing a new vbscript that I created by searching the internet.
> > I have one user called Test which is in the group test1. Also this users
> > is
> > the only one in has OU.
> > When I log in now it does seem to run it, cause if I change something that
> > isn't scripting it gives me an error in script.
> >
> > I attached the script only to the gpo called test_loginscript. Which is
> > only
> > link to the OU of test. The script should run by the user
> > configuration\Windows Settings\Scripts\Logon\
> >
> > Below you can find the script can someone please tell me what I am doing
> > wrong?
> > It should create a W: drive. Rights are set correctly.
> >
> > It is just a test, but if it works I want to expand it with printers.
> >
> > René Klomp
> >
> > ON ERROR RESUME NEXT
> >
> > Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,
> > Path
> >
> >
> > Set WSHShell = CreateObject("WScript.Shell")
> > Set WSHNetwork = CreateObject("WScript.Network")
> > DomainString = Wshnetwork.UserDomain
> > WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
> >
> > UserString = WSHNetwork.UserName
> > Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
> >
> > strComputer = WSHNetwork.ComputerName
> >
> > wscript.sleep 300
> >
> > For Each GroupObj In UserObj.Groups
> > Select Case UCase(GroupObj.Name)
> > Case "test1"
> > WSHNetwork.MapNetworkDrive "w:", "\\Sbserver\Test",True
> > End Select
> > Next
> >
> > WSHPrinters.Item(LOOP_COUNTER +1),True,True
> >
>
> I would remove "On Error Resume Next". This statement serves no purpose in
> this script except to make troubleshooting nearly impossible. Then run the
> script manually (at a command prompt) after logging in as the user.
>
> I believe the problem is that you compare UCase(GroupObj.Name) with "test1".
> You should compare with "TEST1".
>
> There is no need for the Sleep command. I would suggest the following:
> =========
> Set objNetwork = CreateObject("Wscript.Network")
> strUser = objNetwork.UserName
> strDomain = objNetwork.UserDomain
> Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
>
> ' Bind to the group object.
> strGroup = "test1"
> Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
>
> ' Check if the user is a member using the IsMember method of the group
> object.
> If (objGroup.IsMember(objUser.AdsPath) = True) Then
> objNetwork.MapNetworkDrive "W:", "\\Sbserver\Test", True
> End If
> ========
> For a FAQ on configuring logon scripts see this link:
>
> http://www.rlmueller.net/LogonScriptFAQ.htm
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
My System SpecsSystem Spec
Old 10-17-2008   #4 (permalink)
RemyMaza


 
 

Re: VBScript not working as it should

On Oct 14, 9:50*am, Tridec <Tri...@xxxxxx> wrote:
Quote:

> It worked!
> Finally after trying and adjusting 4 scripts...
> Now I want to add a printer to it.
> How do I do that cause I only find local printers on the website.
>
> Thanks so far!
>
>
>
> "Richard Mueller [MVP]" wrote:
Quote:

> > Tridec wrote:
>
Quote:
Quote:

> > >I am testing a new vbscript that I created by searching the internet.
> > > I have one user called Test which is in the group test1. Also this users
> > > is
> > > the only one in has OU.
> > > When I log in now it does seem to run it, cause if I change somethingthat
> > > isn't scripting it gives me an error in script.
>
Quote:
Quote:

> > > I attached the script only to the gpo called test_loginscript. Which is
> > > only
> > > link to the OU of test. The script should run by the user
> > > configuration\Windows Settings\Scripts\Logon\
>
Quote:
Quote:

> > > Below you can find the script can someone please tell me what I am doing
> > > wrong?
> > > It should create a W: drive. Rights are set correctly.
>
Quote:
Quote:

> > > It is just a test, but if it works I want to expand it with printers.
>
Quote:
Quote:

> > > René Klomp
>
Quote:
Quote:

> > > ON ERROR RESUME NEXT
>
Quote:
Quote:

> > > Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,
> > > Path
>
Quote:
Quote:

> > > Set WSHShell = CreateObject("WScript.Shell")
> > > Set WSHNetwork = CreateObject("WScript.Network")
> > > DomainString = Wshnetwork.UserDomain
> > > WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
>
Quote:
Quote:

> > > UserString = WSHNetwork.UserName
> > > Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
>
Quote:
Quote:

> > > strComputer = WSHNetwork.ComputerName
>
Quote:
Quote:

> > > wscript.sleep 300
>
Quote:
Quote:

> > > For Each GroupObj In UserObj.Groups
> > > * *Select Case UCase(GroupObj.Name)
> > > * * * *Case "test1"
> > > * * * * * *WSHNetwork.MapNetworkDrive "w:", "\\Sbserver\Test",True
> > > * *End Select
> > > Next
>
Quote:
Quote:

> > > WSHPrinters.Item(LOOP_COUNTER +1),True,True
>
Quote:

> > I would remove "On Error Resume Next". This statement serves no purposein
> > this script except to make troubleshooting nearly impossible. Then run the
> > script manually (at a command prompt) after logging in as the user.
>
Quote:

> > I believe the problem is that you compare UCase(GroupObj.Name) with "test1".
> > You should compare with "TEST1".
>
Quote:

> > There is no need for the Sleep command. I would suggest the following:
> > =========
> > Set objNetwork = CreateObject("Wscript.Network")
> > strUser = objNetwork.UserName
> > strDomain = objNetwork.UserDomain
> > Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
>
Quote:

> > ' Bind to the group object.
> > strGroup = "test1"
> > Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
>
Quote:

> > ' Check if the user is a member using the IsMember method of the group
> > object.
> > If (objGroup.IsMember(objUser.AdsPath) = True) Then
> > * * objNetwork.MapNetworkDrive "W:", "\\Sbserver\Test", True
> > End If
> > ========
> > For a FAQ on configuring logon scripts see this link:
>
Quote:

> >http://www.rlmueller.net/LogonScriptFAQ.htm
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab -http://www.rlmueller.net
> > --- Hide quoted text -
>
> - Show quoted text -
You could add a sub routine to do it... But seriously, I'm self taught
in vbscript and this is a very easy to find with google. You should
do some homework beforehand, really...



Sub AddPrinterConnection(strPrinterUNC)
On Error Resume Next

objNetwork.AddWindowsPrinterConnection strPrinterUNC

If Err.Number<>0 And blnShowError Then
strMsg="There was a problem mapping " & UCase(strPrinterUNC) & ". "
&_
vbcrlf & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number)
&_
VbCrLf & Err.Description

objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation
Err.Clear
End If

end sub



If you find this code confusing, try one of my fav websites...

http://www.computerperformance.co.uk...on_scripts.htm

Regards,
Matt
www.crossloop.com/matthewbramer

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
VBScript to send email not working on 1 server VB Script
VBScript to send email not working on 1 server VB Script
Vbscript stop working if IE8 beta is installed VB Script
How to do No hang up VBScript (nohup for VBScript) VB Script
working on html objects using HTML DOM, VBscript VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46