Poll: Was this script helpful?

Be advised that this is a public poll: other users can see the choice(s) you selected.

+ Post New Thread
Page 5 of 11 FirstFirst 123456789 ... LastLast
Results 61 to 75 of 165
Scripts Thread, A Printer Script in Coding and Web Development; If you use struser then you could do Select Case struser Case "joe.bloggs" wshnetwork.AddwindowsPrinterConnection Case "John.Smith" wshnetwork.AddwindowsPrinterConnection Case Else ' ...
  1. #61

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,710
    Thank Post
    3,246
    Thanked 1,048 Times in 970 Posts
    Rep Power
    364

    Re: A Printer Script

    If you use struser then you could do

    Select Case struser

    Case "joe.bloggs"
    wshnetwork.AddwindowsPrinterConnection
    Case "John.Smith"
    wshnetwork.AddwindowsPrinterConnection
    Case Else
    ' Code here to add printer connection if its anyone else or if you want to
    ' do anything else afterwards that does not match any of the above users 'in the above case select statements.
    End Select

    If you use Uname then just change the first line of code from

    Select Case struser

    to

    Select Case Uname

    Easier then all the if else statements and easier to read etc.

  2. #62

    Join Date
    Sep 2006
    Location
    Essex
    Posts
    777
    Thank Post
    1
    Thanked 31 Times in 29 Posts
    Rep Power
    23

    Re: A Printer Script

    Beat me to it gecko.. That is excatly what I would do.

  3. #63
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,989
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    thank you

  4. #64

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,710
    Thank Post
    3,246
    Thanked 1,048 Times in 970 Posts
    Rep Power
    364

    Re: A Printer Script

    If strUser returns

    domain\username

    Then you can use the split function before you do the select case to attain the username from it.

    Dim x

    x = split(struser,"\")

    Select Case x(1)

    Case "username_one"
    wshnetwork.AddwindowsPrinterConnection

    Case "username_two"
    wshnetwork.AddwindowsPrinterConnection

    End Select

    '------------------

    Just thought that would be handy.

  5. #65
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,989
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    got it working... needed to change struser = wshnetwork.domain to struser = wshnetwork.username

  6. #66

    Join Date
    Sep 2006
    Location
    Essex
    Posts
    777
    Thank Post
    1
    Thanked 31 Times in 29 Posts
    Rep Power
    23

    Re: A Printer Script

    Quote Originally Posted by timbo343
    got it working... needed to change struser = wshnetwork.domain to struser = wshnetwork.username

    Sorry timbo343, I think that was my mistake! ops:

  7. #67
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    2,989
    Thank Post
    287
    Thanked 273 Times in 194 Posts
    Rep Power
    116

    Re: A Printer Script

    its ok, no probs

  8. #68

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,710
    Thank Post
    3,246
    Thanked 1,048 Times in 970 Posts
    Rep Power
    364

    Re: A Printer Script

    you could just go to www.wisesoft.co.uk and get the script builder ( might of made it easier lol )

    you have to register but registration is free and there are other useful utils on there by wisesoft82 from this site ( I think thats his username on here )

  9. #69

    Join Date
    Oct 2006
    Location
    Ohio USA
    Posts
    14
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: A Printer Script

    Greetings! I, too, am attempting to use a .vbs script to assign specific printers to specific computers in specific rooms. I've been reading this, and other threads, on the subject matter, seeing some of the same scripting concept that I'm attempt to use.
    Here is my dilemma-I have named each of my clients with the following structure: RM400-1-PRN1 with the "PRN1" to be used to indicate, in the scripting, the specific printer. In my script, I use the " = right(xxxxx, 3)" but it does not seem to be reading the "PRNx" and mapping the specified printer. Below is the script that I'm trying to use:

    Example 1:

    Dim wshNetwork
    Dim strUsername
    Dim intCnt
    Dim CurrentUser
    Dim strCompName
    Dim strShortName
    Dim PrinterPath
    Set wshNetwork = CreateObject("WScript.Network")

    On Error Resume Next

    wshNetwork.RemoveNetworkDrive "h:"
    wshNetwork.RemoveNetworkDrive "P:"

    wshNetwork.MapNetworkDrive "h:", "\\xxxx\" & wshNetwork.UserName & "$"

    strCompName = wshNetwork.ComputerName

    strShortName = RIGHT(strCompName,4)
    Select Case strShortName

    Case "PRN1"
    PrinterPath = "\\xxxx\LAB1(KOELLER)"
    wshNetwork.AddWindowsPrinterConnection PrinterPath
    wshNetwork.SetDefaultPrinter "\\xxxx\LAB1(KOELLER)"

    Case "PRN3"
    Set objWSHNetwork = CreateObject("WScript.Network") 'create network object
    strConnectString = "\\xxxx\lab2 (open)"
    strResult = objWSHNetwork.AddWindowsPrinterConnection(strConne ctString)
    wshNetwork.SetDefaultPrinter "\\xxxx\lab2 (open)"

    End Select

    WScript.Quit

    or

    Example 2:

    Dim wshNetwork
    Dim strUsername
    Dim intCnt
    Dim CurrentUser
    Dim strCompName
    Dim strShortName
    Dim PrinterPath
    Set wshNetwork = CreateObject("WScript.Network")

    On Error Resume Next

    wshNetwork.RemoveNetworkDrive "h:"
    wshNetwork.RemoveNetworkDrive "P:"

    wshNetwork.MapNetworkDrive "h:", "\\xxxx\" & wshNetwork.UserName & "$"


    strCompName = wshNetwork.ComputerName
    strShortName = RIGHT(strCompName,4)
    Select Case strShortName

    Case "PRN3"
    PrinterPath = "\\xxxx\MediaCtr3500"
    wshNetwork.AddWindowsPrinterConnection PrinterPath
    wshNetwork.SetDefaultPrinter "\\xxxx\MediaCtr3500"

    End Select

    WScript.Quit

    ("xxxx" is sever name)

    If anyone has any suggestions and/or knows what needs to be fixed to correct the problem, it would be greatly appreciated!

    Behuck

  10. #70

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,710
    Thank Post
    3,246
    Thanked 1,048 Times in 970 Posts
    Rep Power
    364

    Re: A Printer Script

    replied to your other post , if you need more help feel free to pm me

  11. #71

    Join Date
    Jun 2006
    Location
    Leicester
    Posts
    70
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: A Printer Script

    im not sure if its supposed to be case specific but the problem i had was that in the script the computer name had to be lower case otherwise i didn't pick it up

    ie instead of
    Case "PRN1"

    try
    case "prn1"

  12. #72

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,803
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224

    Re: A Printer Script

    yes, Ric's script will lcase() the PC names prior to doing the select....case. So you need to make sure all your case "blah" are lowercase.

  13. #73

    Join Date
    Apr 2007
    Posts
    17
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: A Printer Script

    We had a similar problem with vbscripts. I would say test

    Case "prn1" instead of
    Case "PRN1"
    This should help you however I would also try testing the script to make sure it is getting to that line. A simple test by replacing declared variables with test code.
    For example

    strShortName = "prn1"
    try this in places where variables are passed to identify if there is a error in your code. But looks fine to me.

  14. #74
    mullet_man's Avatar
    Join Date
    Oct 2005
    Location
    Oldham
    Posts
    726
    Thank Post
    34
    Thanked 46 Times in 45 Posts
    Rep Power
    26

    Re: A Printer Script

    Hi

    Great script Ric, I have one little problem which am sure you can help with, I have setup using 3 letters to inspect for our computer rooms etc.

    This has worked fine expect for our Science laptops which are named S-01, S-02 to S-30.

    If I took the letter inspect down to 2, this would clash with RM2 and RM15.

    Any ideas? I know I could write them out individually but just to be lazy and smarter.

    Thanks.

    Ste.

  15. #75

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,590
    Thank Post
    109
    Thanked 762 Times in 593 Posts
    Rep Power
    180

    Re: A Printer Script

    @mullet_man: Not sure what you are after... can you say what you want to achieve, e.g.

    S-01 to S-30 -> \\server\printer1
    RM2-01 to RM2-30 -> \\server\printer2

    or whatever?

    If it is as above, you can use a split on the computerName variable in the script and then you can inspect the bit before the -

SHARE:
+ Post New Thread
Page 5 of 11 FirstFirst 123456789 ... LastLast

Similar Threads

  1. logon script for printer
    By ozzy in forum Scripts
    Replies: 6
    Last Post: 22nd November 2007, 03:03 PM
  2. Printer Script
    By faza in forum Scripts
    Replies: 9
    Last Post: 14th September 2007, 08:30 AM
  3. Logon script & Printer script question.
    By Galway in forum Windows
    Replies: 3
    Last Post: 29th August 2007, 11:00 AM
  4. Add printer script not workling
    By mark in forum Windows
    Replies: 6
    Last Post: 15th September 2005, 10:07 AM
  5. Script to delete printer
    By tosca925 in forum Scripts
    Replies: 2
    Last Post: 31st August 2005, 07:45 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •