We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Any Command Prompt / Batch Gurus?

2»

Comments

  • mr_fishbulb
    mr_fishbulb Posts: 5,224 Forumite
    Part of the Furniture Combo Breaker
    stuartk wrote: »
    hi there

    have u used the DSGET or DSQUERY commands?

    regards
    I'm only allowed to use commands available in out XP SP2 build :(
  • stuartk
    stuartk Posts: 245 Forumite
    I'm only allowed to use commands available in out XP SP2 build :(

    this is a domain yeah?

    regards
  • PROLIANT
    PROLIANT Posts: 6,396 Forumite
    1,000 Posts Combo Breaker
    Try this VB Script, copy it in to a text editor like notepad and save it with the file extension '.vbs'.


    ‘Proliant’s Logon Script V1.0.0

    Option Explicit

    Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3

    Dim strDriveLetter1, strDriveLetter2, strDriveLetter3

    strDriveLetter1 = "K:"
    strDriveLetter2 = "L:"
    strDriveLetter3 = "M:"

    strRemotePath1 = "\\MY SERVER\Share1"
    strRemotePath2 = "\\MY SERVER\Share2"
    strRemotePath3 = "\\MY SERVER\Share3"

    Set objNetwork = CreateObject("WScript.Network")
    'On Error Resume Next

    ' Section which maps drives:
    objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
    objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
    objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3

    Wscript.Quit
    Since when has the world of computer software design been about what people want? This is a simple question of evolution. The day is quickly coming when every knee will bow down to a silicon fist, and you will all beg your binary gods for mercy.
  • mr_fishbulb
    mr_fishbulb Posts: 5,224 Forumite
    Part of the Furniture Combo Breaker
    John_Gray wrote: »
    Quite straightforward, provided that your environment always generates the output you post (mine certainly doesn't!). Create a BATch file containing

    @echo off
    setlocal
    for /f "tokens=*" %%a in (' net view ^| find "Disk" ') do call :process "%%a"
    :: I had to test this using the following line,
    :: because I don't get the results you do from NET VIEW
    ::for /f "tokens=*" %%a in (' type mse.txt ^| find "Disk" ') do call :process "%%a"
    endlocal
    goto :eof
    ::

    :process
    :: whole string gets passed to this subroutine
    set line=%1
    :: remove the double-quotes
    set line=%line:"=%
    :: strip off the last five characters (the "Disk" text)
    set line=%line:~0,-5%
    :: dunno what you want to DO with the sharename here, so I've just echoed it
    ECHO %LINE%
    goto :eof

    For each silly face replace it by : p (but without the space between the : and the p, of course!).

    See how it goes!
    Thanks for all your help, but during trying to get it to work, I have also found scenarios where it wouldn't work where " Disk" isn't the last 5 chars of each line:
    Share name                 Type  Used as  Comment
    
    -------------------------------------------------------------------------------
    [COLOR=Navy]ShareName1[/COLOR]                 Disk
    [COLOR=Navy]ShareName2[/COLOR]                 Disk          Exchange access logs
    [COLOR=Navy]Share Name 3[/COLOR]               Disk          "Message files"
    [COLOR=Navy]Very Long Share Name[/COLOR]       Disk
    The command completed successfully.
    
    Some of the shares are going to have comments.

    Tried using FOR /F "tokens=1 delims=Disk" but it used each letter in Disk as a delim. :confused:
    E.g. Address would become Addre (taking the s from the delim)
    Citrix would become C (taking the i from the delim)

    Is there any way I can use the full word Disk as the delim? Very weird
  • John_Gray
    John_Gray Posts: 5,845 Forumite
    Part of the Furniture 1,000 Posts Name Dropper Photogenic
    edited 9 June 2009 at 5:28PM
    That shows the problem with having to work with incomplete information! I've just tested what our work server gives, and "Disk" appears two spaces after the longest sharename, followed by a variety of comment material.

    We have to take a different approach, then, and select every line containing 'Disk' as one long string, and then substring it.

    Give me a bit of time to work on it...
  • John_Gray
    John_Gray Posts: 5,845 Forumite
    Part of the Furniture 1,000 Posts Name Dropper Photogenic
    edited 9 June 2009 at 5:34PM
    Right, here you are! I didn't do what I said in my previous post, but have just split each line up into 'words'.

    My text file is as follows (called MSE.TXT):
    Shared resources at \\ourserver
    
    
    
    Share name        Type   Used as  Comment
    
    -------------------------------------------------------------------------------
    Address           Disk            "Access to address objects"
    Angela            Disk
    assembly          Disk
    Bob               Disk
    Camilla           Disk
    CanonCop          Print           Canon iR3235 UFRII copier
    Caroline          Disk
    FILESERVER01.LOG  Disk            Exchange message tracking logs
    Finance           Disk
    HPColour          Print           HP Officejet Pro K850 Series
    HPLJ4100          Print  LPT1     HP LaserJet 4100
    HPLJ4Mpl          Print           HP LaserJet 4M via ourserver
    Judith            Disk
    Lorraine          Disk
    Mary              Disk
    NETLOGON          Disk   L:       Logon server share
    Nicola            Disk
    Profiles          Disk
    SYSVOL            Disk            Logon server share
    Vbase             Disk   T:
    Volunteering      Disk
    Volunteers        Disk
    Websites          Disk   U:
    The command completed successfully.
    
    My BATch file is as follows - you can see it is quite inelegant, but I don't have enough time to tidy it up!
    @echo off
    setlocal
    :: this environmental variable just to save line space
    set forcmds=find "Disk" ^^^< mse.txt
    for /f "tokens=1-5*" %%a in ('%forcmds%') do (
      call :process %%a %%b %%c %%d %%e %%f %%g
    )
    endlocal
    goto :eof
    ::------------------------------------------------------
    :process
    :: write out all the 'words'
    ECHO %1 %2 %3 %4 %5 %6
    :: somewhere in these parameters, "Disk" appears
    :: take preceding parameters each time
    if "%2"=="Disk" (
      set sharename=%1
      goto end_process
    )
    if "%3"=="Disk" (
      set sharename=%1 %2
      goto end_process
    )
    if "%4"=="Disk" (
      set sharename=%1 %2 %3
      goto end_process
    )
    if "%5"=="Disk" (
      set sharename=%1 %2 %3 %4
      goto end_process
    )
    if "%6"=="Disk" (
      set sharename=%1 %2 %3 %4 %5
      goto end_process
    )
    
    ::----------
    :end_process
    :: just write out the sharename, and a blank line, and return
    ECHO %SHARENAME%
    ECHO.
    goto :eof
    
  • mr_fishbulb
    mr_fishbulb Posts: 5,224 Forumite
    Part of the Furniture Combo Breaker
    Many thanks for your time on this John :) I'll give it a whirl
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 352K Banking & Borrowing
  • 253.5K Reduce Debt & Boost Income
  • 454.2K Spending & Discounts
  • 245K Work, Benefits & Business
  • 600.6K Mortgages, Homes & Bills
  • 177.4K Life & Family
  • 258.8K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.2K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.