Delete local printer before mapping - printing

I have the following script that maps printers based on AD grouping:
'---------------------------------------------------------------------------------------------
'-------------------------------MAPEAMENTO DE IMPRESSORAS-------------------------------------
on error resume next
'determines the user who just logged on
Set objSysInfo = CreateObject("ADSystemInfo")
Set WSHNetwork = CreateObject("WScript.Network")
'As soon as we tack on LDAP:// and construct an ADsPath we then bind to the user account in
'Active Directory and report back the groups the user belongs to; this can be done simply
'by enumerating the values in the MemberOf attribute.
strUserPath = "LDAP://" & Replace(objSysInfo.UserName, "/", "\/")
Set objUser = GetObject(strUserPath)
For Each objGroup in objUser.Groups
strGroupName = objGroup.CN
'---------------------------------------------------------------------------------------------
'--------------MAPEAMENTO DE IMPRESSORA DO GRUPO UM-------------------------------------------
'Mapeamento de impressoras por grupo definindo a impressora comom padrão para aquele grupo.
Select Case strGroupName
Case "GrupodoAD1"
WshNetwork.AddWindowsPrinterConnection "\\servidor\impressora1"
WshNetwork.SetDefaultPrinter "\\servidor\impressora1"
End Select
'---------------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------------
'--------------MAPEAMENTO DE IMPRESSORA DO GRUPO DOIS-----------------------------------------
'Mapeamento de impressoras por grupo definindo a impressora comom padrão para aquele grupo.
Select Case strGroupName
Case "GrupodoAD2"
WshNetwork.AddWindowsPrinterConnection "\\servidor\impressora2"
WshNetwork.SetDefaultPrinter "\\servidor\impressora2"
End Select
'---------------------------------------------------------------------------------------------
'==========Adicione seções adicionais de case para cada grupo do AD que tiver.+===============
next
Now I was asked to delete some local printers on user's computers. The above script runs on logon. The condition although states that only certain printers must be deleted (some users take computers home and we do not want to delete their home printers).
Is there a way I can accomplish this using the above existing script? How can I do that and where do I insert the information? Can I delete more than 1 printer using a single script?
For example I know I must delete:
Samsung SCX-6545X Series PCL 6
Samsung SCX-6545X Series PCL 5
Samsung SCX-6545X Series PS
If I have similar names like above, can I use that to delete any printer that matches parts of the name?
Best regards and thanks in advance for your help!

This is a script I found from somewhere once and adapted slightly to delete printers by device name. Please approach with caution, understand it, and adapt it to your needs carefully:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer where DeviceID = 'HP LaserJet P1505'")
For Each objPrinter In colInstalledPrinters
objPrinter.Delete_
Next
I think you could replace the equals clause in the "SELECT" statement to use a "IN" so you could check all the printers and delete them in one hit. Example:
("Select * from Win32_Printer where DeviceID In ('HP LaserJet P1505', 'Printer_2', 'Printer_3')")

Related

I created a list using hash, but the information is always deleted after finishing the program [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
I started studying Ruby recently and I was looking for a challenge so I decided to create this program.
I created a program using hash, to create a list of products, where it stores the name and value.
However, I would like the products registered within the hash to remain there even after finishing the program.
Can anyone tell me if this is possible and how I could do it?
code
The hash and every other variable will always be cleared from memory when your program ends. While your program is running, it stores everything in the RAM, and then clear all the memory it's using after finishing.
In order to recover the value from your Hash after exiting your program, you need to persist this information somehow. Using a database or storing it in a file. As someone suggested, you could store it in a JSON file, for example. You could do it like this:
Create an empty file in the same directory of your Ruby script named products.json
Use the Ruby json library to load the file content as a hash at the start of your program
Update the file before exiting the program
A working example:
require 'json'
begin
products = JSON.parse(File.read('products.json'))
rescue StandardError
puts 'Ainda não existem produtos cadastrados. Criando nova lista'
products = {}
end
loop do
puts 'Escolha uma opção'
puts '1 - Adicionar o item e o valor'
puts '2 - Sair'
print 'Opção: '
option = gets.chomp.to_i
if option == 1
print 'Digite o nome do item: '
key = gets.chomp
print 'Digite o valor do item: '
value = gets.chomp
puts "O produto #{key} com o valor de R$#{value} foi cadastrado com sucesso!"
products[key] = value
elsif option == 2
File.open('products.json', 'w').write(JSON.pretty_generate(products))
puts 'Fim'
break
else
puts 'Opção inválida'
end
end

is it possible get values of connection from sql variable? vfp 6

there is a login in the app which does something as it
this is in production and could not be modified
xconec = Sqlstringconnect("Driver={SQL Server};Server=laptop001;Database=Master;Uid=sa;Pwd=sa;")
&& syslanguages es una tabla que se encuentra contenida en la BD Master de SQL Server
xselect = "SELECT * from syslanguages"
xenvio = SQLExec(xconec,xselect,"Micursor")
then always in all form or prg in fox i am using a code similar to
xenvio = SQLExec(xconec,xselect,"Micursor")
then if i do it in all modules, how can i get my connection? well i need
user,db,password,server
this is because i want to call a c# app (an exe) which is going to connect to the same server/database for do inserts. but i have only xconect variable
Use SQLGETPROP().
xpassword = SQLGETPROP(xconect, "Password")
Or:
xstring = SQLGETPROP(xconect, "ConnectString")
and then parse xstring for the pieces that you're looking for.
This works in VFP 9, not sure about VFP 6.

How to translate a dynamic title attribute

I have this kind of translation to make :
<a tal:attributes="href troncon/url;
title string:Cette etape fait partie du troncon ${troncon/nom}"
tal:content="troncon/nom">Canal du centre</a>
You see that I have a dynamic title attribute that I want to be translatable.
I've tried like this :
<a tal:attributes="href troncon/url;
title string:Cette etape fait partie du troncon ${troncon/nom}"
tal:content="troncon/nom"
i18n:attributes="title">Canal du centre</a>
And like this :
<a tal:attributes="href troncon/url;
title string:Cette etape fait partie du troncon ${troncon/nom}"
tal:content="troncon/nom"
i18n:attributes="title"
title="Cette etape fait partie du troncon ${nom}">Canal du centre</a>
But this doesn't work (of course).
Any ideas ?
The result of the tal:attributes call is passed literally to the translation machinery. i18n:attributes matches it's keys against what tal:attributes generates, and if there is a match, the original attribute on the element is ignored (see this I18N article on the Zope 3 wiki.
This means that the result of "Cette etape fait partie du troncon ${troncon/nom}" will be looked up for translation, requiring you to provide translations for each variation of the sentence that can be made with all possible values of troncon/nom.
To get support for proper placeholders in this string you are better off creating a message id in the code that generates the troncon structure and translate it there, presumably in your view. You need:
A message id with the placeholder
Attach the nom value to the message id
Translate this message to the currently selected language
Include the result in your troncon structure
I generally do this is one step:
from zope.i18n import translate
from zope.i18nmessageid import MessageFactory
_ = MessageFactory('yourdomain')
troncon = dict(
...
nom=nom,
nomtitre=translate(
_(u'troncon_nomtitre', default=u'Cette etape fait partie du troncon ${nom}',
mapping=dict(nom=nom)),
context=self.request)
)
Do note that you need a request for the translation function to pick the correct language.
You can always force the translation on context.translate():
tal:attributes="foobar python:context.translate(string, domain='translationdomain')"
http://collective-docs.readthedocs.org/en/latest/i18n/internationalisation.html#manually-translated-message-ids
However, this might be against all best practices.

What's options are there for localisation in WebWorks?

I'm building a WebWorks version of an Android app that's localised into 39 languages.
At the moment all the localisations are in xml files of key-value pairs, one file per language .
Each language file has about 400 lines (roughly 40k per file).
Users can change the language used in app.
What options are there in WebWorks to solve this kind of situation?
I'd be more than happy to convert the resource files into any other kind of format to make working with it a better experience on the platform.
You could store each language set in a JavaScript file that you include/load as needed. (I've converted the XML data to a "Map" since it is just key/value pairs)
e.g. (just ignore my translations... I just Googled this, I'm by no means fluent in Spanish)
//Spanish File "lang_spanish.js"
var translations = {
"lose_a_turn": "pierde un turno",
"do_not_pass_go": "huele como un camello",
"take_a_card": "tener una tarjeta de",
"you_win_the_game":"sin motocicletas en la biblioteca",
"you_can_not_move":"desbordamiento de la pila puede ser un lugar divertido"
};
In your <head> you can then have a generic script tag, that you just change the source of as needed.
e.g.
<script id="langFile" src="js/lang_english.js"></script>
When you want a different language, just remove this script from the DOM and add your new one. e.g.
function switchLang(langName){
var headTag = document.getElementsByTagName('head')[0];
var scriptFile = document.getElementById('langFile');
headTag.removeChild(scriptFile);
var newScript = document.createElement('script');
newScript.id = 'langFile';
newScript.src = 'js/lang_' + langName + '.js';
headTag.appendChild(newScript);
}
//call with:
switchLang('spanish');
The alternative would be to load all 39 languages by default... but that seems like overkill considering most will only ever want 1 or 2.

Abstract type not valid in Exchange web services FindItem request

I'm trying to use EWS to search a Task folder on Exchange 2010. I'm trying to limit the due dates of the Tasks returned, but unfortunately there's no equivalent to the CalendarView for the Task folder, so I have to use a FindItem search.
I'm using Java, Axis2 and I prepare the query like this:
// fiType is, obviously, a FindItemType
RestrictionType rType = fiType.addNewRestriction();
IsGreaterThanOrEqualToType igtoretType = IsGreaterThanOrEqualToType.Factory.newInstance();
igtoretType.addNewFieldURI().setFieldURI(UnindexedFieldURIType.TASK_DUE_DATE);
igtoretType.addNewFieldURIOrConstant().addNewConstant().setValue(dateFormat.format(begCal.getTime()));
IsLessThanOrEqualToType iltoretType = IsLessThanOrEqualToType.Factory.newInstance();
iltoretType.addNewFieldURI().setFieldURI(UnindexedFieldURIType.TASK_DUE_DATE);
iltoretType.addNewFieldURIOrConstant().addNewConstant().setValue(dateFormat.format(endCal.getTime()));
SearchExpressionType[] seArr = new SearchExpressionType[2];
seArr[0] = igtoretType;
seArr[1] = iltoretType;
AndType aType = rType.addNewAnd();
aType.setSearchExpressionArray(seArr);
Unfortunately, I get this error:
org.apache.axis2.AxisFault: La demande a échoué lors de la validation du schéma : L'élément 'http://schemas.microsoft.com/exchange/services/2006/types:SearchExpression' est abstrait ou son type l'est.
Roughly translated from French, it means that the query failed because the type SearchExpression is abstract, or it's type is.
After searching, I found this article explaining how to modify the types.xsd file to take care of this. However, even after applying the modifications, I still get the same error.
I'm at a loss as to how to go about solving this. Any help would be appreciated.
Another option is EWS Java API by Microsoft...

Resources