Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


remove all network drives and printers at logon

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2605
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> remove all network drives and printers at logon
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 remove all network drives and printers at logon - 4/6/2005 9:27:56 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Dear,

I cannot find anything of reference to my problem hence the post :)

I wish to remove all network drives and printers at logon although i do not know if they have anything mapped. I was hoping for something like

objNetwork.RemoveNetworkDrive "*:"

But no joy....

can someone help please?
 
 
Post #: 1
 
 Re: remove all network drives and printers at logon - 4/6/2005 11:32:21 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Take a look at the WSH docs, they have 2 different scripts that would help you.

Taken directly from the docs.
Enumerate network printers and drive mappings

      
Remove network drives

      
Remove network printers

      

(in reply to AzzerShaw)
 
 
Post #: 2
 
 Re: remove all network drives and printers at logon - 4/7/2005 12:27:10 AM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Can you show me an example?

I done:

__________________________________________

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
WScript.Echo "Network drive mappings:"
For i = 0 to oDrives.Count - 1 Step 2
WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)

WshNetwork.RemoveNetworkDrive oDrives.Item(i)
Next
WScript.Echo
WScript.Echo "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)

WshNetwork.RemovePrinterConnection oPrinters.Item(i)

Next

________________________________________

It seems to pick up only one of my network drives and doesnt delete it anyway. It misses about 5 others. Can you show me an example before my pc goes through the window.

Thanks

(in reply to AzzerShaw)
 
 
Post #: 3
 
 Re: remove all network drives and printers at logon - 4/7/2005 6:07:50 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Is the mapped drive in use ? If so, you could try the following.

WshNetwork.RemoveNetworkDrive oDrives.Item(i), true

(in reply to AzzerShaw)
 
 
Post #: 4
 
 Re: remove all network drives and printers at logon - 4/7/2005 8:09:22 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
The saga continues....

It now comes up with an error and still doesnt delete any mappings or printers

...........................

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
WScript.Echo "Network drive mappings:"
For i = 0 to oDrives.Count - 1 Step 2
WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)

WshNetwork.RemoveNetworkDrive oDrives.Item(i),true
Next
WScript.Echo
WScript.Echo "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)

WshNetwork.RemovePrinterConnection oPrinters.Item(i),true

Next

................................

I get a error on line 15 char 1 saying "This network connection does not exist"

Source - Wshnetwork.removenetworkdrive

Which makes no sense cause WshNetwork.RemovePrinterConnection is on line 15 ><

(in reply to AzzerShaw)
 
 
Post #: 5
 
 Re: remove all network drives and printers at logon - 4/7/2005 8:19:29 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
The saga continues....

It now comes up with an error and still doesnt delete any mappings or printers

...........................

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
WScript.Echo "Network drive mappings:"
For i = 0 to oDrives.Count - 1 Step 2
WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)

WshNetwork.RemoveNetworkDrive oDrives.Item(i),true
Next
WScript.Echo
WScript.Echo "Network printer mappings:"
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)

WshNetwork.RemovePrinterConnection oPrinters.Item(i),true

Next

................................

I get a error on line 15 char 1 saying "This network connection does not exist"

Source - Wshnetwork.removenetworkdrive

Which makes no sense cause WshNetwork.RemovePrinterConnection is on line 15 ><

(in reply to AzzerShaw)
 
 
Post #: 6
 
 Re: remove all network drives and printers at logon - 4/8/2005 7:48:15 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
When you remove the 2 lines below,

WshNetwork.RemoveNetworkDrive oDrives.Item(i),true
WshNetwork.RemovePrinterConnection oPrinters.Item(i),true

What do you see ?

(in reply to AzzerShaw)
 
 
Post #: 7
 
 Re: remove all network drives and printers at logon - 4/10/2005 8:24:09 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
I see a list of my drives. For example

Drive E: = \\server\myfolder

and printer

Port Techresp = \\Pserver\Printer

(in reply to AzzerShaw)
 
 
Post #: 8
 
 Re: remove all network drives and printers at logon - 4/10/2005 11:44:59 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Okay worked it out myself. To delete all printer connections (not local) and remove all mapped drives, the code is as follows

______________________________

On error resume next

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to oDrives.Count - 1 Step 2
WshNetwork.RemoveNetworkDrive oDrives.Item(i),true,true
Next
For i = 0 to oPrinters.Count - 1 Step 2
WScript.Echo oPrinters.Item(i+1)
WshNetwork.RemovePrinterConnection oPrinters.Item(i+1)

Next

______________________________________________

(in reply to AzzerShaw)
 
 
Post #: 9
 
 Re: remove all network drives and printers at logon - 4/11/2005 1:49:46 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Glad you have it worked out =)

(in reply to AzzerShaw)
 
 
Post #: 10
 
 
 
  

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 >> remove all network drives and printers at logon Page: [1]
Jump to:





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