Sign in to follow this  
Followers 0
giggity

Create TCP printer port

2 posts in this topic

Is there a way to create TCP printer ports using runas for non admin users? I am trying to deploy printer installs on a network via login script. I can install the printer no problem if the user currently has the tcp port created but other than that I can't seem to get this to work.

$Addr = "192.168.45.34"
$PNumber = "9100"
MakeNewPort($Addr, $PNumber)

Func MakeNewPort($Address, $PortNumber)
    $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    $objNewPort = $objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_

    $objNewPort.Name = "IP_"&$Address
    $objNewPort.Protocol = 1
    $objNewPort.HostAddress = $Address
    $objNewPort.PortNumber = $PortNumber
    $objNewPort.SNMPEnabled = False
    $objNewPort.Put_
EndFunc
:lmao:

I can't get that code to work for non admin users.

Share this post


Link to post
Share on other sites



Is there a way to create TCP printer ports using runas for non admin users? I am trying to deploy printer installs on a network via login script. I can install the printer no problem if the user currently has the tcp port created but other than that I can't seem to get this to work.

$Addr = "192.168.45.34"
$PNumber = "9100"
MakeNewPort($Addr, $PNumber)

Func MakeNewPort($Address, $PortNumber)
    $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    $objNewPort = $objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_

    $objNewPort.Name = "IP_"&$Address
    $objNewPort.Protocol = 1
    $objNewPort.HostAddress = $Address
    $objNewPort.PortNumber = $PortNumber
    $objNewPort.SNMPEnabled = False
    $objNewPort.Put_
EndFunc
:lmao:

I can't get that code to work for non admin users.

Restart the script with Admin credentials ..

AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 
Break(0)
$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0       ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
   Exit
EndIf
; commands go here that require Administrator rights

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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  
Followers 0