升级到Windows 7 64位后VBS脚本无法正常工作 [英] VBS script not working after upgrading to Windows 7 64bit

查看:80
本文介绍了升级到Windows 7 64位后VBS脚本无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的脚本。

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




映射网络驱动器工作正常,但添加网络打印机却没有。此脚本在Windows XP,Vista和7 32位下运行良好。现在我们在Windows 7 64bit中使用它,它不再连接到我们的打印机。任何建议都值得赞赏。


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.

 

推荐答案

我建议发布您的问题官方脚本专家论坛!或者主持人可以将其移到那里:

I would recommend posting your question to The Official Scripting Guys Forum!, or perhaps a moderator can move it there:

http://social.technet.microsoft.com/Forums/en-US/ITCG/threads

此论坛是主要用于Visual Basic .NET。

This forum is primarily for Visual Basic .NET.


这篇关于升级到Windows 7 64位后VBS脚本无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆