Dim oWsh, strUserProfile , oFSO, oFile
Set oWsh = WScript.CreateObject("WScript.Shell")
strUserProfile = ws.ExpandEnvironmentStrings("%userprofile%")
Set oFSO= CreateObject("Scripting.FileSystemObject")
Set oFile= oFSO.CreateTextFile("strUserProfile\file.txt")
strUserProfile = oWsh.ExpandEnvironmentStrings("%userprofile%")
Dim oWsh, strUserProfile, oFSO, oFile
Call LogEntry("TEST")
Function LogEntry(LogEntryText)
Set oWsh = WScript.CreateObject("WScript.Shell")
strUserProfile = oWsh.ExpandEnvironmentStrings("%userprofile%")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.OpenTextFile(strUserProfile & "\file.txt", 8, True, 0)
oFile.WriteLine "<![LOG[" & LogEntryText & "]LOG]!><time=""" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & ".001+240"" date=""" & Replace(Date, "/", "-") & """ component=""PrintMapDelete"" context="""" type=""1"" thread=""0"" file=""" & WScript.Application & " " & WScript.Version & """>"
End Function
Dim oWsh, strUserProfile , oFSO, oFile
Call LogEntry("TEST")
Function LogEntry (LogEntryText)
Set oWsh = WScript.CreateObject("WScript.Shell")
strUserProfile = oWsh.ExpandEnvironmentStrings("%userprofile%")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(strUserProfile & "\file.txt")
oFile.Close
Set oFile = oFSO.OpenTextFile(strUserProfile & "\file.txt", 8, True, 0)
oFile.WriteLine "<![LOG[" & LogEntryText & "]LOG]!><time=""" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & ".001+240"" date=""" & Replace(Date(), "/", "-") & """ component=""PrintMapDelete"" context="""" type=""1"" thread=""0"" file=""" & WScript.Application & " " & WScript.Version & """>"
End Function
Dim oWsh, strUserProfile, oFSO, oFile, strFile
Call LogEntry("LogEntryText")
Function LogEntry(LogEntryText)
Set oWsh = WScript.CreateObject("WScript.Shell")
strUserProfile = oWsh.ExpandEnvironmentStrings("%userprofile%")
strFile = strUserProfile & "\file.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FileExists(strFile) Then
oFSO.CreateTextFile strFile
End If
Set oFile = oFSO.OpenTextFile(strFile, 8, 0)
oFile.WriteLine "<![LOG[" & LogEntryText & "]LOG]!><time=""" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & ".001+240"" date=""" & Replace(Date, "/", "-") & """ component=""PrintMapDelete"" context="""" type=""1"" thread=""0"" file=""" '& WScript.Application & " " & WScript.Version & """>"
End Function
Set objFile = objFSO.CreateTextFile(strFile)
oFSO.CreateTextFile strFile
Dim oWsh, strUserProfile, oFSO, oFile, strFile
Call LogEntry("LogEntryText")
Function LogEntry(LogEntryText)
Set oWsh = WScript.CreateObject("WScript.Shell")
strUserProfile = oWsh.ExpandEnvironmentStrings("%userprofile%")
strFile = strUserProfile & "\file.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FileExists(strFile) Then
oFSO.CreateTextFile strFile
End If
Set oFile = oFSO.OpenTextFile(strFile, 8, 0)
oFile.WriteLine "<![LOG[" & LogEntryText & "]LOG]!><time=""" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & ".001+240"" date=""" & Replace(Date, "/", "-") & """ component=""PrintMapDelete"" context="""" type=""1"" thread=""0"" file=""" '& WScript.Application & " " & WScript.Version & """>"
End Function
Dim oWsh, strUserProfile, oFSO, oFile, strFile
Call LogEntry("LogEntryText")
Function LogEntry(LogEntryText)
Set oWsh = WScript.CreateObject("WScript.Shell")
strUserProfile = oWsh.ExpandEnvironmentStrings("%userprofile%")
strFile = strUserProfile & "\file.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FileExists(strFile) Then
oFSO.CreateTextFile strFile
End If
Set oFile = oFSO.OpenTextFile(strFile, 8, 0)
oFile.WriteLine "<![LOG[" & LogEntryText & "]LOG]!><time=""" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & ".001+240"" date=""" & Replace(Date, "/", "-") & """ component=""PrintMapDelete"" context="""" type=""1"" thread=""0"" file=""" '& WScript.Application & " " & WScript.Version & """>"
End Function
strSrvName1 = "\\server1\HP"
strSrvName2 = "\\server2\Dell"
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = WshNetwork.EnumPrinterConnections
For intPrinter = 0 To colPrinters.Count - 1 Step 2
strPrinterPort = colPrinters(intPrinter)
strPrinterName = colPrinters(intPrinter + 1)
LogEntry strPrinterName & " - " & strPrinterPort
If left(colPrinters.Item(intPrinter + 1),len(strSrvName1)) = strSrvName1 Then
LogEntry " Printer matches target name. Printer will be deleted"
On Error Resume Next
WshNetwork.RemovePrinterConnection strPrinterName
If Err.Number = 0 Then
LogEntry " Printer was succesfully deleted"
Else
LogEntry " An error occured while deleting the printer. Error Number: " & Err.Number & " Error Description: " & Err.Description
End If
Else
LogEntry " Printer does not match target name. No action required"
End If
If left(colPrinters.Item(intPrinter + 1),len(strSrvName2)) = strSrvName2 Then
LogEntry " Printer matches target name. Printer will be deleted"
On Error Resume Next
WshNetwork.RemovePrinterConnection strPrinterName
If Err.Number = 0 Then
LogEntry " Printer was succesfully deleted"
Else
LogEntry " An error occured while deleting the printer. Error Number: " & Err.Number & " Error Description: " & Err.Description
End If
Else
LogEntry " Printer does not match target name. No action required"
End If
Next
Dim oWsh, strUserProfile , oFSO, oFile
Call LogEntry("TEST")
Function LogEntry (LogEntryText)
Set oWsh = WScript.CreateObject("WScript.Shell")
strUserProfile = oWsh.ExpandEnvironmentStrings("%userprofile%")
MsgBox "The current users profile is located at: " & strUserProfile
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(strUserProfile & "\file.txt")
oFile.Close
Set oFile = oFSO.OpenTextFile(strUserProfile & "\file.txt", 8, True, 0)
oFile.WriteLine "<![LOG[" & LogEntryText & "]LOG]!><time=""" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & ".001+240"" date=""" & Replace(Date(), "/", "-") & """ component=""PrintMapDelete"" context="""" type=""1"" thread=""0"" file=""" & WScript.Application & " " & WScript.Version & """>"
End Function
strSrvName1 = "\\server1\HP"
strSrvName2 = "\\server2\Dell"
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set colPrinters = WshNetwork.EnumPrinterConnections
For intPrinter = 0 To colPrinters.Count - 1 Step 2
strPrinterPort = colPrinters(intPrinter)
strPrinterName = colPrinters(intPrinter + 1)
LogEntry strPrinterName & " - " & strPrinterPort
If Left(colPrinters.Item(intPrinter + 1), Len(strSrvName1)) = strSrvName1 Then
LogEntry " Printer matches target name. Printer will be deleted"
On Error Resume Next
WshNetwork.RemovePrinterConnection strPrinterName
If Err.Number = 0 Then
LogEntry " Printer was succesfully deleted"
Else
LogEntry " An error occured while deleting the printer. Error Number: " & Err.Number & " Error Description: " & Err.Description
End If
Else
LogEntry " Printer does not match target name. No action required"
End If
If Left(colPrinters.Item(intPrinter + 1), Len(strSrvName2)) = strSrvName2 Then
LogEntry " Printer matches target name. Printer will be deleted"
On Error Resume Next
WshNetwork.RemovePrinterConnection strPrinterName
If Err.Number = 0 Then
LogEntry " Printer was succesfully deleted"
Else
LogEntry " An error occured while deleting the printer. Error Number: " & Err.Number & " Error Description: " & Err.Description
End If
Else
LogEntry " Printer does not match target name. No action required"
End If
Next
Function LogEntry(LogEntryText)
Set oWsh = WScript.CreateObject("WScript.Shell")
strUserProfile = oWsh.ExpandEnvironmentStrings("%userprofile%")
MsgBox "The current users profile is located at: " & strUserProfile
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(strUserProfile & "\file.txt")
oFile.Close
Set oFile = oFSO.OpenTextFile(strUserProfile & "\file.txt", 8, True, 0)
oFile.WriteLine "<![LOG[" & LogEntryText & "]LOG]!><time=""" & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & ".001+240"" date=""" & Replace(Date, "/", "-") & """ component=""PrintMapDelete"" context="""" type=""1"" thread=""0"" file=""" & WScript.Application & " " & WScript.Version & """>"
oFile.Close
End Function
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to oDrives.Count - 1 Step 2
WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
Next
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)
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)
Next
Open in new window