To find workgroup of my machine

Discussion in 'Mac Programming' started by nehovahralph, Apr 20, 2007.

  1. nehovahralph macrumors newbie

    Joined:
    Apr 20, 2007
    #1
    Hi all,
    Newly joined the forum......Can anyone help me how to find the name of the workgroup of my machine using cocoa programming.(ie using code i want to find the name of my workgroup.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I'm 99% certain that you can't access this directly from Cocoa. If SMB sharing is not turned on I'm not sure that you will be in ANY workgroup.

    You can either shell out to one of the SAMBA tools (sorry not sure which one) or parse the smb config file.
     
  3. nehovahralph thread starter macrumors newbie

    Joined:
    Apr 20, 2007
    #3
    Thanks but

    Hi,
    I am very thankful to u for sharing ur knowledge with me but as u know that we cannot see in which workgroup our machine belongs from our own machine .So is there any API either in cocoa or in carbon to display my machine's workgroup name by sitting on my own machine.If there is any API kindly inform me .
    Thanking u.
     
  4. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #4
    You can see which workgroup you are a member of.

    Run Applications->Utilities->Directory Access then look under SMB/CIFS and it will tell you what Workgroup you are a member of
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    There is no declared API that I am aware of. SAMBA is running on the machine. Either connect to it at 127.0.0.1 and ask it, parse the config file, or run the underlying utility that Directory Access is calling (it is almost certainly not using an API but calling a subtask).
     
  6. nehovahralph thread starter macrumors newbie

    Joined:
    Apr 20, 2007
    #6
    Hi all,
    As i had mentioned previously,I want a code by which I can get my machine's workgroup name .Using Directory acces utility ,I know that we can get the machine's workgroup name.But my requirement is that I need a code to be written in my project to get the machine's workgroup name.So ,if any of u have any idea on how to do this kindly send ur opinions.
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    I've already suggested twice how to do it. I state again there is no Cocoa API for this[/url]. Probably the easiest way is to grab the config line from the smb configuration file and parse it in Cocoa.

    The file is /etc/smb.conf. This Unix command will get the line we need:

    Code:
    grep "workgroup =" /etc/smb.conf
    Then using a combination of NSTask and NSString's componentsSeparatedByString: you should be able to get the workgroup in a few lines of code.
     
  8. nehovahralph thread starter macrumors newbie

    Joined:
    Apr 20, 2007
    #8
    Hi all,
    Thanks for sharing with me regarding smb.conf file where the workgroup name is given .But others in my network can see my system in Finder->network->My network eventhough I had set my workgroup name to Finder->network->Fortune.Why is this happening ?Why does my system be seen in the workgroup Fortune.Kindly check it out?
     
  9. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    Altering the contents of the config file will have no effect until the daemons that provide the smb services are restarted as they only read the files when they start. Either reboot the machine, turn Windows file sharing off then on in System preferences or read up on using launchd to restart the daemons.
     

Share This Page