Pessoal;
Estou com um problema preciso recuperar o nome de quem está logado na estãção para definir se o meu script vai excluir ou não a impressora! tentei isto mas não deu certo!
On Error Resume Next
DIM cont Dim lngLen
Dim strUserName
Dim fOSUserName
Dim lngx
strComputer = "."
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
strUserName = String(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
fOSUserName = Left(strUserName, lngLen - 1)
Username = fOSUername
Else
fOSUserName = vbNullString
End If
if (userme = XXXXX) then
For Each objprinter In colInstalledPrinters
If InStr(objprinter.Name, "\\servidor\H") > 0 Then
'wscript.echo "Excluir impressora: " & objprinter.Name
WshNetwork.RemovePrinterConnection objprinter.Name
cont = cont + 1
Else
If InStr(objprinter.Name, "\\servidor\h") > 0 Then
'wscript.echo "Excluir impressora: " & objprinter.Name
WshNetwork.RemovePrinterConnection objprinter.Name
cont = cont + 1
End If
End If
Next
if cont > 0 then
wscript.echo "Impressoras Excluidas Com Exito"
else
wscript.echo "Nenhuma impressora para excluir"
end if
está dando um erro de tipo incompativeis quando ele pega o nome do usuario a parte de exclusão está funcionando normalmente! obrigado