Jump to content
Sign in to follow this  
dcjohnston

Want to wrap my vbscript to run as admin...

Recommended Posts

dcjohnston

The VBSCRIPT code converter didnt work on my vbscript code. The converter created the .au3 code and I was able to compile, but it would not execute.

So I was wondering if there was a way to wrap the vbscript into an admin package? Or if someone could look at why this code wouldnt convert.

Thanks for everyones assistance...

Here is the vbscript code:

Dim Printname
Dim Printserver


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
   
For each objPrinter in colInstalledPrinters
 
         'msgbox objprinter.name
  if objprinter.name = "\\ga016f3f\GA016P15A" then

     
     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""           
  

  Elseif  objprinter.name = "\\ga016f3f\GA016P1A" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P1E" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P2B" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P3C" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P3D" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P4A" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P4B" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P4C" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P4E" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P5A" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P5B" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\Ga016PSE" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P10A" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P10B" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\Ga016P10C" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P10D" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P11" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\Ga016P11B" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\Ga016P11C" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P11D" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P13C" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P13E" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P13F" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P14B" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P14E" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P15A" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P15B" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P15C" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P15D" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P15E" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P15F" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P22" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P38" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P41" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P54" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P64" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P65" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P70" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P81" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P85" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P89" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P93" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P98" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P99" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P11" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P103" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P110" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P111" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P116" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P117" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P122" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P125" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P126" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P136" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P137" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P138" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P139" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P141" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P142" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P143" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P144" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P145" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P146" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P147" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P151" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P155" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P156" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P160" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P162" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P164" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P165" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P167" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""

  Elseif  objprinter.name = "\\ga016f3f\GA016P169" then

     Printname = (RIGHT(objprinter.name,(len(objprinter.name)-11)))
     Printserver = "\\ga016vp01\"& printname &""



end if

if printname = "" then
On Error Resume Next
end if





'__________________________________________________________
'Printer Installs
'__________________________________________________________



Set WshNetwork = CreateObject("WScript.Network") 
PrinterPath = printserver  
    'msgbox printerpath
'PrinterDriver = "HP LaserJet 4250 PCL 6" 
wshNetwork.AddWindowsPrinterConnection PrinterPath 
'wshNetwork.AddWindowsPrinterConnection PrinterDriver 

Next




'__________________________________________________________
'Delete all printers using HP universal driver
'__________________________________________________________

'strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where DriverName = 'HP Universal Printing PCL 6'")

For Each objPrinter in colInstalledPrinters
        objPrinter.Delete_
Next
Edited by dcjohnston

Share this post


Link to post
Share on other sites
dcjohnston

Here is the code for the converted vbscript code. It is having a problem with Line 415 $WSHNetwork.AddWindowsPrinterConnection ($PrinterPath)

The requested action with this object has failed.

; ----------------------------------------------------------------------------
;
; VBScript to AutoIt Converter v0.4
;
; ----------------------------------------------------------------------------


Dim $Printname
Dim $Printserver


$strComputer = "."
 $objWMIService = ObjGet("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
 $colInstalledPrinters =  $objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
   
For $objPrinter in $colInstalledPrinters
 
         ;msgbox $objPrinter.name
  if $objPrinter.name = "\\ga016f3f\GA016P15A" then

     
     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""           
  

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P1A" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P1E" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P2B" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P3C" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P3D" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P4A" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P4B" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P4C" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P4E" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P5A" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P5B" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\Ga016PSE" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P10A" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P10B" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\Ga016P10C" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P10D" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P11" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\Ga016P11B" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\Ga016P11C" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P11D" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P13C" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P13E" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P13F" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P14B" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P14E" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P15A" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P15B" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P15C" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P15D" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P15E" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P15F" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P22" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P38" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P41" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P54" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P64" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P65" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P70" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P81" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P85" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P89" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P93" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P98" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P99" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P11" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P103" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P110" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P111" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P116" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P117" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P122" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P125" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P126" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P136" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P137" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P138" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P139" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P141" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P142" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P143" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P144" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P145" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P146" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P147" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P151" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P155" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P156" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P160" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P162" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P164" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P165" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P167" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""

  $Elseif  $objPrinter.name = "\\ga016f3f\GA016P169" then

     $Printname = (StringRight($objPrinter.name,(StringLen($objPrinter.name)-11)))
     $Printserver = "\\ga016vp01\"& $Printname &""



EndIf

if $Printname = "" then
;VA On Error Resume Next
EndIf





;__________________________________________________________
;Printer Installs
;__________________________________________________________



 $WshNetwork = ObjCreate("WScript.Network") 
$PrinterPath = $Printserver  
    ;msgbox $PrinterPath
;PrinterDriver = "HP LaserJet 4250 PCL 6" 
$WshNetwork.AddWindowsPrinterConnection ($PrinterPath )
;wshNetwork.AddWindowsPrinterConnection PrinterDriver 

Next




;__________________________________________________________
;Delete all printers using HP universal driver
;__________________________________________________________

;strComputer = "."
 $objWMIService = ObjGet("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")

 $colInstalledPrinters =  $objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where DriverName = 'HP Universal Printing PCL 6'")

For $objPrinter in $colInstalledPrinters
        $objPrinter.Delete_()
Next

Share this post


Link to post
Share on other sites
PsaltyDS

If you want to run a VBScript as admin:

RunAsSet($User, $Domain, $Password)
Run(@ComSpec & ' /c cscript "' & $YourVBScript & '" ' & $Parameters)

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dcjohnston

OK help me out here.....this is not so easy.....My code below bombs pretty bad.

RunAsSet($Myname, $corp, $myPassword)

Run(@ComSpec & ' /c cscript "' & $e:\myvbscript.vbs & '" ' & $Parameters)

Edited by dcjohnston

Share this post


Link to post
Share on other sites
PsaltyDS

OK help me out here.....this is not so easy.....My code below bombs pretty bad.

RunAsSet($Myname, $corp, $myPassword)

Run(@ComSpec & ' /c cscript "' & $e:\myvbscript.vbs & '" ' & $Parameters)

Is the $Myname variable set to an administrator's user name?

Is the $corp variable set to the $Myname account's domain (@ComputerName for local account)?

Is the $myPassword variable set to the $Myname account's password?

If they are then it could be the bad literal path (not quoted):

RunAsSet($Myname, $corp, $myPassword)
Run(@ComSpec & ' /c cscript e:\myvbscript.vbs")

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dcjohnston

Got it and thanks its seems to be working. Now is there a way to compile the script into the .exe file? Is there a way I can push the script without having to point to a path for the vbscript?

Thanks for your time btw.

Is the $Myname variable set to an administrator's user name?

Is the $corp variable set to the $Myname account's domain (@ComputerName for local account)?

Is the $myPassword variable set to the $Myname account's password?

If they are then it could be the bad literal path (not quoted):

RunAsSet($Myname, $corp, $myPassword)
Run(@ComSpec & ' /c cscript e:\myvbscript.vbs")

:rolleyes:

Share this post


Link to post
Share on other sites
PsaltyDS

Got it and thanks its seems to be working. Now is there a way to compile the script into the .exe file? Is there a way I can push the script without having to point to a path for the vbscript?

If you learn enough about VBScript and AutoIt, you might still pull off the conversion. I don't have much faith in that converter, as it was abandoned in June 2005 (when last I looked, anyway): VBScript to AutoIt Converter, VBScript to AutoIt Converter.

Setting that aside, you can certainly use FileInstall() to put a compressed copy of the .vbs file in your compiled script which will be decompressed to a specified location at run time:

If FileInstall("e:\myvbscript.vbs", @ScriptDir, 1) Then
    RunAsSet($Myname, $corp, $myPassword)
    Run(@ComSpec & ' /c cscript "' & @ScriptDir & '\myvbscript.vbs"')
Else
    MsgBox(16, "Error", "Failed to extract required VBScript file.")
EndIf

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dcjohnston

With my code the .vbs file will not extract for some reason. Does this look right? Forgive me on my lack on autoit knowledge...

If FileInstall("c:\temp\fixfinal2.vbs", @ScriptDir, 1) Then

RunAsSet($Myname, $corp, $myPassword)

Run(@ComSpec & ' /c cscript "' & @ScriptDir & '\fixfinal2.vbs"')

Else

MsgBox(16, "Error", "Failed to extract required VBScript file.")

EndIf

If you learn enough about VBScript and AutoIt, you might still pull off the conversion. I don't have much faith in that converter, as it was abandoned in June 2005 (when last I looked, anyway): VBScript to AutoIt Converter, VBScript to AutoIt Converter.

Setting that aside, you can certainly use FileInstall() to put a compressed copy of the .vbs file in your compiled script which will be decompressed to a specified location at run time:

If FileInstall("e:\myvbscript.vbs", @ScriptDir, 1) Then
    RunAsSet($Myname, $corp, $myPassword)
    Run(@ComSpec & ' /c cscript "' & @ScriptDir & '\myvbscript.vbs"')
Else
    MsgBox(16, "Error", "Failed to extract required VBScript file.")
EndIf

:rolleyes:

Share this post


Link to post
Share on other sites
PsaltyDS

With my code the .vbs file will not extract for some reason. Does this look right? Forgive me on my lack on autoit knowledge...

If FileInstall("c:\temp\fixfinal2.vbs", @ScriptDir, 1) Then

RunAsSet($Myname, $corp, $myPassword)

Run(@ComSpec & ' /c cscript "' & @ScriptDir & '\fixfinal2.vbs"')

Else

MsgBox(16, "Error", "Failed to extract required VBScript file.")

EndIf

From the help file for FileInstall:

dest = The destination path of the file with trailing backslash if only the directory is used. This can be a variable.

Either path it out completely, or add a backslash to the @Scriptdir:

FileInstall("c:\temp\fixfinal2.vbs", @ScriptDir & '\fixfinal2.vbs"', 1)

; Or...

FileInstall("c:\temp\fixfinal2.vbs", @ScriptDir & '\', 1)

:rolleyes:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dcjohnston

That was the trick....

Man Autoit has really changed in the past year or two. Very nice.

Thanks again my friend..

Dave

From the help file for FileInstall:

Either path it out completely, or add a backslash to the @Scriptdir:

c2--><!--RmlsZUluc3RhbGwoJnF1b3Q7YzomIzA5Mjt0ZW1wJiMwOTI7Zml4ZmluYWwyLnZicyZxdW90OywgQFNjcmlwdERpciAmYW1wOyAm
IzM5OyYjMDkyO2ZpeGZpbmFsMi52YnMmcXVvdDsmIzM5OywgMSkKCjsgT3IuLi4KCkZpbGVJbnN0YWxsKCZxdW90O2M6JiMwOTI7
dGVtcCYjMDkyO2ZpeGZpbmFsMi52YnMmcXVvdDssIEBTY3JpcHREaXIgJmFtcDsgJiMzOTsmIzA5MjsmIzM5OywgMSk=--><!--eg

:rolleyes:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×