![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 > 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 - 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 Specs![]() |
![]() |
| 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 | |||