Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
RE: Select Case Problem
Logged in as: Guest
arrSession:exec spGetSession 2,2,51517
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
WSH & Client Side VBScript
>> RE: Select Case Problem
Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page:
<<
< prev
1
[2]
Login
Message
<< Older Topic
Newer Topic >>
RE: Select Case Problem -
9/9/2007 5:54:00 PM
ginolard
Posts: 1053
Score: 21
Joined: 8/10/2005
Status:
offline
Well, your For Next loop doesn't really do anything other than loop through the groups and assign the group name to the strGroupName variable. Presumably you want to check that variable and map a printer based on its value
Try this instead
'On Error Resume Next Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("Wscript.Network") Set objPrinters = objNetwork.EnumPrinterConnections Set objDrives = objNetwork.EnumNetworkDrives '******************************************************************************** 'Delete Network Printer '******************************************************************************** For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2 If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True End If msgbox ( "Delete PRinter" ) Next strUserPath = "LDAP://" & objSysInfo.UserName Set objUser = GetObject(strUserPath) For Each strGroup in objUser.MemberOf strGroupPath = "LDAP://" & strGroup Set objGroup = GetObject(strGroupPath) strGroupName = objGroup.CN '******************************************************************************** 'Map Network Printer '******************************************************************************** Select Case strGroupName Case "printserveR_user" objNetwork.AddwindowsPrinterConnection "printserver\prt22" msgBox ( " Map Printer" ) End Select Next MsgBox ( "END" )
_____________________________
Author of ManagePC -
http://managepc.net
AD Query Template -
http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework -
http://www.visualbasicscript.com/m_59109/tm.htm
(in reply to
repa
)
Post #: 21
RE: Select Case Problem -
9/9/2007 6:00:35 PM
repa
Posts: 19
Score: 0
Joined: 9/4/2007
Status:
offline
hi,
i testet it with your version.
but still the same. Delete Printer runs, but mapping not.
(in reply to
ginolard
)
Post #: 22
RE: Select Case Problem -
9/9/2007 6:48:38 PM
ginolard
Posts: 1053
Score: 21
Joined: 8/10/2005
Status:
offline
Then the Case Statement isn't being triggered. The logic is fine. Are you sure that the group name you want to check is "printserveR_user"?
_____________________________
Author of ManagePC -
http://managepc.net
AD Query Template -
http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework -
http://www.visualbasicscript.com/m_59109/tm.htm
(in reply to
repa
)
Post #: 23
RE: Select Case Problem -
9/9/2007 6:49:42 PM
repa
Posts: 19
Score: 0
Joined: 9/4/2007
Status:
offline
yes, 100%
(in reply to
ginolard
)
Post #: 24
RE: Select Case Problem -
9/9/2007 6:53:02 PM
repa
Posts: 19
Score: 0
Joined: 9/4/2007
Status:
offline
sorry, my fault :D
was logged in with false user id ^^
IT WORKS :))))))))))))))))
now, i try the hole script :))
(in reply to
ginolard
)
Post #: 25
RE: Select Case Problem -
9/9/2007 7:28:01 PM
repa
Posts: 19
Score: 0
Joined: 9/4/2007
Status:
offline
hi
ok, works now great, but drives are not deleted. why?
Code looks like:
On Error Resume Next Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("Wscript.Network") Set objPrinters = objNetwork.EnumPrinterConnections Set objDrives = WshNetwork.EnumNetworkDrives strUserPath = "LDAP://" & objSysInfo.UserName Set objUser = GetObject(strUserPath) '******************************************************************************** 'In this section, we define all things, used later in this script '******************************************************************************** 'Define, what should be done: MapPrinter = enable DelPrinter = enable mapNetworkDrive = enable DelNetworkDrive = enable 'Define Network Drives NetDriveI = "i:" NetDriveJ = "j:" NetDriveK = "k:" NetDriveL = "l:" NetDriveM = "m:" NetDriveN = "n:" NetDriveO = "o:" NetDriveP = "p:" NetDriveQ = "q:" NetDriveR = "r:" NetDriveS = "s:" NetDriveT = "t:" NetDriveU = "u:" NetDriveV = "v:" NetDriveY = "y:" NetDriveX = "x:" NetDriveZ = "z:" 'Define Servers Server1 = "\\12" Server2 = "\\13" Server3 = "\\15" Server4 = "\\14" PSRV1 = "\\16" '******************************************************************************** 'END '******************************************************************************** '******************************************************************************** 'Remove Network Drives '******************************************************************************** objNetwork.RemoveNetworkDrive NetDriveI, True, True objNetwork.RemoveNetworkDrive NetDriveJ, True, True objNetwork.RemoveNetworkDrive NetDriveK, True, True objNetwork.RemoveNetworkDrive NetDriveL, True, True objNetwork.RemoveNetworkDrive NetDriveM, True, True objNetwork.RemoveNetworkDrive NetDriveN, True, True objNetwork.RemoveNetworkDrive NetDriveO, True, True objNetwork.RemoveNetworkDrive NetDriveP, True, True objNetwork.RemoveNetworkDrive NetDriveQ, True, True objNetwork.RemoveNetworkDrive NetDriveR, True, True objNetwork.RemoveNetworkDrive NetDriveS, True, True objNetwork.RemoveNetworkDrive NetDriveT, True, True objNetwork.RemoveNetworkDrive NetDriveU, True, True objNetwork.RemoveNetworkDrive NetDriveV, True, True objNetwork.RemoveNetworkDrive NetDriveY, True, True objNetwork.RemoveNetworkDrive NetDriveX, True, True objNetwork.RemoveNetworkDrive NetDriveZ, True, True msgbox ("Del Drive") '******************************************************************************** 'Map Network Drives '******************************************************************************** if mapNetworkDrive = enable then For Each strGroup in objUser.MemberOf strGroupPath = "LDAP://" & strGroup Set objGroup = GetObject(strGroupPath) strGroupName = objGroup.CN objNetwork.MapNetworkDrive NetDriveI, Server2 & "\Installation" objNetwork.MapNetworkDrive NetDriveJ, Server1 & "\Daten" objNetwork.MapNetworkDrive NetDriveL, Server1 & "\se9" Select Case strGroupName 'Map SoftM drive if user in group GLSoftMAdmin Case "GlSoftMAdmin" objNetwork.MapNetworkDrive NetDriveS, Server1 & "\se8" 'Map SoftM drive if user in group GLSoftMUser Case "GlSoftMUser" objNetwork.MapNetworkDrive NetDriveS, Server1 & "\user" 'Map Unikis drive if user in group GlRohagSpedi Case "GLRohagSpedi" objNetwork.MapNetworkDrive NetDriveU, Server3 & "\se7$" 'Map Mammut drive if user in group GLMammut Case "GLMammut" objNetwork.MapNetworkDrive NetDriveM, Server3 & "\se4" 'Map Finanz drive if user in group GLDietikerFinanz Case "GLDietikerFinanz" objNetwork.MapNetworkDrive NetDriveN, Server1 & "\finanzen" 'Map Finanzen drive if user in group GLDietikerPersonal Case "GLDietikerPersonal" objNetwork.MapNetworkDrive NetDriveN, Server1 & "\finanzen" 'Map Finanzen drive if user in group GLDietikerKonzernleitung Case "GLDietikerKonzernleitung" objNetwork.MapNetworkDrive NetDriveN, Server1 & "\finanzen" 'Map Finanzen drive if user in group GLBuDiv Case "GLBuDiv" objNetwork.MapNetworkDrive NetDriveN, Server1 & "\finanzen" 'Map Finanzen drive if user in group GLDietikerIfrsUmstellung Case "GLDietikerIfrsUmstellung" objNetwork.MapNetworkDrive NetDriveN, Server1 & "\finanzen" 'Map Lager drive if user in group GLDiagLager Case "GLDiagLager" objNetwork.MapNetworkDrive NetDriveK, Server1 & "\lager$" 'Map Stahl drive if user in group GLStahl Case "GLStahl" objNetwork.MapNetworkDrive NetDriveV, Server1 & "\stahl" 'Map Alucd2003 drive if user in group GLAluCD Case "GLAluCD" objNetwork.MapNetworkDrive NetDriveY, Server1 & "\se3" 'Map Lohn drive if user in group GLLohn Case "GLLohn" objNetwork.MapNetworkDrive NetDriveO, Server1 & "\lohn$" 'Map SocoAG drive if user in group LOSoCoAG Case "LOSocAG" objNetwork.MapNetworkDrive NetDriveT, Server1 & "\se2" 'Map analysen drive if user in group GLAnalysen Case "GLAnalysen" objNetwork.MapNetworkDrive NetDriveR, Server1 & "\Analysen$" 'Map analysen drive if user in group G_SoCo_User Case "G_SoCo_User" objNetwork.MapNetworkDrive NetDriveZ, Server4 & "\se" 'Map analysen drive if user in group G_SoCo_IT Case "G_SoCo_IT" objNetwork.MapNetworkDrive NetDriveQ, Server4 & "\Backupstorage" objNetwork.MapNetworkDrive NetDrivex, Server4 & "\Softwarestorage" End Select Next End IF If delPrinter = enable then '******************************************************************************** 'Delete Network Printer '******************************************************************************** For LOOP_COUNTER = 0 To objPrinters.Count - 1 Step 2 If Left(objPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then objNetwork.RemovePrinterConnection objPrinters.Item(LOOP_COUNTER +1),True,True End If msgbox ( "Delete PRinter" ) Next end If if mapPrinter = enable then '******************************************************************************** 'Map Network Printer '******************************************************************************** For Each strGroup in objUser.MemberOf strGroupPath = "LDAP://" & strGroup Set objGroup = GetObject(strGroupPath) strGroupName = objGroup.CN Select Case strGroupName Case "print_user" objNetwork.AddwindowsPrinterConnection PSRV1 & "\printer_PRT22" msgBox ( " Map Printer" ) End Select Next end If msgbox ( "END" )
(in reply to
repa
)
Post #: 26
RE: Select Case Problem -
9/9/2007 7:33:29 PM
ginolard
Posts: 1053
Score: 21
Joined: 8/10/2005
Status:
offline
Jeez, there's no need to do all that...
This will delete all network drives
On Error Resume Next Set objNetwork = CreateObject("WScript.Network") Set colDrives = objNetwork.EnumNetworkDrives If colDrives.Count > 0 Then For i = 0 to colDrives.Count-1 Step 2 objNetwork.RemoveNetworkDrive colDrives.Item(i),True Next End If
This will delete all network drives from I: onwards
On Error Resume Next Set objNetwork = CreateObject("WScript.Network") Set colDrives = objNetwork.EnumNetworkDrives If colDrives.Count > 0 Then For i = 0 to colDrives.Count-1 Step 2 Select Case colDrives.Item(i) Case "D:","E:","F:","G:","H:" Case Else objNetwork.RemoveNetworkDrive colDrives.Item(i),True End Select Next End If
_____________________________
Author of ManagePC -
http://managepc.net
AD Query Template -
http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework -
http://www.visualbasicscript.com/m_59109/tm.htm
(in reply to
repa
)
Post #: 27
RE: Select Case Problem -
9/9/2007 7:51:53 PM
repa
Posts: 19
Score: 0
Joined: 9/4/2007
Status:
offline
hi
i only want to delete the selected Drives, this is ok.
But, the drives still there after running the script.
(in reply to
ginolard
)
Post #: 28
RE: Select Case Problem -
9/9/2007 8:00:01 PM
ginolard
Posts: 1053
Score: 21
Joined: 8/10/2005
Status:
offline
Remove the On Error Resume Next and see if the script is generating any errors
_____________________________
Author of ManagePC -
http://managepc.net
AD Query Template -
http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework -
http://www.visualbasicscript.com/m_59109/tm.htm
(in reply to
repa
)
Post #: 29
Page:
<<
< prev
1
[2]
If you found our site useful please link to us
<a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>
.
All Forums
>>
[Scripting]
>>
WSH & Client Side VBScript
>> RE: Select Case Problem
Page:
<<
< prev
1
[2]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
New Messages
No New Messages
Hot Topic w/ New Messages
Hot Topic w/o New Messages
Locked w/ New Messages
Locked w/o New Messages
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI