LogOn script to enable Network services

Posted on 2006-04-10
Last Modified: 2013-12-13
I'm working on a script, which may be used at logon, or as system process to enable the Network services (i.e. "Client for Microsoft Network" and "File and Print Sharing") if users notebooks are in office/home network. If users are in different network with static or dhcp-enabled IP (unknown IP addreses, but not from our networks) so these services must be in down-state (disabled). How to implement this?
Question by:veaceslavz
    LVL 27

    Accepted Solution

    Interesting question.
    I see two problems:
    1) Services are started _before_ user logs in.
    2) Logon scripts are run with user priveleges, so user must be local administrator

    So until user login every share will be open. Not very good.

    If you insist on your question. There is onw easy way:
    1) You will write 'check' program (VBS or whatsever language) that will return 1 if user is in LAN and 0 otherwise
    2) In logon script you will run your 'check' program and analyse return code (IF .. THEN) on 1 you will run 'net start ...' on 0 you will run 'net stop ...' with appropriate service names. See 'net start' for list of services.

    LVL 2

    Expert Comment

    Just in case this response still gets to the person who originally asked the question, I'll just add that you can avoid having the services run until login on foreign networks by having them down by default (manual startup would be a start).  Then they'd only be enabled on login.

    The problem of NET START not working unless the users were local admin still stands, though, and it's very rarely a good idea to give users that much power over their machines.  I do have another suggestion.

    If you start with your potentially insecure services / shares / etc disabled security is taken care of.  Then you can have the login script attempt to contact a service running on a server, like the DC, on your own network.  If this succeeds, that service, which could run with domain administrative priveleges, could start the relevant services on the user  machine remotely.  I think if you're thinking of looking into this more deeply, WMI might be useful to you - use:

    Set objWMI = GetObject("winmgmts://<machine>/root/CIMV2")

    to connect (I think that's right; I could be wrong.  The thing I'm not sure of is whether that should be "CreateObject" rather than "GetObject" but like I say I think the above is correct).  The various methods of the WMI object will be useful for controlling administrative things.  I won't bother going into more detail if this question seems to be abandoned anyway.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    Visual xHarbour 1 47
    scoresClump  challenge 31 85
    copyEvens challenge 6 46
    Installed softare without GUID 6 16
    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now