vbscript and prncnfg.vbs inside? - printing

I have a vbscript to get some informations about the system printing of a remote computer. I can get all the drivers installed, the default network printer name and all my results are send in a outputfile.
I want to get informations about my default network printer by the prncnfg.vbs from the printer server (driver, location, etc.) and send these informations in my outputfile.
Maybe there is an other way to do that ?
Thanks for any suggestions

So, I start to understand the way to do that. But something doesn't work.
First I need to read a file and remove 10 caracters to create my variable, this process works very well:
'Read C:\Temp\DefaultPrinter
Dim shortDefaultPrinter
If objFSO.FileExists("\"& strComputer &"\c$\Temp\DefaultPrinter.txt") then
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("\"& strComputer &"\c$\Temp\DefaultPrinter.txt",1)
DefaultPrinter = objFileToRead.ReadAll()
'remove text \vangogh\
shortDefaultPrinter = Right(DefaultPrinter, Len(DefaultPrinter) - 10)
'MsgBox(shortDefaultPrinter)
objFileToRead.Close
Set objFileToRead = Nothing
Second I want to use my variable shortDefaultPrinter for my query to find the location of my printer:
'Select DefaultPrinter and show location
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName, Location from " _
& " 'LDAP://DC=huge,DC=ad,DC=hcuge,DC=ch' where objectClass='printQueue' and printerName='" & shortDefaultPrinter & "' "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
PrinterLocation = objRecordSet.Fields("Location").Value
MsgBox(PrinterLocation)
objRecordSet.MoveNext
Loop
MsgBox doesn't open, but if I write the name of the printer in place of " & shortDefaultPrinter & ", ex dmed-i714, the process works.
Here I am. If anyone has a suggestion it would be appreciate.

Related

Sending emails to recipients if certain cell value is met by each receipient

Basically I've used Google Sheets to create an invoice tracker, and I want to send a reminder email to each of my clients when their invoice is due. I've already set the date and the count down, and now I want to send them the reminder email when the cell value reaches "2" meaning 32 days has passed since I've invoiced them.
I've gathered the codes from different sources online, and also I've set a 24 hr trigger to run the code once in a day. The email template is also in place. Data of each client (dates, names, addresses, etc.) are listed in separate rows.
My problem is that instead of sending 1 single email to the right client, the mailing app sends emails to all clients when any of them have a due invoice!
I'm not sure which function or code I should use.
I tried 'Email_Sent' thing, but couldn't get anywhere good with it!
function CheckMaturity() {
// Fetch invoice maturity
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('InvoiceTracker').activate();
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
for (var i = 5;i<=10;i++){
var invoiceMaturityRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('InvoiceTracker').getRange(i, 13);
var invoiceMaturity = invoiceMaturityRange.getValue();
// Check invoice maturity
if (invoiceMaturity = 2){
// Fetch the email address
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('InvoiceTracker').activate();
var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('EmailTemplate').getRange(1,1).getValue();
var currentAddress = ss.getRange(i, 15).getValue();
var currentInvoiceNo = ss.getRange(i, 3).getValue();
var currentInvoiceDate = ss.getRange(i, 4).getValue();
var currentClient = ss.getRange(i, 14).getValue();
var messageBody = templateText.replace('{client}',currentClient).replace('{invoiceNo}',currentInvoiceNo).replace('{invoiceDate}', currentInvoiceDate);
var subjectLine = 'Kind reminder - Invoice status';
MailApp.sendEmail(currentAddress, subjectLine, messageBody);{
SpreadsheetApp.getActiveSpreadsheet().toast('Invoice reminder sent to' +currentClient, 'Reminder sent', -1);
}
}
}
}
I want the app to send only one single email to the right (relevant) client.
I think you need the below. Please check the variables and references. The following code should be adjusted. The column 'A' should be replaced with the column in which you have the last record to prevent that you miss any clients. Furthermore, please check the comments in the code below.
.Range("A1047854").End(xlUp).Row
And hereby the full code:
Sub SendEmails()
Dim myOlApp As Outlook.Application, MailItem As Outlook.MailItem
Dim attachmentPath1 As String, attachmentPath2 As String
Set myOlApp = CreateObject("Outlook.Application")
'loop through a sheet (change index)
For i = 1 To ThisWorkbook.Sheets("index").Range("A1047854").End(xlUp).Row
'set key for check (or just do it directly in the if)
invoiceMaturity = ThisWorkbook.Sheets("index").Range("A" & i).Value
If invoiceMaturity = "2" Then
'you can load the variables first, before adding them to the email, or add them directly.
Name = ""
MailAddress = ""
Address = ""
currentInvoiceNo = ""
currentInvoiceDate = ""
currentClient = ""
'make item for each iteration (again)
Set MailItem = myOlApp.CreateItem(olMailItem)
'attachments
attachmentPath1 = "path/to/file.something" 'or set to ""(nothing)
'body
MailItem.HTMLBody = "<B>" & "<h3>" & "DRAFT:" & "</h3>" & "</B>" & "<br>" & _
"Dear, " & "<br>" & "<br>" & _
"Please find enclosed a kind reminder.." & "<br>" & "<br>" & _
"Please note, that.." & "</b>" & "<br>" & "<br>" & _
"Should you have any questions or comments on the above, please do let us know." & "<br>" & "<br>" & _
"Kind regards," & "<br>" & "<br>" & _
"Signature"
MailItem.to = MailAddress 'adjust email
MailItem.Subject = "[subject of email" & "a variable?" 'adjust subject
MailItem.Show 'or mailitem.send
'just to make sure
Set MailItem = ""
End If
Next i
End Sub

LSXLC ODBC Stored Procedure

I'm trying to connect to an Oracle RDB database using LSXLC (ODBC Connector).
But when it comes to stored procedures I'm having a hard time getting it to work.
The code below always results in "Error: Parameter name not supplied: fnl_date, Connector 'odbc2', Method -Call-". The error is triggered on "count = connection.Call(input, 1, result)"
Can anyone tell me what I'm doing wrong?
Public Function testLsxlcProc()
On Error GoTo handleError
Dim connection As LCConnection("odbc2")
connection.Server = "source"
connection.Userid = "userid"
connection.Password = "password"
connection.procedure = "proc_name"
connection.Connect
If connection.IsConnected Then
Dim input As New LCFieldList()
Dim result As New LCFieldList()
Dim break As LCField
Set break = input.Append("fnl_date", LCTYPE_TEXT)
break.Text = "2014-07-01"
Dim agrNo As LCField
Set agrNo = input.Append("fnl_agreement_no", LCTYPE_TEXT)
agrNo.Text = "123456"
Dim curr As LCField
Set curr = input.Append("fnl_currency_code", LCTYPE_TEXT)
curr.Text = "SEK"
Dim stock As LCField
Set stock = input.Append("fnl_stock_id", LCTYPE_TEXT)
stock.Text = "01"
connection.Fieldnames = "status, value"
Dim count As Integer
count = connection.Call(input, 1, result)
Call logger.debug("Count: " & count)
Else
Error 2000, "Unable to connect to database."
End If
handleExit:
connection.Disconnect
Exit Function
handleError:
On Error Resume Next
Call logger.error(Nothing)
Resume handleExit
End Function
Thanks in advance!
I had made a stupid mistake and had a mismatch between the name of the input parameter in Domino and the name of the input parameter in the stored procedure.
Make sure all names match up and there shouldn't be a problem.
Stored-Procedure "mylib.MyStoredProc" wird aufgerufen ...
LcSession.Status = 12325: LC-Error: errCallStoredProc 12325 (Error: Parameter name not supplied: P_S651_AC, Connector 'odbc2', Method -Call-)
Solution: changed "mylib" into "MYLIB" and all was well.
Check not only Parameter-Names, but also the Search-Path.

Classic ASP - ADO execute Stored Procedure passing in parameters

I am needing to pass parameters into a stored procedure with Classic ASP. I do see some people using the Command object and others NOT using it.
My sproc params are like this:
#RECORD_NUMBER decimal(18,0),
#ErrorType nvarchar(100),
#INSURANCE_CODE smallint,
#CompanyId int,
#INS_ID_NUM nchar(22)
Then I'm trying to do this:
Dim conn, rsSet,rsString, cmd
Dim RN,ET,IC,CI,IIN
RN = Request.Form("Record_Number")
ET = Request.Form("ErrorType")
IC = Request.Form("INSURANCE_CODE")
CI = Request.Form("CompanyID")
IIN = Request.Form("INS_ID_NUM")
set conn = server.CreateObject("adodb.connection")
set rsSet = Server.CreateObject ("ADODB.Recordset")
conn.Open Application("conMestamed_Utilities_ConnectionString")
rs_string = "apUpdateBill " & RN &",'" & ET & "'," & IC & "," & CI & ",'" & IIN & "'"
rsSet.Open rsString, conn, adOpenForwardOnly,, adCmdText
(I don't need a Recordset, i'm just trying to get it to send in data)
Error:
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
I have tried Command stuff and I get "precision" errors
Do I "have" to use command object?
e.g.
Set cmd = Server.CreateObject("ADODB.Command")
'Set cmd.ActiveConnection = conn
'cmd.CommandText = "apUpdateBill"
'cmd.CommandType = adCmdStoredProc
'Cmd.Parameters.append Cmd.createParameter("#Record_Number", adDecimal, adParamInput, 18)
'Cmd.Parameters("#Record_Number").Precision = 0
'Cmd.Parameters("#Record_Number").value = Request.Form("Record_Number")
Here is how you would do it, you won't need to create a recordset object since it is an update stored procedure:
'Set the connection
'...............
'Set the command
DIM cmd
SET cmd = Server.CreateObject("ADODB.Command")
SET cmd.ActiveConnection = Conn
'Prepare the stored procedure
cmd.CommandText = "apUpdateBill"
cmd.CommandType = 4 'adCmdStoredProc
cmd.Parameters("#RECORD_NUMBER") = Request.Form("Record_Number")
cmd.Parameters("#ErrorType") = Request.Form("ErrorType")
cmd.Parameters("#INSURANCE_CODE") = Request.Form("INSURANCE_CODE")
cmd.Parameters("#CompanyId") = Request.Form("CompanyID")
cmd.Parameters("#INS_ID_NUM") = Request.Form("INS_ID_NUM")
'Execute the stored procedure
'This returns recordset but you dont need it
cmd.Execute
Conn.Close
SET Conn = Nothing

I need a vbscript if possible or a batch (.bat) file that changes tcp/ip printer color options to black & white

first of all, I am new to the world of scripting. I did a VBScript that adds TCP/IP printers (in a network) to a computer. So far I also managed to change the printers to perform duplex printing with a batch file. Now I need someway to change the printer color settings to print in black & white.
I'd appreciate if you could help me please,
Thanks in advance.
Code to add tcp/ip printer to computer:
strComputer = "."
Dim objWMI:Set objWMI = GetObject("winmgmts://" & strComputer & "\root\cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem", , 48)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
objWMIService.Security_.Privileges.AddAsString "SeLoadDriverPrivilege", True
Install "167.221.10.249" ''printer IP to be added
sub Install(strIP)
InstallPrinterPort strIP
end Sub
strBasePrinter = "PRINTERNAME"
strPrinterName = "Xerox WorkCentre 7120 PCL6" '' Printer controller
strINFPath = "\\167.221.1.67\printer_7120\x2GCHAX.inf" ''path to .inf file
strIPPort = "IP_" & "167.221.10.249"
Set objShell = CreateObject("WScript.Shell")
strCommand = "cmd /c rundll32 printui.dll,PrintUIEntry /if /b """ & strBasePrinter & """ /f " & strINFPath & " /r """ & strIPPort & """ /m """ & strPrinterName & """ & /Z"
objShell.Run strCommand, 1, True
Sub InstallPrinterPort(strIP)
Set colInstalledPorts = objWMIService.ExecQuery _
("Select Name from Win32_TCPIPPrinterPort")
For each objPort in colInstalledPorts
If objPort.Name="IP_" & strIP then exit sub
Next
Set objNewPort = objWMIService.Get _
("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "IP_" & strIP
objNewPort.Protocol = 1
objNewPort.HostAddress = strIP
objNewPort.PortNumber = "9100"
objNewPort.SNMPEnabled = True
objNewPort.Put_
end Sub
During my research i found this. I believe it sets the printer to it's default colors.
Option Explicit
Dim objPrinter
Set objPrinter = CreateObject("WScript.Network")
objPrinter.SetDefaultPrinter "\\ServerName\PrinterName"
' End of example VBScript

call stored procedure in vb script

I have created a stored procedure. I tested it in the query analyser like this EXEC test '10/12/2012'. It is OK. But I called it following way in the vb script. It not OK.
InstanceVar = CreateObject("ADODB.Recordset")
InstanceVar.ActiveConnection = ConnVar
InstanceVar.Source = "EXEC Test '" & Date() & "'"
InstanceVar.CursorType = 3
InstanceVar.CursorLocation = 3
InstanceVar.Open()
I have got 80040E14 error. How can I solve it
I realise this is a bit late, but I found this question when looking for a solution to the same problem. I've solved it like this:
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = ConnVar
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "Test"
cmd.Parameters.Append(cmd.CreateParameter("#my_date", adVarChar, adParamInput,10))
cmd.Parameters("#my_date") = "10/12/2012"
Set rsResults = Server.CreateObject("ADODB.Recordset")
rsResults.CursorLocation = adUseClient
rsResults.Open cmd,,adOpenForwardOnly,adLockBatchOptimistic
Using CursorLocation = adUseClient means you can navigate the rsResults RecordSet using MoveNext, MoveFirst etc.

Resources