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!

Check multiple groups and map the drive? 3

Status
Not open for further replies.

ColdFlame

Technical User
Jul 24, 2007
48
0
0
CA
Hey there,

I'm trying to re-write my login scripts and amalgamate my 4 scripts into one login script. In doing so, there is tons of redundancy that I want to eliminate.

My main problem at the moment is trying to do something along these lines, but I'm not sure if it can be done in VBS...

If InGroup ("Accounting", "PayrollGroup", "HRGroup") Then
MapDrive "N:", "\\server\Acct"
End If

Is that right? I have seen, though now can't find, an example that did this:

If InGroup ("Accounting", "PayrollGroup", "HRGroup",0) Then
MapDrive "N:", "\\server\Acct"
End If

Essentially I want the script to check that particular user if they're in any of the aforementioned groups, and if so, then map that drive. I really don't want to have three if statements just to check those three groups.

TIA!

Jeremy
 
I have read it; is there no way to do it my suggested way? Or do you have to use the CASE statements?

Sorry, I'm learning this on the fly and am (obviously) not a wizard with scripting or any programming at all for that matter.

Thanks,

Jeremy
 
Yeah, if you don't want to use case statements you can use elseif.
Code:
If InGroup ("Accounting", "PayrollGroup", "HRGroup",0) Then
   MapDrive "N:", "\\server\Acct"

Else if InGroup ("Facilities", "IT",0) Then
   MapDrive "J:", "\\server\Something else"

Elseif etc

Else
anything you want to do here
End if

 
Perhaps I should post my whole script, though it is long. I can't figure out where I've gone wrong in it as it doesn't seem to run at all on my test user when I log in as them.

'**********************************************************************************
' Set Environment Variables
'*********************************************************************************
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set WSHShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next

Domain = WSHNetwork.UserDomain
UserName = ""

While UserName = ""
UserName = WSHNetwork.UserName
MyGroups = GetGroups(Domain, UserName)
Wend

'*********************************************************************************
' Main Process:
'*********************************************************************************
GrpMeb UserName
ShowBox
Wscript.Quit

'*********************************************************************************
'Function: GetGroups
'*********************************************************************************
Function GetGroups(Domain, UserName)
Set objUser = GetObject("WinNT://" & Domain & "/" & UserName)
GetGroups=""
For Each objGroup In objUser.Groups
GetGroups=GetGroups & "[" & UCase(objGroup.Name) & "]"
Next
End Function

'********************************************************************************
'Function: InGroup
'********************************************************************************
Function InGroup(strGroup)
InGroup=False
If InStr(MyGroups,"[" & UCase(strGroup) & "]") Then
InGroup=True
End If
End Function

'*********************************************************************************
' MapDrives Subroutine
'*********************************************************************************
Sub MapDrive(sDrive,sShare)
On Error Resume Next
WSHNetwork.RemoveNetworkDrive sDrive
Err.Clear
WSHNetwork.MapNetworkDrive sDrive,sShare
End Sub

'********************************************************************************
'Map Drives:
'********************************************************************************
Sub GrpMeb(UNAME)
If INGROUP ("Calgary Office") Then
MapDrive "G:", "\\CGYPDC01\Work_1"
MapDrive "I:", "\\CGYPDC01\Projects"
MapDrive "L:", "\\CGYPDC01\Work_1"
MapDrive "M:", "\\CGYSQL01\Deltek"
End If

If INGROUP ("Cost_Control") Then
MapDrive "H:", "\\CGYPDC01\Cost_Ctl"
End If

If INGROUP ("Map Accounting", "PayrollGroup", "CGYACCTGRP", "Accounting") Then
MapDrive "N:", "\\CGYPDC01\Acct"
End If

If INGROUP ("Business Development") Then
MapDrive "J:", "\\CGYPDC01\Busdev"
End If

If INGROUP ("Accounting", "Corporate Admin", 0) Then
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G006"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G018"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G046"
End If

If INGROUP ("2nd Floor") Then
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G038"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G051"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G058"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G059"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G068"
End If

If INGROUP ("3rd Floor") Then
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G026"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G027"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G037"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G048"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G050"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G056"
End If

If INGROUP ("4th Floor") Then
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G010"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G011"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G047"
End If

If INGROUP ("5th Floor") Then
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G033"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G034"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G040"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G045"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G056"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G061"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G064"
End If

If INGROUP ("Kinetic Colour") Then
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G001"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G054"
End If

If INGROUP ("Corp Colour") Then
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G066 Colour"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G066 Mono"
End If

If INGROUP ("4th Floor Color") Then
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G065"
End If


If INGROUP ("PonokaCGYGRP", "EDMCGYGRP", "FtSaskCGYGRP", 0) Then
MapDrive "G:", "\\CGYPDC01\Work_1"
MapDrive "I:", "\\CGYPDC01\Projects"
MapDrive "L:", "\\CGYPDC01\Work_2"
End If

'********************************************************************************
'Edmonton:
'********************************************************************************
If INGROUP ("EdmontonGRP") Then
MapDrive "R:", "\\EDMDC\Projects"
MapDrive "S:", "\\EDMDC\Work_2"
MapDrive "T:", "\\EDMDC\Work_1"
End If

If INGROUP ("GEN Solutions Projects") Then
MapDrive "R:", "\\EDMDC\Projects"
End If

'********************************************************************************
'Ponoka:
'********************************************************************************
If INGROUP ("PonokaGRP", "FtPonokaGRP", 0) Then
MapDrive "P:", "\\PonokaDC\Projects"
MapDrive "Q:", "\\PonokaDC\General"
WSHNetwork.AddWindowsPrinterConnection "\\PonokaDC\P01"
WSHNetwork.AddWindowsPrinterConnection "\\PonokaDC\mita"
End If

'********************************************************************************
'Fort Saskatchewan
'********************************************************************************
If INGROUP ("FortGRP", "FtSaskAdmin", "TEMP", 0) Then
MapDrive "U:", "\\FtSaskDC\Projects"
MapDrive "V:", "\\FtSaskDC\General"
WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM01"
WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM02"
WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM03"
End If

'********************************************************************************
'CAD Installations:
'********************************************************************************
If INGROUP ("EdmCADGRP", "Drafting Users", "Drafting Leads", "Gem Drafting", 0) Then
On Error Resume Next
Dim Shell, File, struser, strprog
Set Shell = CreateObject("WScript.Shell")
struser = Shell.ExpandEnvironmentStrings("%appdata%")
strprog = Shell.ExpandEnvironmentStrings("%programfiles%")
Set ofs=WScript.CreateObject("Scripting.FilesystemObject")
Set oFile=ofs.GetFile("C:\program files\autocad 2007\acad.exe")
If Err.Number = 0 Then
Err.Number = 0
Set oFile=ofs.GetFile("c:\program files\gemini\geminiSetup.exe")
If Err.Number = 0 Then
Err.Number = 0
File = """c:\program files\gemini\geminiSetup.exe"""
Shell.Run File
Set oFile=ofs.GetFile(struser & "\gemini\manager.exe")
If Err.Number = 0 Then
Err.Number = 0
File = """" & struser & "\gemini\manager.exe"""
Shell.Run File
End If
Else
Err.Number = 0
MsgBox "AutoCAD Installation found! Setup Program not found" & chr(13) & "Please Contact CAD_Support before running AutoCAD", VBOK
End If
End If
End If

End Sub

Can anyone help me decipher this? From Bryncspain's suggestion, it appears as though I *CAN* do the If statements rather than the cases? Where am I going wrong?
 
Here...I've converted your sub to use case statements. It looks much cleaner and should work fine. It's not tested and the group names are case sensitive without the UCase.

Code:
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")


Sub GrpMeb(UNAME, DomainString)
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UNAME)

For Each GroupObj In UserObj.Groups
    Select Case UCase(GroupObj.Name)
			Case "Calgary Office"
			    MapDrive "G:", "\\CGYPDC01\Work_1"
			    MapDrive "I:", "\\CGYPDC01\Projects"
			    MapDrive "L:", "\\CGYPDC01\Work_1"
			    MapDrive "M:", "\\CGYSQL01\Deltek" 
			
			Case "Cost_Control"
			    MapDrive "H:", "\\CGYPDC01\Cost_Ctl"
			
			Case "Map Accounting", "PayrollGroup", "CGYACCTGRP", "Accounting"
			    MapDrive "N:", "\\CGYPDC01\Acct"
			
			Case "Business Development"
			    MapDrive "J:", "\\CGYPDC01\Busdev"
			
			Case "Accounting", "Corporate Admin"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G006"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G018"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G046"
			
			Case "2nd Floor"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G038"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G051"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G058"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G059"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G068"
			
			Case "3rd Floor"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G026"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G027"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G037"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G048"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G050"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G056"
			
			Case "4th Floor"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G010"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G011"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G047"
			
			Case "5th Floor"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G033"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G034"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G040"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G045"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G056"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G061"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G064"
			
			Case "Kinetic Colour"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G001"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G054"
			
			Case "Corp Colour"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G066 Colour"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G066 Mono"
			
			Case "4th Floor Color"
			    WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G065"
			
			Case "PonokaCGYGRP", "EDMCGYGRP", "FtSaskCGYGRP"
			    MapDrive "G:", "\\CGYPDC01\Work_1"
			    MapDrive "I:", "\\CGYPDC01\Projects"
			    MapDrive "L:", "\\CGYPDC01\Work_2"
			
			'******************************************************************************** 
			'Edmonton:
			'******************************************************************************** 
			Case "EdmontonGRP"
			    MapDrive "R:", "\\EDMDC\Projects"
			    MapDrive "S:", "\\EDMDC\Work_2"
			    MapDrive "T:", "\\EDMDC\Work_1"
			
			Case "GEN Solutions Projects"
			    MapDrive "R:", "\\EDMDC\Projects"
			
			'******************************************************************************** 
			'Ponoka:
			'******************************************************************************** 
			Case "PonokaGRP", "FtPonokaGRP"
			    MapDrive "P:", "\\PonokaDC\Projects"
			    MapDrive "Q:", "\\PonokaDC\General"
			    WSHNetwork.AddWindowsPrinterConnection "\\PonokaDC\P01"
			    WSHNetwork.AddWindowsPrinterConnection "\\PonokaDC\mita"
			
			'******************************************************************************** 
			'Fort Saskatchewan
			'******************************************************************************** 
			Case "FortGRP", "FtSaskAdmin", "TEMP"
			    MapDrive "U:", "\\FtSaskDC\Projects"
			    MapDrive "V:", "\\FtSaskDC\General"
			    WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM01"
			    WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM02"
			    WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM03"
			
			'******************************************************************************** 
			'CAD Installations:
			'******************************************************************************** 
			Case "EdmCADGRP", "Drafting Users", "Drafting Leads", "Gem Drafting"
			    On Error Resume Next 
			    Dim Shell, File, struser, strprog
			    Set Shell = CreateObject("WScript.Shell")
			    struser = Shell.ExpandEnvironmentStrings("%appdata%")
			    strprog = Shell.ExpandEnvironmentStrings("%programfiles%")
			    Set ofs=WScript.CreateObject("Scripting.FilesystemObject") 
			    Set oFile=ofs.GetFile("C:\program files\autocad 2007\acad.exe") 
			    If Err.Number = 0 Then 
			        Err.Number = 0
			        Set oFile=ofs.GetFile("c:\program files\gemini\geminiSetup.exe") 
			        If Err.Number = 0 Then 
			            Err.Number = 0
			            File = """c:\program files\gemini\geminiSetup.exe"""
			            Shell.Run File 
			            Set oFile=ofs.GetFile(struser & "\gemini\manager.exe") 
			            If Err.Number = 0 Then 
			                Err.Number = 0
			                File = """" & struser & "\gemini\manager.exe"""
			                Shell.Run File 
			            End If
			        Else
			            Err.Number = 0
			            MsgBox "AutoCAD Installation found! Setup Program not found" & chr(13) & "Please Contact CAD_Support before running AutoCAD", VBOK
			        End If
			    End If
			
			Case Else
			End Select

End Sub
 
Thanks for your help, Brycspain.

It gives me more direction to follow, though I still can't get it working. I'm stumped... but will continue working on it! *sighs*
 
Sorry to post again, but Brycspain, you said:

It's not tested and the group names are case sensitive without the UCase.

Does this mean I must either match the case identically in the script as to how they are in Active Directory? Or does this mean I must put them in all upper case? markdmac's page has them all in upper case, so I'm a bit confused.

Please help! Thanks in advance!
 
They need to match how they appear in Active Directory.

HTH,

Chris
 
CKugo: Thanks for your answer, it did help! Unfortunately it didn't solve the problem...

---

Is there a way I can find out which line this is failing on? I've gone through line by line and can't seem to find why it's not working. I get no popups stating "Error on Line xx character xx".

I did find a few problems with the case of group names, however I've since corrected all of those to the appropriate cases.

I'm at a loss. Thanks in advance again..
 
Have you commented out the On Error Resume Next statement? This will usually help since when it's on, the script will bypass any errors and continue processing. Once you do that, post the revised script and bold the line you're getting the error on.
 
Thanks Brycspain, I hadn't done that. I have since done that, and it resulted in an error in which I realized my mistake and corrected. Now, it runs without any error but I don't see any results (no mapped drives, no mapped printers, etc..)

Code is as follows:


'On Error Resume Next

Dim WSHShell, WSHNetwork, objDomain, DomainString, UName, UserObj, Path, strComputer

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

'Find the Windows Directory
WinDir = WSHShell.ExpandEnvironmentStrings("%WinDir%")

'Grab the user name
UName = WSHNetwork.UserName

'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UName)

'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName

For Each GroupObj In UserObj.Groups
Select Case UCase(GroupObj.Name)
Case "Calgary Office"
WSHNetwork.MapNetworkDrive "G:", "\\CGYPDC01\Work_1"
WSHNetwork.MapNetworkDrive "I:", "\\CGYPDC01\Projects"
WSHNetwork.MapNetworkDrive "L:", "\\CGYPDC01\Work_1"
WSHNetwork.MapNetworkDrive "M:", "\\CGYSQL01\Deltek"

Case "Cost_Control"
WSHNetwork.MapNetworkDrive "H:", "\\CGYPDC01\Cost_Ctl"

Case "Map Accounting", "PayrollGroup", "CGYACCTGRP", "Accounting"
WSHNetwork.MapNetworkDrive "N:", "\\CGYPDC01\Acct"

Case "Business Development"
WSHNetwork.MapNetworkDrive "J:", "\\CGYPDC01\Busdev"

Case "Accounting", "Corporate Admin"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G006"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G018"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G046"

Case "2nd Floor"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G038"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G051"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G058"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G059"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G068"

Case "3rd Floor"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G026"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G027"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G037"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G048"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G050"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G056"

Case "4th Floor"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G010"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G011"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G047"

Case "5th Floor"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G033"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G034"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G040"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G045"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G056"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G061"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G064"

Case "Kinetic Colour"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G001"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G054"

Case "Corp Colour"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G066 Colour"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G066 Mono"

Case "4th Floor Color"
WSHNetwork.AddWindowsPrinterConnection "\\CGYPDC01\G065"

Case "PonokaCGYGRP", "EdmCgyGrp", "FtSaskCGYGRP"
WSHNetwork.MapNetworkDrive "G:", "\\CGYPDC01\Work_1"
WSHNetwork.MapNetworkDrive "I:", "\\CGYPDC01\Projects"
WSHNetwork.MapNetworkDrive "L:", "\\CGYPDC01\Work_2"

'********************************************************************************
'Edmonton:
'********************************************************************************
Case "EdmontonGRP"
WSHNetwork.MapNetworkDrive "R:", "\\EDMDC\Projects"
WSHNetwork.MapNetworkDrive "S:", "\\EDMDC\Work_2"
WSHNetwork.MapNetworkDrive "T:", "\\EDMDC\Work_1"

Case "GEN Solutions Projects"
WSHNetwork.MapNetworkDrive "R:", "\\EDMDC\Projects"

'********************************************************************************
'Ponoka:
'********************************************************************************
Case "PonokaGRP", "FtPonokaGRP"
WSHNetwork.MapNetworkDrive "P:", "\\PonokaDC\Projects"
WSHNetwork.MapNetworkDrive "Q:", "\\PonokaDC\General"
WSHNetwork.AddWindowsPrinterConnection "\\PonokaDC\P01"
WSHNetwork.AddWindowsPrinterConnection "\\PonokaDC\mita"

'********************************************************************************
'Fort Saskatchewan
'********************************************************************************
Case "FortGRP", "FtSaskAdmin", "Temp"
WSHNetwork.MapNetworkDrive "U:", "\\FtSaskDC\Projects"
WSHNetwork.MapNetworkDrive "V:", "\\FtSaskDC\General"
WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM01"
WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM02"
WSHNetwork.AddWindowsPrinterConnection "\\FtSaskDC\KPM03"

'********************************************************************************
'CAD Installations:
'********************************************************************************
Case "EdmCadGrp", "Drafting Users", "Drafting Leads", "Gem Drafting"
Dim Shell, File, struser, strprog
Set Shell = CreateObject("WScript.Shell")
struser = Shell.ExpandEnvironmentStrings("%appdata%")
strprog = Shell.ExpandEnvironmentStrings("%programfiles%")
Set ofs=WScript.CreateObject("Scripting.FilesystemObject")
Set oFile=ofs.GetFile("C:\program files\autocad 2007\acad.exe")
If Err.Number = 0 Then
Err.Number = 0
Set oFile=ofs.GetFile("c:\program files\gemini\geminiSetup.exe")
If Err.Number = 0 Then
Err.Number = 0
File = """c:\program files\gemini\geminiSetup.exe"""
Shell.Run File
Set oFile=ofs.GetFile(struser & "\gemini\manager.exe")
If Err.Number = 0 Then
Err.Number = 0
File = """" & struser & "\gemini\manager.exe"""
Shell.Run File
End If
Else
Err.Number = 0
MsgBox "AutoCAD Installation found! Setup Program not found" & chr(13) & "Please Contact CAD_Support before running AutoCAD", VBOK
End If
End If

Case Else
End Select
Next

Set WSHPrinters = WSHNetwork.EnumPrinterConnections
For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
'To remove only networked printers use this If Statement
If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
End If
'To remove all printers incuding LOCAL printers use this statement and comment out the If Statement above
'WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER +1),True,True
Next

'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing

'Quit the Script
wscript.quit
 
Nope; the case matches exactly what is written there. I have gone through and verified that.
 
Replace this:

Code:
Select Case UCase(GroupObj.Name)

With this:

Code:
Select Case(GroupObj.Name)

The UCASE will convert all the group names to upper case hence UCASE.
 
Oh wow, thank you so much Brycspain (and any others that provided input).

You have been incredibly helpful and have lifted a great stress from my shoulders. Sorry to be such a "n00b"; scripting just isn't my thing! =)

Anyway, thanks very much again. Hopefully this will be the last of it!

Regards,

Jeremy
 
ColdFlame,

I was in your position about a year ago and I wore Markdmac and other's on this board out. Just glad I can help...isn't vbscripting cool?
 
I wouldn't go as far as to say it's "Cool", but I will say it can do some pretty powerful things. *laughs* We'll see how many other snippets of code I manage to find and end up implementing as a result of Markdmac and others such as yourself.

You definitely did help me out, and I do very much appreciate it.

Regards,

Jeremy
 
Is there any easy way to remove all network drives? Much like the printers, I'd prefer drive mappings to be cleared and then remapped. Particularly because I'll be changing a couple drive letters in one of my remote office locations and don't want them to have multiple mappings to the same share/resource with different letters. They're illiterate enough without having to worry about that! :p

BTW, the above posted script works great, however I had to move the "Remove network printer" portion up towards the top as it mapped the printers properly, then removed them as a result of that statement and the order in which it was processed.

Thanks in advance!
 
Nevermind; I missed it in markdmac's script.

My apologies to waste your time!

Thanks again,

Jeremy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top