Click here to Skip to main content
15,917,005 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionSingle click on a checked list box Pin
steve_rm7-Dec-06 19:04
steve_rm7-Dec-06 19:04 
AnswerRe: Single click on a checked list box [modified] Pin
steve_rm7-Dec-06 19:13
steve_rm7-Dec-06 19:13 
QuestionVirtual Printer Driver in Vb.net Pin
sandeegk777-Dec-06 18:24
sandeegk777-Dec-06 18:24 
QuestionSearch Database Pin
The ANZAC7-Dec-06 18:05
The ANZAC7-Dec-06 18:05 
AnswerRe: Search Database Pin
Christian Graus7-Dec-06 18:40
protectorChristian Graus7-Dec-06 18:40 
GeneralRe: Search Database Pin
The ANZAC7-Dec-06 18:44
The ANZAC7-Dec-06 18:44 
QuestionSet blank for 1st item combolist in VSFlexGrid Pin
angelagke7-Dec-06 17:05
angelagke7-Dec-06 17:05 
QuestionVB script not workng on Win 2000 Pin
japel7-Dec-06 10:53
japel7-Dec-06 10:53 
This script works great on the XP box I wrote it on but not on a Win 2000 box.

The script was found while Googling and I have added the rename sub and a few other changes to suite my required task.

I am reletivly new to dev and am not sure if the problem is win2k supporting the script or if the script needs changing.

The problem is at line 70 creating the tcp ip ports. if I take this out the script runs to completion telling me the printers are added but they are not.

I manually added the ports and re ran the script but no luck.

Please help...

<br />
'This script will add ip ports for your local printers and attach printers to<br />
'those ports. Just edit the arrays to reflect the paths for the .INF files<br />
'and get the printer descriptions from the .INF files. If the printer is listed<br />
'in the system32/inf/ntprint.inf use that as the .INF it tells the script where<br />
'to look for the driver otherwise use the UNC path to get the path.<br />
'===================================================<br />
strComputer = "."<br />
'strComputer can be an array of netbios computer names or<br />
'ip addresses put into a for loop<br />
'===================================================<br />
<br />
Public Error<br />
Dim Count:Count=0<br />
Set WshShell = WScript.CreateObject("WScript.Shell")<br />
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")<br />
<br />
<br />
Wscript.echo "This process may take several minutes please be patient." & VbCrLf _<br />
				& "Another pop-up box will inform you when it is finished."<br />
				<br />
'Here is where your edit the port IP addresses<br />
'===================================================<br />
Dim IPArray<br />
IPArray = Array( "192.168.100.1","192.168.100.1")<br />
Dim PrintersArray<br />
'===================================================<br />
<br />
'Here is where you enter the driver inf paths<br />
PrintersArray=Array("C:\CanonDrivers\win2k_xp_PCLModBW\P52KUKAL.INF",_<br />
"C:\CanonDrivers\win2k_xp_PS_2-9\W2KPS3K.INF")<br />
'===================================================<br />
<br />
'Here is where you edit the printer names<br />
Dim PrinterNames<br />
PrinterNames=Array("Canon iR C5180 PCL5c", "Canon iR C5180 PS3")<br />
'===================================================<br />
<br />
'Here is where you edit the new printer names<br />
Dim PrinterNewNames<br />
PrinterNewNames=Array("Black and White", "Colour")<br />
'===================================================<br />
<br />
For n = LBound(IPArray) To UBound(IPArray)<br />
'Install the IP printer ports<br />
Install_IP_Ports IPArray(n)<br />
Next<br />
For n = LBound(IPArray) To UBound(IPArray)<br />
Count = Count + 1 'just increments the counter for the message at the end!<br />
'===================================================<br />
<br />
'Add the printers (Arguments: ip port, path to the .inf files, printer name)<br />
'get the name from the inf files or make one up!<br />
'===================================================<br />
<br />
Add_local_ip_printer IPArray(n), PrintersArray(n),PrinterNames(n)<br />
Next<br />
'===================================================<br />
<br />
'If only one printer in array set to zero e.g. PrinterNames(0) or comment out!=<br />
Make_Default_printer PrinterNewNames(0)<br />
<br />
'===================================================<br />
'Install the TCP/IP Port(s):<br />
Function Install_IP_Ports(strIPAddress)<br />
<br />
Set objWMIService = GetObject("Winmgmts:")<br />
objWMIService.Security_.Privileges. _<br />
    AddAsString "SeLoadDriverPrivilege", True<br />
<br />
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_<br />
objNewPort.Name = strIPAddress<br />
objNewPort.Protocol = 2<br />
objNewPort.HostAddress = strIPAddress<br />
objNewPort.PortNumber = "515"<br />
objNewPort.Queue = "lp"<br />
objNewPort.SNMPCommunity = "public"<br />
objNewPort.SNMPEnabled = False<br />
objNewPort.Put_<br />
<br />
'stop the spooler<br />
Set colServiceList = objWMIService.ExecQuery _<br />
("Select * from Win32_Service where Name='Spooler'")<br />
For Each objService In colServiceList <br />
errReturn = objService.StopService()<br />
WScript.Sleep 1000<br />
Next<br />
<br />
'start the spooler<br />
For Each objService In colServiceList<br />
errReturn = objService.StartService()<br />
WScript.Sleep 5000<br />
Next<br />
<br />
End Function<br />
<br />
Function Add_local_ip_printer(strIP,strPath_To_Inf_Files,strPrintername)<br />
<br />
WSHShell.run ("CMD.EXE /C RUNDLL32 PRINTUI.DLL,PrintUIEntry /if /b "_<br />
& chr(34) & strPrinterName & chr(34) & " /f " & chr(34) _<br />
& strPath_To_Inf_Files & chr(34) & " /r " & chr(34) _<br />
& strIP & chr(34) & " /m " & chr(34) & strPrinterName & chr(34) _<br />
& " /q /u"),0,True<br />
<br />
ReNamePrinter strPrintername,PrinterNewNames(n)<br />
<br />
End Function<br />
<br />
Function ReNamePrinter(prnName,prnNewName)<br />
<br />
Set objWMIService = GetObject("winmgmts:" _<br />
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")<br />
<br />
Set colPrinters =  objWMIService.ExecQuery _<br />
    ("Select * from Win32_Printer Where DeviceID = '" & prnName & "'" )<br />
<br />
For Each objPrinter in colPrinters<br />
    objPrinter.RenamePrinter(prnNewName)<br />
    'objPrinter.Put_<br />
Next<br />
<br />
End Function<br />
<br />
Function Make_Default_printer(strPrinterName)<br />
<br />
Set colInstalledPrinters = objWMIService.ExecQuery _<br />
("Select * from Win32_Printer") <br />
For Each objPrinter in colInstalledPrinters<br />
If objPrinter.Name = strPrinterName Then<br />
objPrinter.SetDefaultPrinter()<br />
End If<br />
Next<br />
<br />
End Function<br />
<br />
Wscript.echo "Install completed, please check you have 2 printers added" & VbCrLf _<br />
				& "One named 'Black and White' and the other named 'Colour'"<br />
'End Script<br />


When people make you see red, be thankful your not colour blind.

QuestionRound to nearest quarter of hour Pin
VK-Cadec7-Dec-06 10:07
VK-Cadec7-Dec-06 10:07 
AnswerRe: Round to nearest quarter of hour Pin
Uber17-Dec-06 15:51
Uber17-Dec-06 15:51 
GeneralRe: Round to nearest quarter of hour Pin
Uber17-Dec-06 16:28
Uber17-Dec-06 16:28 
QuestionC++ and VB.NET Pin
Kornfeld Eliyahu Peter7-Dec-06 9:39
professionalKornfeld Eliyahu Peter7-Dec-06 9:39 
QuestionHow to get multiple key states simultaneously Pin
Gregbob7-Dec-06 7:41
Gregbob7-Dec-06 7:41 
AnswerRe: How to get multiple key states simultaneously Pin
Christian Graus7-Dec-06 8:11
protectorChristian Graus7-Dec-06 8:11 
QuestionHow to control tab size Pin
adairjk7-Dec-06 5:58
adairjk7-Dec-06 5:58 
Questionmdi application error Pin
kharkov927-Dec-06 5:15
kharkov927-Dec-06 5:15 
AnswerRe: mdi application error Pin
minhnguyen089-Dec-06 1:04
minhnguyen089-Dec-06 1:04 
GeneralRe: mdi application error Pin
kharkov9211-Dec-06 4:07
kharkov9211-Dec-06 4:07 
QuestionCallbackOnCollectedDelegate with keeyboard Hook Pin
tessers7-Dec-06 1:31
tessers7-Dec-06 1:31 
Questionsharing of a translucent form using netmeeting Pin
rumadash7-Dec-06 0:14
rumadash7-Dec-06 0:14 
AnswerRe: sharing of a translucent form using netmeeting Pin
Dave Kreskowiak7-Dec-06 15:04
mveDave Kreskowiak7-Dec-06 15:04 
GeneralRe: sharing of a translucent form using netmeeting Pin
rumadash7-Dec-06 16:00
rumadash7-Dec-06 16:00 
GeneralRe: sharing of a translucent form using netmeeting Pin
Dave Kreskowiak7-Dec-06 18:00
mveDave Kreskowiak7-Dec-06 18:00 
Questionhow to download binary file from SQL SERVER to VB.NET Pin
Syed Ali Raza6-Dec-06 22:27
Syed Ali Raza6-Dec-06 22:27 
AnswerRe: how to download binary file from SQL SERVER to VB.NET Pin
Alessandro7-Dec-06 1:57
Alessandro7-Dec-06 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.