Jump to content

Retrieve Printer Share Name From Network


 Share

Recommended Posts

Um, you can't. There is no way of placing a share name into a $var and pull an IP address. You couldn't even do this with Batch Or VB Scripting. Sorry mate.

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Link to comment
Share on other sites

Not even if I already know the IP? :lmao:

OMG! I totaly have dyslexia! I read your question way wrong sorry about that!

$var = "Sharename"

$var2 = "\\192.168.1.2\"&$var

I don't know if that is what you are asking.

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Link to comment
Share on other sites

Or if you are using AD or something and have the same print server you could:

;Server = "192.168.1.2" Don't know how you are using the PrintServer Share relationship.

$Server = "\\192.168.1.2\"

$Share1 = "name1"

$Share2 = "name2"

$Share3 = "name3"

$Printshare1 = $Server&$Share1

$Printshare2 = $Server&$Share2

$Printshare3 = $Server&$Share3

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Link to comment
Share on other sites

Unfortunately, I don't know the sharename beforehand.

What I would like to do is:

------------------------------

Connect to a networked PC

Copy the Printer's share name into a variable

Could this be done by reading the registry remotely, maybe?

Sorry for not being clear enough. :lmao:

Edited by buymeapc
Link to comment
Share on other sites

Unfortunately, I don't know the sharename beforehand.

What I would like to do is:

------------------------------

Connect to a networked PC

Copy the Printer's share name into a variable

Could this be done by reading the registry remotely, maybe?

Sorry for not being clear enough. :lmao:

I know you can use the NET VIEW command via the command line and if the server has shares on it you can view them that way.

So you could use the RUN() with the NEW VIEW command into a txt file. Once you have it in the file you could _FileReadToArray(). Then you could trim everything in the array after the first space so that way you have the name.

I'll try and throw something to gether for you. Stand by.

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Link to comment
Share on other sites

This needs beta, and has to be run as an admin

; Generated by AutoIt Scriptomatic
$strComputer = InputBox("Printer Shares", "Enter IP or Server Name")
If Not @error Then
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""

    $Output=""
    $Output = $Output & "Computer: " & $strComputer  & @CRLF
    $Output = $Output & "==========================================" & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PrinterShare", "WQL", _
                                                            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) then
        For $objItem In $colItems
            $Output = StringTrimRight(StringMid($objItem.Dependent,StringInStr($objItem.Dependent,'="')+2),1)
            if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
            $Output=""
        Next
    Else
        Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PrinterShare" )
    Endif
EndIf
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Here it is like the way I was talking about. It needs a little more formating, bu there you go.

#include <File.au3>

Dim $printerlist
$x = 1
$servername = InputBox("Server Name", "Enter the server name here")
RunWait(@ComSpec & " /c net view "&$servername&" > C:\out.txt")
$linecout = _FileCountLines("C:\out.txt")
If Not FileExists("C:\printerlist.txt") Then _FileCreate("C:\printerlist.txt")

Do
    $printername = FileReadLine("C:\out.txt", $x)
    $aprinter = StringSplit($printername, " ")
    FileWriteLine("C:\printerlist.txt", $aprinter[1])
    $x = $x + 1
Until $x = $linecout

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Link to comment
Share on other sites

You can also adjust $x = 1 to $x = 8 and it will remove all of the microsoft crap that it places in there. Also if you wanted to you could Trim the white space and replace it with a comma and change printerlist.txt to printerlist.cvs and have a nice sortable worksheet. Okay good luck.

Quick update:

#include <File.au3>

$x = 8
$output = "C:\out.txt"
$printerlist = "C:\printerlist.txt"

If FileExists($output) Then FileDelete($output)
If FileExists($printerlist) Then FileDelete($printerlist)
$servername = InputBox("Server Name", "Enter the server name here")
RunWait(@ComSpec & " /c net view "&$servername&" > "&$output, "C:\", @SW_HIDE)
$linecout = _FileCountLines($output)
If Not FileExists($printerlist) Then _FileCreate($printerlist)

Do
    $printername = FileReadLine($output, $x)
    $aprinter = StringSplit($printername, " ")
    If Not $aprinter[1] = "" Then FileWriteLine($printerlist, $aprinter[1])
    $x = $x + 1
Until $x = $linecout - 1

RunWait("notepad "&$printerlist)

I added another quick update to remove the text "The command completed successfully." from the bottom.

Quick Edit: I cleaned up the code a little

Quick Edit: I change it so it would not put blank spaces in the text file. That should do it.

Edited by flaxcrack

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Link to comment
Share on other sites

Wow!!! Thanks so much for the help! Everything working, now. :lmao:

I just hope I was able to help somewhat. Sorry I didn't pick up on what you were saying before. ;)

[quote] Gilbertson's Law: Nothing is foolproof to a sufficiently talented fool.Sandro Alvares: Flaxcrack is please not noob! i can report you is stop stupid. The Post[/quote]I made this: FWD & MD5PWD()

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...