locked
VBS script not working after upgrading to Windows 7 64bit RRS feed

  • Question

  • Here is my script.

    on error resume next
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set AllDrives = WshNetwork.EnumNetworkDrives()
    Set oShell = CreateObject("Shell.Application")
    '**************************************Initiliaze Variables**************************************************
    Dim usrName
    usrName = WshNetwork.UserName
    usrName = Lcase(usrName)
    
    '**************************************Map network Folders***************************************************
    Drive_N = "N:" 'Word Processing folder
    RemotePath_N = "\\fndfs.MyDomain.com\MyShared$"
    Drive_O = "O:" 'shared O drive
    RemotePath_O = "\\MyFS.MyDomain.com\shared$"
    
    N_Connected = False
    O_Connected = False
    
    
    For i = 0 To AllDrives.Count - 1 Step 2
      If AllDrives.Item(i) = Drive_N Then N_Connected = True  
      If AllDrives.Item(i) = Drive_O Then O_Connected = True
    Next
    
    'mapped the "N" drive
    If N_Connected = False then
      WShNetwork.MapNetworkDrive Drive_N, RemotePath_N
    Else
      WShNetwork.RemoveNetworkDrive Drive_N
      WShNetwork.MapNetworkDrive Drive_N, RemotePath_N
    End If
    oShell.NameSpace("N:\").Self.Name = "Word Processing"
    
    
    
    '**************************Custom Network Drive Map***********************************************************
    If usrName = "smithc" Then  
    
      If O_Connected = False then
        WShNetwork.MapNetworkDrive Drive_O, RemotePath_O
      Else
        WShNetwork.RemoveNetworkDrive Drive_O
        WShNetwork.MapNetworkDrive Drive_O, RemotePath_O
      End If
      oShell.NameSpace("O:\").Self.Name = "CT3 Shared"
    
    End If
    
    '**************************************Map network printers**************************************************
    Set Printers = WshNetwork.EnumPrinterConnections
    
    '****************Assign the network printer path to a variable**********************************************
    HP4100 = "\\server1.MyDomain.com\HPLJ4100n"
    HP8000PCL = "\\server1.MyDomain.com\HPLJ_8000N"
    HP4250_1 = "\\server1.MyDomain.com\HPLJ4250#1"
    HP4250_2 = "\\server1.MyDomain.com\HPLJ4250#2"
    HP4250_4 = "\\server1.MyDomain.com\HPLJ4250#4"
    HP4250_5 = "\\server1.MyDomain.com\HPLJ4250#5"
    HP3550 = "\\server1.MyDomain.com\hpLJCol3550"
    HPCol3600 = "\\server1.MyDomain.com\HPLJCol3600"
    XR5550 = "\\server1.MyDomain.com\Phaser5550DN_PS"
    
    LPT2_port = "LPT2"
    
    '**********Initialy set the network printer connection to false*********************************************
    HP4_Connected = False
    HP4250_1Connected= False
    HP3550_Connected = False
    HP4250_2Connected = False
    HP4250_4Connected = False
    HP4250_5Connected = False
    HP8PCL_Connected = False
    HPCol3600_Connected = False
    XR5550_Connected = False
    LPT2_Connected = False
    
    '**********************Determined if the printer is already connected******************************************
    For i = 0 to Printers.Count - 1 Step 2
      If Printers.Item(i+1) = HP4100 Then HP4_Connected = True
      If Printers.Item(i+1) = HP4250_1 Then HP4250_1Connected= True
      If Printers.Item(i+1) = HP4250_1PS Then HP4250_1psConnected= True
      If Printers.Item(i+1) = HP3550 Then HP3550_Connected = True
      If Printers.Item(i+1) = HPCol3600 Then HPCol3600_Connected = True
      If Printers.Item(i+1) = HP4250_2 Then HP4250_2Connected = True
      If Printers.Item(i+1) = HP4250_2PS Then HP4250_2psConnected = True
      If Printers.Item(i+1) = HP4250_4 Then HP4250_4Connected = True
      If Printers.Item(i+1) = HP4250_4PS Then HP4250_4psConnected = True
      If Printers.Item(i+1) = HP4250_5PS Then HP4250_5psConnected = True
      If Printers.Item(i+1) = HP8000PCL Then HP8PCL_Connected = True
      If Printers.Item(i+1) = XR5550 Then XR5550_Connected = True
      If Printers.Item(i) = LPT2_port Then LPT2_Connected = True
    Next
    
    '***********************Connecting to network shared printers**************************************************
    'Teresa and Wyane are haiving problems printing reports from RE and FE because the default printer kept default to
    'the 4100 and 4250#1 so I've made the following modification so that they don't get these two printers mapped to their profile
    
    If usrName <> "schneiderR" AND usrName <> "bobt" Then
      If HP4_Connected = False Then
        WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4100n"
      Else
        WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\HPLJ4100n"
        WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4100n"
      End If
    
      If HP4250_1Connected= False Then
        WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4250#1"
      Else
        WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\HPLJ4250#1"
        WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4250#1"
      End If
    
    End If
    
    If HP8PCL_Connected = False Then
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ_8000N"
    Else
      WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\HPLJ_8000N"
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ_8000N"
    End If
    
    If XR5550_Connected = False Then
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\Phaser5550DN_PS"
    Else
      WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\Phaser5550DN_PS"
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\Phaser5550DN_PS"
    End If
    
    If HP3550_Connected = False Then
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\hpLJCol3550"
    Else
      WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\hpLJCol3550"
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\hpLJCol3550"
    End If
    
    If HPCol3600_Connected = False Then
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJCol3600"
    Else
      WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\HPLJCol3600"
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJCol3600"
    End If
    
    
    If HP4250_2Connected = False Then
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4250#2"
    Else
      WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\HPLJ4250#2"
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4250#2"
    End If
    
    If HP4250_4Connected = False Then
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4250#4"
    Else
      WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\HPLJ4250#4"
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4250#4"
    End If
    
    If HP4250_5Connected = False Then
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4250#5"
    Else
      WshNetwork.RemovePrinterConnection "\\server1.MyDomain.com\HPLJ4250#5"
      WshNetwork.AddWindowsPrinterConnection "\\server1.MyDomain.com\HPLJ4250#5"
    End If
    
    '********************************Setting Custom Printers*******************************************************
    'WshShell.PopUp usrName
    
    If usrName = "bobT" Or usrName = "johnsonc" Then
      If LPT2_Connected = False Then
        WshNetwork.AddPrinterConnection "LPT2", "\\server1.MyDomain.com\HPLJ4250#2"
      Else
        WshNetwork.RemovePrinterConnection "LPT2"
        WshNetwork.AddPrinterConnection "LPT2", "\\server1.MyDomain.com\HPLJ4250#2"
      End If
        
    End If
    
    '********************************Setting default printer according to user*************************************
    If usrName = "busht" Then
      WshNetwork.SetDefaultPrinter "\\server1.MyDomain.com\HPLJ4100n"
    ElseIf usrName = "bobt" Then
      WshNetwork.SetDefaultPrinter "\\server1.MyDomain.com\Phaser5550DN_PS"
    ElseIf usrName = "mayab" Then
      WshNetwork.SetDefaultPrinter "\\server1.MyDomain.com\HPLJ4250#1"
    ElseIf usrName = "schneiderR" Then
      WshNetwork.SetDefaultPrinter "\\server1.MyDomain.com\HPLJ4250#2"
    ElseIf usrName = "weisD" Or usrName = "lorcho" Or usrName = "charlie" Then
      WshNetwork.SetDefaultPrinter "\\server1.MyDomain.com\HPLJ4250#4"
    ElseIf usrName = "mashp" Then
      WshNetwork.SetDefaultPrinter "\\server1.MyDomain.com\HPLJ4250#5"
    Else
      WshNetwork.SetDefaultPrinter "\\server1.MyDomain.com\HPLJ_8000N"
    End If

    The mapping network drive works just fine but the adding network printer does not. This script works perfectly fine under Windows XP, Vista, and 7 32bit. Now we have it in Windows 7 64bit and it's no longer connecting to our printers. Any suggestion is much appreciated.

     

    • Moved by Andreas Johansson Thursday, August 4, 2011 9:57 PM OT (From:Visual Basic General)
    Thursday, August 4, 2011 6:19 PM

All replies